Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Use literals in place of HTTPStatus constants in tests (#13463)
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel authored Aug 5, 2022
1 parent 3d2cabf commit e2ed1b7
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 191 deletions.
1 change: 1 addition & 0 deletions changelog.d/13463.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use literals in place of `HTTPStatus` constants in tests.
5 changes: 2 additions & 3 deletions tests/federation/test_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from http import HTTPStatus
from unittest.mock import Mock

from synapse.api.errors import Codes, SynapseError
Expand Down Expand Up @@ -51,7 +50,7 @@ def test_complexity_simple(self):
channel = self.make_signed_federation_request(
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
)
self.assertEqual(HTTPStatus.OK, channel.code)
self.assertEqual(200, channel.code)
complexity = channel.json_body["v1"]
self.assertTrue(complexity > 0, complexity)

Expand All @@ -63,7 +62,7 @@ def test_complexity_simple(self):
channel = self.make_signed_federation_request(
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
)
self.assertEqual(HTTPStatus.OK, channel.code)
self.assertEqual(200, channel.code)
complexity = channel.json_body["v1"]
self.assertEqual(complexity, 1.23)

Expand Down
5 changes: 2 additions & 3 deletions tests/federation/transport/test_knocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import OrderedDict
from http import HTTPStatus
from typing import Dict, List

from synapse.api.constants import EventTypes, JoinRules, Membership
Expand Down Expand Up @@ -256,7 +255,7 @@ def test_room_state_returned_when_knocking(self):
RoomVersions.V7.identifier,
),
)
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
self.assertEqual(200, channel.code, channel.result)

# Note: We don't expect the knock membership event to be sent over federation as
# part of the stripped room state, as the knocking homeserver already has that
Expand Down Expand Up @@ -294,7 +293,7 @@ def test_room_state_returned_when_knocking(self):
% (room_id, signed_knock_event.event_id),
signed_knock_event_json,
)
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
self.assertEqual(200, channel.code, channel.result)

# Check that we got the stripped room state in return
room_state_events = channel.json_body["knock_state_events"]
Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from http import HTTPStatus
from typing import Any, Dict

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -58,7 +57,7 @@ def _deactivate_my_account(self) -> None:
access_token=self.token,
)

self.assertEqual(req.code, HTTPStatus.OK, req)
self.assertEqual(req.code, 200, req)

def test_global_account_data_deleted_upon_deactivation(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,4 @@ def test_deny_redact_server_acl(self):
channel = self.make_request(
"POST", path, content={}, access_token=self.access_token
)
self.assertEqual(int(channel.result["code"]), 403)
self.assertEqual(channel.code, 403)
3 changes: 1 addition & 2 deletions tests/handlers/test_room_member.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from http import HTTPStatus
from unittest.mock import Mock, patch

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -260,7 +259,7 @@ def test_local_users_joining_on_another_worker_contribute_to_rate_limit(
f"/_matrix/client/v3/rooms/{self.room_id}/join",
access_token=self.bob_token,
)
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
self.assertEqual(channel.code, 200, channel.json_body)

# wait for join to arrive over replication
self.replicate()
Expand Down
3 changes: 1 addition & 2 deletions tests/http/server/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import inspect
import itertools
import logging
from http import HTTPStatus
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -78,7 +77,7 @@ def test_disconnect(
if expect_cancellation:
expected_code = HTTP_STATUS_REQUEST_CANCELLED
else:
expected_code = HTTPStatus.OK
expected_code = 200

request = channel.request
if channel.is_finished():
Expand Down
14 changes: 7 additions & 7 deletions tests/rest/client/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_add_filter(self) -> None:
self.EXAMPLE_FILTER_JSON,
)

self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
self.assertEqual(channel.json_body, {"filter_id": "0"})
filter = self.get_success(
self.store.get_user_filter(user_localpart="apple", filter_id=0)
Expand All @@ -58,7 +58,7 @@ def test_add_filter_for_other_user(self) -> None:
self.EXAMPLE_FILTER_JSON,
)

self.assertEqual(channel.result["code"], b"403")
self.assertEqual(channel.code, 403)
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)

def test_add_filter_non_local_user(self) -> None:
Expand All @@ -71,7 +71,7 @@ def test_add_filter_non_local_user(self) -> None:
)

self.hs.is_mine = _is_mine
self.assertEqual(channel.result["code"], b"403")
self.assertEqual(channel.code, 403)
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)

def test_get_filter(self) -> None:
Expand All @@ -85,15 +85,15 @@ def test_get_filter(self) -> None:
"GET", "/_matrix/client/r0/user/%s/filter/%s" % (self.user_id, filter_id)
)

self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
self.assertEqual(channel.json_body, self.EXAMPLE_FILTER)

def test_get_filter_non_existant(self) -> None:
channel = self.make_request(
"GET", "/_matrix/client/r0/user/%s/filter/12382148321" % (self.user_id)
)

self.assertEqual(channel.result["code"], b"404")
self.assertEqual(channel.code, 404)
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)

# Currently invalid params do not have an appropriate errcode
Expand All @@ -103,12 +103,12 @@ def test_get_filter_invalid_id(self) -> None:
"GET", "/_matrix/client/r0/user/%s/filter/foobar" % (self.user_id)
)

self.assertEqual(channel.result["code"], b"400")
self.assertEqual(channel.code, 400)

# No ID also returns an invalid_id error
def test_get_filter_no_id(self) -> None:
channel = self.make_request(
"GET", "/_matrix/client/r0/user/%s/filter/" % (self.user_id)
)

self.assertEqual(channel.result["code"], b"400")
self.assertEqual(channel.code, 400)
Loading

0 comments on commit e2ed1b7

Please sign in to comment.