Skip to content

Commit

Permalink
update test response code, introduced in matrix-org#11228
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Nov 9, 2021
1 parent 3b3cf2a commit bd70ffd
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def test_requester_is_no_admin(self, method: str, url: str):
access_token=self.other_user_tok,
)

self.assertEqual(403, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

@parameterized.expand(
Expand All @@ -534,7 +534,7 @@ def test_room_does_not_exist(self, method: str, url: str):
access_token=self.admin_user_tok,
)

self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

@parameterized.expand(
Expand All @@ -555,7 +555,7 @@ def test_room_is_not_valid(self, method: str, url: str):
access_token=self.admin_user_tok,
)

self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(
"invalidroom is not a legal room ID",
channel.json_body["error"],
Expand All @@ -573,7 +573,7 @@ def test_new_room_user_does_not_exist(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand All @@ -591,7 +591,7 @@ def test_new_room_user_is_not_local(self):
access_token=self.admin_user_tok,
)

self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(
"User must be our own: @not:exist.bla",
channel.json_body["error"],
Expand All @@ -609,7 +609,7 @@ def test_block_is_not_bool(self):
access_token=self.admin_user_tok,
)

self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.BAD_JSON, channel.json_body["errcode"])

def test_purge_is_not_bool(self):
Expand All @@ -624,7 +624,7 @@ def test_purge_is_not_bool(self):
access_token=self.admin_user_tok,
)

self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.BAD_JSON, channel.json_body["errcode"])

def test_delete_expired_status(self):
Expand All @@ -638,7 +638,7 @@ def test_delete_expired_status(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id1 = channel.json_body["purge_id"]

Expand All @@ -653,7 +653,7 @@ def test_delete_expired_status(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id2 = channel.json_body["purge_id"]

Expand All @@ -664,7 +664,7 @@ def test_delete_expired_status(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertEqual(2, len(channel.json_body["results"]))
self.assertEqual("complete", channel.json_body["results"][0]["status"])
self.assertEqual("complete", channel.json_body["results"][1]["status"])
Expand All @@ -681,7 +681,7 @@ def test_delete_expired_status(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertEqual(1, len(channel.json_body["results"]))
self.assertEqual("complete", channel.json_body["results"][0]["status"])
self.assertEqual(purge_id2, channel.json_body["results"][0]["purge_id"])
Expand All @@ -695,7 +695,7 @@ def test_delete_expired_status(self):
access_token=self.admin_user_tok,
)

self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

def test_delete_same_room_twice(self):
Expand All @@ -721,7 +721,7 @@ def test_delete_same_room_twice(self):
access_token=self.admin_user_tok,
)

self.assertEqual(400, second_channel.code, msg=second_channel.json_body)
self.assertEqual(HTTPStatus.BAD_REQUEST, second_channel.code, msg=second_channel.json_body)
self.assertEqual(Codes.UNKNOWN, second_channel.json_body["errcode"])
self.assertEqual(
f"History purge already in progress for {self.room_id}",
Expand All @@ -730,7 +730,7 @@ def test_delete_same_room_twice(self):

# get result of first call
first_channel.await_result()
self.assertEqual(200, first_channel.code, msg=first_channel.json_body)
self.assertEqual(HTTPStatus.OK, first_channel.code, msg=first_channel.json_body)
self.assertIn("purge_id", first_channel.json_body)

# check status after finish the task
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_purge_room_and_block(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand Down Expand Up @@ -792,7 +792,7 @@ def test_purge_room_and_not_block(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand Down Expand Up @@ -824,7 +824,7 @@ def test_block_room_and_not_purge(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand Down Expand Up @@ -870,7 +870,7 @@ def test_shutdown_room_consent(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand All @@ -881,7 +881,7 @@ def test_shutdown_room_consent(self):
self.url_status_by_room_id,
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertEqual(1, len(channel.json_body["results"]))

# Test that member has moved to new room
Expand All @@ -908,7 +908,7 @@ def test_shutdown_room_block_peek(self):
content={"history_visibility": "world_readable"},
access_token=self.other_user_tok,
)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)

# Test that room is not purged
with self.assertRaises(AssertionError):
Expand All @@ -925,7 +925,7 @@ def test_shutdown_room_block_peek(self):
access_token=self.admin_user_tok,
)

self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertIn("purge_id", channel.json_body)
purge_id = channel.json_body["purge_id"]

Expand All @@ -936,7 +936,7 @@ def test_shutdown_room_block_peek(self):
self.url_status_by_room_id,
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
self.assertEqual(1, len(channel.json_body["results"]))

# Test that member has moved to new room
Expand Down Expand Up @@ -1020,7 +1020,11 @@ def _test_result(
self.url_status_by_room_id,
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel_room_id.code, msg=channel_room_id.json_body)
self.assertEqual(
HTTPStatus.OK,
channel_room_id.code,
msg=channel_room_id.json_body
)
self.assertEqual(1, len(channel_room_id.json_body["results"]))
self.assertEqual(purge_id, channel_room_id.json_body["results"][0]["purge_id"])

Expand All @@ -1030,7 +1034,11 @@ def _test_result(
self.url_status_by_purge_id + purge_id,
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel_purge_id.code, msg=channel_purge_id.json_body)
self.assertEqual(
HTTPStatus.OK,
channel_purge_id.code,
msg=channel_purge_id.json_body,
)

# test values that are the same in both responses
for content in [
Expand Down

0 comments on commit bd70ffd

Please sign in to comment.