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

Commit

Permalink
Move single-use methods out of TestCase (#12348)
Browse files Browse the repository at this point in the history
These methods are only used by a single testcase, so they shouldn't be
cluttering up the base `TestCase` class.
  • Loading branch information
richvdh authored Apr 1, 2022
1 parent f871222 commit b7762b0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.d/12348.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move single-use methods out of `TestCase`.
11 changes: 11 additions & 0 deletions tests/rest/client/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.store = hs.get_datastores().main
self.submit_token_resource = PasswordResetSubmitTokenResource(hs)

def attempt_wrong_password_login(self, username: str, password: str) -> None:
"""Attempts to login as the user with the given password, asserting
that the attempt *fails*.
"""
body = {"type": "m.login.password", "user": username, "password": password}

channel = self.make_request(
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
)
self.assertEqual(channel.code, 403, channel.result)

def test_basic_password_reset(self) -> None:
"""Test basic password reset flow"""
old_password = "monkey"
Expand Down
16 changes: 16 additions & 0 deletions tests/storage/test_cleanup_extrems.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ def run_delta_file(txn):

self.wait_for_background_updates()

def add_extremity(self, room_id: str, event_id: str) -> None:
"""
Add the given event as an extremity to the room.
"""
self.get_success(
self.hs.get_datastores().main.db_pool.simple_insert(
table="event_forward_extremities",
values={"room_id": room_id, "event_id": event_id},
desc="test_add_extremity",
)
)

self.hs.get_datastores().main.get_latest_event_ids_in_room.invalidate(
(room_id,)
)

def test_soft_failed_extremities_handled_correctly(self):
"""Test that extremities are correctly calculated in the presence of
soft failed events.
Expand Down
27 changes: 0 additions & 27 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,33 +717,6 @@ def create_and_send_event(

return event.event_id

def add_extremity(self, room_id, event_id):
"""
Add the given event as an extremity to the room.
"""
self.get_success(
self.hs.get_datastores().main.db_pool.simple_insert(
table="event_forward_extremities",
values={"room_id": room_id, "event_id": event_id},
desc="test_add_extremity",
)
)

self.hs.get_datastores().main.get_latest_event_ids_in_room.invalidate(
(room_id,)
)

def attempt_wrong_password_login(self, username, password):
"""Attempts to login as the user with the given password, asserting
that the attempt *fails*.
"""
body = {"type": "m.login.password", "user": username, "password": password}

channel = self.make_request(
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
)
self.assertEqual(channel.code, 403, channel.result)

def inject_room_member(self, room: str, user: str, membership: Membership) -> None:
"""
Inject a membership event into a room.
Expand Down

0 comments on commit b7762b0

Please sign in to comment.