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

Commit b7762b0

Browse files
authored
Move single-use methods out of TestCase (#12348)
These methods are only used by a single testcase, so they shouldn't be cluttering up the base `TestCase` class.
1 parent f871222 commit b7762b0

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

changelog.d/12348.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move single-use methods out of `TestCase`.

tests/rest/client/test_account.py

+11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
8989
self.store = hs.get_datastores().main
9090
self.submit_token_resource = PasswordResetSubmitTokenResource(hs)
9191

92+
def attempt_wrong_password_login(self, username: str, password: str) -> None:
93+
"""Attempts to login as the user with the given password, asserting
94+
that the attempt *fails*.
95+
"""
96+
body = {"type": "m.login.password", "user": username, "password": password}
97+
98+
channel = self.make_request(
99+
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
100+
)
101+
self.assertEqual(channel.code, 403, channel.result)
102+
92103
def test_basic_password_reset(self) -> None:
93104
"""Test basic password reset flow"""
94105
old_password = "monkey"

tests/storage/test_cleanup_extrems.py

+16
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ def run_delta_file(txn):
6868

6969
self.wait_for_background_updates()
7070

71+
def add_extremity(self, room_id: str, event_id: str) -> None:
72+
"""
73+
Add the given event as an extremity to the room.
74+
"""
75+
self.get_success(
76+
self.hs.get_datastores().main.db_pool.simple_insert(
77+
table="event_forward_extremities",
78+
values={"room_id": room_id, "event_id": event_id},
79+
desc="test_add_extremity",
80+
)
81+
)
82+
83+
self.hs.get_datastores().main.get_latest_event_ids_in_room.invalidate(
84+
(room_id,)
85+
)
86+
7187
def test_soft_failed_extremities_handled_correctly(self):
7288
"""Test that extremities are correctly calculated in the presence of
7389
soft failed events.

tests/unittest.py

-27
Original file line numberDiff line numberDiff line change
@@ -717,33 +717,6 @@ def create_and_send_event(
717717

718718
return event.event_id
719719

720-
def add_extremity(self, room_id, event_id):
721-
"""
722-
Add the given event as an extremity to the room.
723-
"""
724-
self.get_success(
725-
self.hs.get_datastores().main.db_pool.simple_insert(
726-
table="event_forward_extremities",
727-
values={"room_id": room_id, "event_id": event_id},
728-
desc="test_add_extremity",
729-
)
730-
)
731-
732-
self.hs.get_datastores().main.get_latest_event_ids_in_room.invalidate(
733-
(room_id,)
734-
)
735-
736-
def attempt_wrong_password_login(self, username, password):
737-
"""Attempts to login as the user with the given password, asserting
738-
that the attempt *fails*.
739-
"""
740-
body = {"type": "m.login.password", "user": username, "password": password}
741-
742-
channel = self.make_request(
743-
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
744-
)
745-
self.assertEqual(channel.code, 403, channel.result)
746-
747720
def inject_room_member(self, room: str, user: str, membership: Membership) -> None:
748721
"""
749722
Inject a membership event into a room.

0 commit comments

Comments
 (0)