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

Commit e2ed1b7

Browse files
authored
Use literals in place of HTTPStatus constants in tests (#13463)
1 parent 3d2cabf commit e2ed1b7

18 files changed

+172
-191
lines changed

changelog.d/13463.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use literals in place of `HTTPStatus` constants in tests.

tests/federation/test_complexity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from http import HTTPStatus
1615
from unittest.mock import Mock
1716

1817
from synapse.api.errors import Codes, SynapseError
@@ -51,7 +50,7 @@ def test_complexity_simple(self):
5150
channel = self.make_signed_federation_request(
5251
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
5352
)
54-
self.assertEqual(HTTPStatus.OK, channel.code)
53+
self.assertEqual(200, channel.code)
5554
complexity = channel.json_body["v1"]
5655
self.assertTrue(complexity > 0, complexity)
5756

@@ -63,7 +62,7 @@ def test_complexity_simple(self):
6362
channel = self.make_signed_federation_request(
6463
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
6564
)
66-
self.assertEqual(HTTPStatus.OK, channel.code)
65+
self.assertEqual(200, channel.code)
6766
complexity = channel.json_body["v1"]
6867
self.assertEqual(complexity, 1.23)
6968

tests/federation/transport/test_knocking.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
from collections import OrderedDict
15-
from http import HTTPStatus
1615
from typing import Dict, List
1716

1817
from synapse.api.constants import EventTypes, JoinRules, Membership
@@ -256,7 +255,7 @@ def test_room_state_returned_when_knocking(self):
256255
RoomVersions.V7.identifier,
257256
),
258257
)
259-
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
258+
self.assertEqual(200, channel.code, channel.result)
260259

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

299298
# Check that we got the stripped room state in return
300299
room_state_events = channel.json_body["knock_state_events"]

tests/handlers/test_deactivate_account.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from http import HTTPStatus
1514
from typing import Any, Dict
1615

1716
from twisted.test.proto_helpers import MemoryReactor
@@ -58,7 +57,7 @@ def _deactivate_my_account(self) -> None:
5857
access_token=self.token,
5958
)
6059

61-
self.assertEqual(req.code, HTTPStatus.OK, req)
60+
self.assertEqual(req.code, 200, req)
6261

6362
def test_global_account_data_deleted_upon_deactivation(self) -> None:
6463
"""

tests/handlers/test_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,4 @@ def test_deny_redact_server_acl(self):
314314
channel = self.make_request(
315315
"POST", path, content={}, access_token=self.access_token
316316
)
317-
self.assertEqual(int(channel.result["code"]), 403)
317+
self.assertEqual(channel.code, 403)

tests/handlers/test_room_member.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from http import HTTPStatus
21
from unittest.mock import Mock, patch
32

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

265264
# wait for join to arrive over replication
266265
self.replicate()

tests/http/server/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import inspect
1616
import itertools
1717
import logging
18-
from http import HTTPStatus
1918
from typing import (
2019
Any,
2120
Callable,
@@ -78,7 +77,7 @@ def test_disconnect(
7877
if expect_cancellation:
7978
expected_code = HTTP_STATUS_REQUEST_CANCELLED
8079
else:
81-
expected_code = HTTPStatus.OK
80+
expected_code = 200
8281

8382
request = channel.request
8483
if channel.is_finished():

tests/rest/client/test_filter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_add_filter(self) -> None:
4343
self.EXAMPLE_FILTER_JSON,
4444
)
4545

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

61-
self.assertEqual(channel.result["code"], b"403")
61+
self.assertEqual(channel.code, 403)
6262
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)
6363

6464
def test_add_filter_non_local_user(self) -> None:
@@ -71,7 +71,7 @@ def test_add_filter_non_local_user(self) -> None:
7171
)
7272

7373
self.hs.is_mine = _is_mine
74-
self.assertEqual(channel.result["code"], b"403")
74+
self.assertEqual(channel.code, 403)
7575
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)
7676

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

88-
self.assertEqual(channel.result["code"], b"200")
88+
self.assertEqual(channel.code, 200)
8989
self.assertEqual(channel.json_body, self.EXAMPLE_FILTER)
9090

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

96-
self.assertEqual(channel.result["code"], b"404")
96+
self.assertEqual(channel.code, 404)
9797
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
9898

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

106-
self.assertEqual(channel.result["code"], b"400")
106+
self.assertEqual(channel.code, 400)
107107

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

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

0 commit comments

Comments
 (0)