From f4f3e4cf447dd64b287f39a5bb6b794cb98922e3 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 17 Dec 2021 18:18:48 +0000 Subject: [PATCH 1/4] Return the device ID when registering an appservice user in test helpers --- tests/handlers/test_user_directory.py | 6 ++++-- tests/storage/test_user_directory.py | 4 +++- tests/unittest.py | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/handlers/test_user_directory.py b/tests/handlers/test_user_directory.py index 70c621b825f4..482c90ef68c5 100644 --- a/tests/handlers/test_user_directory.py +++ b/tests/handlers/test_user_directory.py @@ -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( @@ -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 ) diff --git a/tests/storage/test_user_directory.py b/tests/storage/test_user_directory.py index 7f5b28aed8c4..48f1e9d8411b 100644 --- a/tests/storage/test_user_directory.py +++ b/tests/storage/test_user_directory.py @@ -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( diff --git a/tests/unittest.py b/tests/unittest.py index 14318483674e..0698b3d13ae8 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -620,18 +620,18 @@ 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", @@ -643,7 +643,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, From 2feaa13e705eb1810c32089fb25e34dd05bbf461 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 20 Dec 2021 15:41:38 +0000 Subject: [PATCH 2/4] Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/11615.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11615.misc diff --git a/changelog.d/11615.misc b/changelog.d/11615.misc new file mode 100644 index 000000000000..0aa953650493 --- /dev/null +++ b/changelog.d/11615.misc @@ -0,0 +1 @@ +Expose the registered device ID from the `register_appservice_user` test helper. \ No newline at end of file From 0899cd5a5fdb2efb3d74b739ae48239a87776769 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 20 Dec 2021 15:45:18 +0000 Subject: [PATCH 3/4] Fix up concurrently-introduced test --- tests/rest/client/test_room_batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rest/client/test_room_batch.py b/tests/rest/client/test_room_batch.py index 721454c1875f..e9f870403536 100644 --- a/tests/rest/client/test_room_batch.py +++ b/tests/rest/client/test_room_batch.py @@ -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 ) From 8a385c8b6a379b223e23a88ff938f2d3c3dce17b Mon Sep 17 00:00:00 2001 From: reivilibre Date: Mon, 20 Dec 2021 15:56:37 +0000 Subject: [PATCH 4/4] Update tests/unittest.py Co-authored-by: Patrick Cloke --- tests/unittest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unittest.py b/tests/unittest.py index 0698b3d13ae8..6fc617601a40 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -631,7 +631,8 @@ def register_appservice_user( Raises: if the request to '/register' does not return 200 OK. - Returns: the MXID of the new user, the device ID of the new user's first device. + Returns: + The MXID of the new user, the device ID of the new user's first device. """ channel = self.make_request( "POST",