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

Commit

Permalink
Prepare unit tests for Python 3.12 (#16099)
Browse files Browse the repository at this point in the history
  • Loading branch information
V02460 committed Aug 25, 2023
1 parent ed6de4b commit 84f441f
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .ci/scripts/calculate_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def set_output(key: str, value: str):
"database": "sqlite",
"extras": "all",
}
for version in ("3.9", "3.10", "3.11")
for version in ("3.9", "3.10", "3.11", "3.12.0-rc.1")
)


trial_postgres_tests = [
{
"python-version": "3.8",
Expand Down
1 change: 1 addition & 0 deletions changelog.d/16099.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prepare unit tests for Python 3.12.
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions synapse/logging/_terse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"processName",
"relativeCreated",
"stack_info",
"taskName",
"thread",
"threadName",
}
Expand Down
24 changes: 12 additions & 12 deletions tests/handlers/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,50 +122,50 @@ def test_get_devices_by_user(self) -> None:

self.assertEqual(3, len(res))
device_map = {d["device_id"]: d for d in res}
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user1,
"device_id": "xyz",
"display_name": "display 0",
"last_seen_ip": None,
"last_seen_ts": None,
},
device_map["xyz"],
}.items(),
device_map["xyz"].items(),
)
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user1,
"device_id": "fco",
"display_name": "display 1",
"last_seen_ip": "ip1",
"last_seen_ts": 1000000,
},
device_map["fco"],
}.items(),
device_map["fco"].items(),
)
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user1,
"device_id": "abc",
"display_name": "display 2",
"last_seen_ip": "ip3",
"last_seen_ts": 3000000,
},
device_map["abc"],
}.items(),
device_map["abc"].items(),
)

def test_get_device(self) -> None:
self._record_users()

res = self.get_success(self.handler.get_device(user1, "abc"))
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user1,
"device_id": "abc",
"display_name": "display 2",
"last_seen_ip": "ip3",
"last_seen_ts": 3000000,
},
res,
}.items(),
res.items(),
)

def test_delete_device(self) -> None:
Expand Down
5 changes: 3 additions & 2 deletions tests/rest/client/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,9 @@ def test_spam_checker_deny(self) -> None:
body,
)
self.assertEqual(channel.code, 403, channel.result)
self.assertDictContainsSubset(
{"errcode": Codes.LIMIT_EXCEEDED, "extra": "value"}, channel.json_body
self.assertLessEqual(
{"errcode": Codes.LIMIT_EXCEEDED, "extra": "value"}.items(),
channel.json_body.items(),
)


Expand Down
8 changes: 4 additions & 4 deletions tests/rest/client/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_POST_appservice_registration_valid(self) -> None:

self.assertEqual(channel.code, 200, msg=channel.result)
det_data = {"user_id": user_id, "home_server": self.hs.hostname}
self.assertDictContainsSubset(det_data, channel.json_body)
self.assertLessEqual(det_data.items(), channel.json_body.items())

def test_POST_appservice_registration_no_type(self) -> None:
as_token = "i_am_an_app_service"
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_POST_user_valid(self) -> None:
"device_id": device_id,
}
self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body)
self.assertLessEqual(det_data.items(), channel.json_body.items())

@override_config({"enable_registration": False})
def test_POST_disabled_registration(self) -> None:
Expand All @@ -157,7 +157,7 @@ def test_POST_guest_registration(self) -> None:

det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body)
self.assertLessEqual(det_data.items(), channel.json_body.items())

def test_POST_disabled_guest_registration(self) -> None:
self.hs.config.registration.allow_guest_access = False
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_POST_registration_requires_token(self) -> None:
"device_id": device_id,
}
self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body)
self.assertLessEqual(det_data.items(), channel.json_body.items())

# Check the `completed` counter has been incremented and pending is 0
res = self.get_success(
Expand Down
40 changes: 21 additions & 19 deletions tests/rest/client/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def test_edit_reply(self) -> None:
)
self.assertEqual(200, channel.code, channel.json_body)
event_result = channel.json_body
self.assertDictContainsSubset(original_body, event_result["content"])
self.assertLessEqual(original_body.items(), event_result["content"].items())

# also check /context, which returns the *edited* event
channel = self.make_request(
Expand All @@ -587,14 +587,14 @@ def test_edit_reply(self) -> None:
(context_result, "/context"),
):
# The reference metadata should still be intact.
self.assertDictContainsSubset(
self.assertLessEqual(
{
"m.relates_to": {
"event_id": self.parent_id,
"rel_type": "m.reference",
}
},
result_event_dict["content"],
}.items(),
result_event_dict["content"].items(),
desc,
)

