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

Commit

Permalink
Fix user directory test for deactivated support user. (#16157)
Browse files Browse the repository at this point in the history
Support users should not be added to the user directory after
being deactivated.
  • Loading branch information
clokep authored Aug 22, 2023
1 parent bc72d80 commit b657e89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/16157.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix assertion in user directory unit tests.
19 changes: 11 additions & 8 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,24 @@ def test_handle_local_profile_change_with_appservice_sender(self) -> None:
self.assertIsNone(profile)

def test_handle_user_deactivated_support_user(self) -> None:
"""Ensure a support user doesn't get added to the user directory after deactivation."""
s_user_id = "@support:test"
self.get_success(
self.store.register_user(
user_id=s_user_id, password_hash=None, user_type=UserTypes.SUPPORT
)
)

mock_remove_from_user_dir = Mock(return_value=make_awaitable(None))
with patch.object(
self.store, "remove_from_user_dir", mock_remove_from_user_dir
):
self.get_success(self.handler.handle_local_user_deactivated(s_user_id))
# BUG: the correct spelling is assert_not_called, but that makes the test fail
# and it's not clear that this is actually the behaviour we want.
mock_remove_from_user_dir.not_called()
# The profile should not be in the directory.
profile = self.get_success(self.store._get_user_in_directory(s_user_id))
self.assertIsNone(profile)

# Remove the user from the directory.
self.get_success(self.handler.handle_local_user_deactivated(s_user_id))

# The profile should still not be in the user directory.
profile = self.get_success(self.store._get_user_in_directory(s_user_id))
self.assertIsNone(profile)

def test_handle_user_deactivated_regular_user(self) -> None:
r_user_id = "@regular:test"
Expand Down

0 comments on commit b657e89

Please sign in to comment.