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

Replace assertEquals with assertEqual. #12092

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12092.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User `assertEqual` instead of the deprecated `assertEquals` in test code.
36 changes: 18 additions & 18 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_get_user_by_req_user_valid_token(self):
request.args[b"access_token"] = [self.test_token]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
requester = self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(requester.user.to_string(), self.test_user)
self.assertEqual(requester.user.to_string(), self.test_user)

def test_get_user_by_req_user_bad_token(self):
self.store.get_user_by_access_token = simple_async_mock(None)
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_get_user_by_req_appservice_valid_token(self):
request.args[b"access_token"] = [self.test_token]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
requester = self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(requester.user.to_string(), self.test_user)
self.assertEqual(requester.user.to_string(), self.test_user)

def test_get_user_by_req_appservice_valid_token_good_ip(self):
from netaddr import IPSet
Expand All @@ -128,7 +128,7 @@ def test_get_user_by_req_appservice_valid_token_good_ip(self):
request.args[b"access_token"] = [self.test_token]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
requester = self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(requester.user.to_string(), self.test_user)
self.assertEqual(requester.user.to_string(), self.test_user)

def test_get_user_by_req_appservice_valid_token_bad_ip(self):
from netaddr import IPSet
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_get_user_by_req_appservice_valid_token_valid_user_id(self):
request.args[b"user_id"] = [masquerading_user_id]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
requester = self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(
self.assertEqual(
requester.user.to_string(), masquerading_user_id.decode("utf8")
)

Expand Down Expand Up @@ -242,10 +242,10 @@ def test_get_user_by_req_appservice_valid_token_valid_device_id(self):
request.args[b"org.matrix.msc3202.device_id"] = [masquerading_device_id]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
requester = self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(
self.assertEqual(
requester.user.to_string(), masquerading_user_id.decode("utf8")
)
self.assertEquals(requester.device_id, masquerading_device_id.decode("utf8"))
self.assertEqual(requester.device_id, masquerading_device_id.decode("utf8"))

@override_config({"experimental_features": {"msc3202_device_masquerading": True}})
def test_get_user_by_req_appservice_valid_token_invalid_device_id(self):
Expand Down Expand Up @@ -275,8 +275,8 @@ def test_get_user_by_req_appservice_valid_token_invalid_device_id(self):
request.requestHeaders.getRawHeaders = mock_getRawHeaders()

failure = self.get_failure(self.auth.get_user_by_req(request), AuthError)
self.assertEquals(failure.value.code, 400)
self.assertEquals(failure.value.errcode, Codes.EXCLUSIVE)
self.assertEqual(failure.value.code, 400)
self.assertEqual(failure.value.errcode, Codes.EXCLUSIVE)

def test_get_user_by_req__puppeted_token__not_tracking_puppeted_mau(self):
self.store.get_user_by_access_token = simple_async_mock(
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_get_user_by_req__puppeted_token__tracking_puppeted_mau(self):
request.args[b"access_token"] = [self.test_token]
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
self.get_success(self.auth.get_user_by_req(request))
self.assertEquals(self.store.insert_client_ip.call_count, 2)
self.assertEqual(self.store.insert_client_ip.call_count, 2)

def test_get_user_from_macaroon(self):
self.store.get_user_by_access_token = simple_async_mock(
Expand Down Expand Up @@ -369,9 +369,9 @@ def test_blocking_mau(self):
self.store.get_monthly_active_count = simple_async_mock(lots_of_users)

e = self.get_failure(self.auth.check_auth_blocking(), ResourceLimitError)
self.assertEquals(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEquals(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEquals(e.value.code, 403)
self.assertEqual(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEqual(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEqual(e.value.code, 403)

# Ensure does not throw an error
self.store.get_monthly_active_count = simple_async_mock(small_number_of_users)
Expand Down Expand Up @@ -473,9 +473,9 @@ def test_hs_disabled(self):
self.auth_blocking._hs_disabled = True
self.auth_blocking._hs_disabled_message = "Reason for being disabled"
e = self.get_failure(self.auth.check_auth_blocking(), ResourceLimitError)
self.assertEquals(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEquals(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEquals(e.value.code, 403)
self.assertEqual(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEqual(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEqual(e.value.code, 403)

def test_hs_disabled_no_server_notices_user(self):
"""Check that 'hs_disabled_message' works correctly when there is no
Expand All @@ -488,9 +488,9 @@ def test_hs_disabled_no_server_notices_user(self):
self.auth_blocking._hs_disabled = True
self.auth_blocking._hs_disabled_message = "Reason for being disabled"
e = self.get_failure(self.auth.check_auth_blocking(), ResourceLimitError)
self.assertEquals(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEquals(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEquals(e.value.code, 403)
self.assertEqual(e.value.admin_contact, self.hs.config.server.admin_contact)
self.assertEqual(e.value.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
self.assertEqual(e.value.code, 403)

def test_server_notices_mxid_special_cased(self):
self.auth_blocking._hs_disabled = True
Expand Down
20 changes: 10 additions & 10 deletions tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def test_filter_presence_match(self):
)

results = self.get_success(user_filter.filter_presence(events=events))
self.assertEquals(events, results)
self.assertEqual(events, results)

def test_filter_presence_no_match(self):
user_filter_json = {"presence": {"types": ["m.*"]}}
Expand All @@ -388,7 +388,7 @@ def test_filter_presence_no_match(self):
)

results = self.get_success(user_filter.filter_presence(events=events))
self.assertEquals([], results)
self.assertEqual([], results)

def test_filter_room_state_match(self):
user_filter_json = {"room": {"state": {"types": ["m.*"]}}}
Expand All @@ -407,7 +407,7 @@ def test_filter_room_state_match(self):
)

results = self.get_success(user_filter.filter_room_state(events=events))
self.assertEquals(events, results)
self.assertEqual(events, results)

def test_filter_room_state_no_match(self):
user_filter_json = {"room": {"state": {"types": ["m.*"]}}}
Expand All @@ -428,7 +428,7 @@ def test_filter_room_state_no_match(self):
)

results = self.get_success(user_filter.filter_room_state(events))
self.assertEquals([], results)
self.assertEqual([], results)

def test_filter_rooms(self):
definition = {
Expand All @@ -444,7 +444,7 @@ def test_filter_rooms(self):

filtered_room_ids = list(Filter(self.hs, definition).filter_rooms(room_ids))

self.assertEquals(filtered_room_ids, ["!allowed:example.com"])
self.assertEqual(filtered_room_ids, ["!allowed:example.com"])

@unittest.override_config({"experimental_features": {"msc3440_enabled": True}})
def test_filter_relations(self):
Expand Down Expand Up @@ -486,7 +486,7 @@ async def events_have_relations(*args, **kwargs):
Filter(self.hs, definition)._check_event_relations(events)
)
)
self.assertEquals(filtered_events, events[1:])
self.assertEqual(filtered_events, events[1:])

def test_add_filter(self):
user_filter_json = {"room": {"state": {"types": ["m.*"]}}}
Expand All @@ -497,8 +497,8 @@ def test_add_filter(self):
)
)

self.assertEquals(filter_id, 0)
self.assertEquals(
self.assertEqual(filter_id, 0)
self.assertEqual(
user_filter_json,
(
self.get_success(
Expand All @@ -524,6 +524,6 @@ def test_get_filter(self):
)
)

self.assertEquals(filter.get_filter_json(), user_filter_json)
self.assertEqual(filter.get_filter_json(), user_filter_json)

self.assertRegexpMatches(repr(filter), r"<FilterCollection \{.*\}>")
self.assertRegex(repr(filter), r"<FilterCollection \{.*\}>")
28 changes: 14 additions & 14 deletions tests/api/test_ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def test_allowed_via_can_do_action(self):
limiter.can_do_action(None, key="test_id", _time_now_s=0)
)
self.assertTrue(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(None, key="test_id", _time_now_s=5)
)
self.assertFalse(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(None, key="test_id", _time_now_s=10)
)
self.assertTrue(allowed)
self.assertEquals(20.0, time_allowed)
self.assertEqual(20.0, time_allowed)

def test_allowed_appservice_ratelimited_via_can_requester_do_action(self):
appservice = ApplicationService(
Expand All @@ -45,19 +45,19 @@ def test_allowed_appservice_ratelimited_via_can_requester_do_action(self):
limiter.can_do_action(as_requester, _time_now_s=0)
)
self.assertTrue(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(as_requester, _time_now_s=5)
)
self.assertFalse(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(as_requester, _time_now_s=10)
)
self.assertTrue(allowed)
self.assertEquals(20.0, time_allowed)
self.assertEqual(20.0, time_allowed)

def test_allowed_appservice_via_can_requester_do_action(self):
appservice = ApplicationService(
Expand All @@ -76,19 +76,19 @@ def test_allowed_appservice_via_can_requester_do_action(self):
limiter.can_do_action(as_requester, _time_now_s=0)
)
self.assertTrue(allowed)
self.assertEquals(-1, time_allowed)
self.assertEqual(-1, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(as_requester, _time_now_s=5)
)
self.assertTrue(allowed)
self.assertEquals(-1, time_allowed)
self.assertEqual(-1, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(as_requester, _time_now_s=10)
)
self.assertTrue(allowed)
self.assertEquals(-1, time_allowed)
self.assertEqual(-1, time_allowed)

def test_allowed_via_ratelimit(self):
limiter = Ratelimiter(
Expand Down Expand Up @@ -246,15 +246,15 @@ def test_multiple_actions(self):
limiter.can_do_action(None, key="test_id", n_actions=3, _time_now_s=0)
)
self.assertTrue(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

# Test that, after doing these 3 actions, we can't do any more action without
# waiting.
allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(None, key="test_id", n_actions=1, _time_now_s=0)
)
self.assertFalse(allowed)
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

# Test that after waiting we can do only 1 action.
allowed, time_allowed = self.get_success_or_raise(
Expand All @@ -269,15 +269,15 @@ def test_multiple_actions(self):
self.assertTrue(allowed)
# The time allowed is the current time because we could still repeat the action
# once.
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

allowed, time_allowed = self.get_success_or_raise(
limiter.can_do_action(None, key="test_id", n_actions=2, _time_now_s=10)
)
self.assertFalse(allowed)
# The time allowed doesn't change despite allowed being False because, while we
# don't allow 2 actions, we could still do 1.
self.assertEquals(10.0, time_allowed)
self.assertEqual(10.0, time_allowed)

# Test that after waiting a bit more we can do 2 actions.
allowed, time_allowed = self.get_success_or_raise(
Expand All @@ -286,4 +286,4 @@ def test_multiple_actions(self):
self.assertTrue(allowed)
# The time allowed is the current time because we could still repeat the action
# once.
self.assertEquals(20.0, time_allowed)
self.assertEqual(20.0, time_allowed)
Loading