Expand Down Expand Up @@ -1372,9 +1372,11 @@ def test_thread_edit_latest_event(self) -> None:
latest_event_in_thread = thread_summary["latest_event"]
# The latest event in the thread should have the edit appear under the
# bundled aggregations.
self.assertDictContainsSubset(
{"event_id": edit_event_id, "sender": "@alice:test"},
latest_event_in_thread["unsigned"]["m.relations"][RelationTypes.REPLACE],
self.assertLessEqual(
{"event_id": edit_event_id, "sender": "@alice:test"}.items(),
latest_event_in_thread["unsigned"]["m.relations"][
RelationTypes.REPLACE
].items(),
)

def test_aggregation_get_event_for_annotation(self) -> None:
Expand Down Expand Up @@ -1637,9 +1639,9 @@ def test_redact_relation_thread(self) -> None:
##################################################
self.assertEqual(self._get_related_events(), list(reversed(thread_replies)))
relations = self._get_bundled_aggregations()
self.assertDictContainsSubset(
{"count": 3, "current_user_participated": True},
relations[RelationTypes.THREAD],
self.assertLessEqual(
{"count": 3, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD].items(),
)
# The latest event is the last sent event.
self.assertEqual(
Expand All @@ -1658,9 +1660,9 @@ def test_redact_relation_thread(self) -> None:
# The thread should still exist, but the latest event should be updated.
self.assertEqual(self._get_related_events(), list(reversed(thread_replies)))
relations = self._get_bundled_aggregations()
self.assertDictContainsSubset(
{"count": 2, "current_user_participated": True},
relations[RelationTypes.THREAD],
self.assertLessEqual(
{"count": 2, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD].items(),
)
# And the latest event is the last unredacted event.
self.assertEqual(
Expand All @@ -1677,9 +1679,9 @@ def test_redact_relation_thread(self) -> None:
# Nothing should have changed (except the thread count).
self.assertEqual(self._get_related_events(), thread_replies)
relations = self._get_bundled_aggregations()
self.assertDictContainsSubset(
{"count": 1, "current_user_participated": True},
relations[RelationTypes.THREAD],
self.assertLessEqual(
{"count": 1, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD].items(),
)
# And the latest event is the last unredacted event.
self.assertEqual(
Expand Down Expand Up @@ -1774,12 +1776,12 @@ def test_redact_parent_thread(self) -> None:
event_ids = self._get_related_events()
relations = self._get_bundled_aggregations()
self.assertEqual(len(event_ids), 1)
self.assertDictContainsSubset(
self.assertLessEqual(
{
"count": 1,
"current_user_participated": True,
},
relations[RelationTypes.THREAD],
}.items(),
relations[RelationTypes.THREAD].items(),
)
self.assertEqual(
relations[RelationTypes.THREAD]["latest_event"]["event_id"],
Expand Down
30 changes: 15 additions & 15 deletions tests/storage/test_client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def test_insert_new_client_ip(self) -> None:
)

r = result[(user_id, device_id)]
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user_id,
"device_id": device_id,
"ip": "ip",
"user_agent": "user_agent",
"last_seen": 12345678000,
},
r,
}.items(),
r.items(),
)

def test_insert_new_client_ip_none_device_id(self) -> None:
Expand Down Expand Up @@ -526,15 +526,15 @@ def test_devices_last_seen_bg_update(self) -> None:
)

r = result[(user_id, device_id)]
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user_id,
"device_id": device_id,
"ip": None,
"user_agent": None,
"last_seen": None,
},
r,
}.items(),
r.items(),
)

# Register the background update to run again.
Expand All @@ -561,15 +561,15 @@ def test_devices_last_seen_bg_update(self) -> None:
)

r = result[(user_id, device_id)]
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user_id,
"device_id": device_id,
"ip": "ip",
"user_agent": "user_agent",
"last_seen": 0,
},
r,
}.items(),
r.items(),
)

def test_old_user_ips_pruned(self) -> None:
Expand Down Expand Up @@ -640,15 +640,15 @@ def test_old_user_ips_pruned(self) -> None:
)

r = result2[(user_id, device_id)]
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": user_id,
"device_id": device_id,
"ip": "ip",
"user_agent": "user_agent",
"last_seen": 0,
},
r,
}.items(),
r.items(),
)

def test_invalid_user_agents_are_ignored(self) -> None:
Expand Down Expand Up @@ -777,13 +777,13 @@ def _runtest(
self.store.get_last_client_ip_by_device(self.user_id, device_id)
)
r = result[(self.user_id, device_id)]
self.assertDictContainsSubset(
self.assertLessEqual(
{
"user_id": self.user_id,
"device_id": device_id,
"ip": expected_ip,
"user_agent": "Mozzila pizza",
"last_seen": 123456100,
},
r,
}.items(),
r.items(),
)
Loading

0 comments on commit 84f441f

Please sign in to comment.