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

Commit

Permalink
Expose the registered device ID from the register_appservice_user t…
Browse files Browse the repository at this point in the history
…est helper. (#11615)
  • Loading branch information
reivilibre authored Feb 2, 2022
1 parent 3f72c2a commit 513913c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/11615.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose the registered device ID from the `register_appservice_user` test helper.
6 changes: 4 additions & 2 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def test_excludes_appservices_user(self) -> None:
# Register an AS user.
user = self.register_user("user", "pass")
token = self.login(user, "pass")
as_user = self.register_appservice_user("as_user_potato", self.appservice.token)
as_user, _ = self.register_appservice_user(
"as_user_potato", self.appservice.token
)

# Join the AS user to rooms owned by the normal user.
public, private = self._create_rooms_and_inject_memberships(
Expand Down Expand Up @@ -388,7 +390,7 @@ def test_handle_local_profile_change_with_deactivated_user(self) -> None:

def test_handle_local_profile_change_with_appservice_user(self) -> None:
# create user
as_user_id = self.register_appservice_user(
as_user_id, _ = self.register_appservice_user(
"as_user_alice", self.appservice.token
)

Expand Down
2 changes: 1 addition & 1 deletion tests/rest/client/test_room_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.clock = clock
self.storage = hs.get_storage()

self.virtual_user_id = self.register_appservice_user(
self.virtual_user_id, _ = self.register_appservice_user(
"as_user_potato", self.appservice.token
)

Expand Down
4 changes: 3 additions & 1 deletion tests/storage/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ def test_population_excludes_appservice_user(self) -> None:
# Register an AS user.
user = self.register_user("user", "pass")
token = self.login(user, "pass")
as_user = self.register_appservice_user("as_user_potato", self.appservice.token)
as_user, _ = self.register_appservice_user(
"as_user_potato", self.appservice.token
)

# Join the AS user to rooms owned by the normal user.
public, private = self._create_rooms_and_inject_memberships(
Expand Down
9 changes: 5 additions & 4 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,18 +620,19 @@ def register_appservice_user(
self,
username: str,
appservice_token: str,
) -> str:
) -> Tuple[str, str]:
"""Register an appservice user as an application service.
Requires the client-facing registration API be registered.
Args:
username: the user to be registered by an application service.
Should be a full username, i.e. ""@localpart:hostname" as opposed to just "localpart"
Should NOT be a full username, i.e. just "localpart" as opposed to "@localpart:hostname"
appservice_token: the acccess token for that application service.
Raises: if the request to '/register' does not return 200 OK.
Returns: the MXID of the new user.
Returns:
The MXID of the new user, the device ID of the new user's first device.
"""
channel = self.make_request(
"POST",
Expand All @@ -643,7 +644,7 @@ def register_appservice_user(
access_token=appservice_token,
)
self.assertEqual(channel.code, 200, channel.json_body)
return channel.json_body["user_id"]
return channel.json_body["user_id"], channel.json_body["device_id"]

def login(
self,
Expand Down

0 comments on commit 513913c

Please sign in to comment.