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

Commit 2514694

Browse files
committed
Add - unit test coverage.
1 parent 216dd62 commit 2514694

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/module_api/test_api.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from unittest.mock import Mock
14+
from unittest.mock import Mock, patch
1515

1616
from twisted.internet import defer
1717

1818
from synapse.api.constants import EduTypes, EventTypes
19+
from synapse.api.errors import NotFoundError
1920
from synapse.events import EventBase
2021
from synapse.federation.units import Transaction
2122
from synapse.handlers.presence import UserPresenceState
@@ -409,7 +410,8 @@ def test_send_local_online_presence_to_federation(self):
409410

410411
self.assertTrue(found_update)
411412

412-
def test_update_membership(self):
413+
@patch("synapse.handlers.room_member.RoomMemberMasterHandler._remote_join")
414+
def test_update_membership(self, mocked_remote_join):
413415
"""Tests that the module API can update the membership of a user in a room."""
414416
peter = self.register_user("peter", "hackme")
415417
lesley = self.register_user("lesley", "hackme")
@@ -532,6 +534,32 @@ def test_update_membership(self):
532534
self.assertEqual(res["displayname"], "simone")
533535
self.assertIsNone(res["avatar_url"])
534536

537+
# Check that no remote join attempts have occurred thus far.
538+
self.assertFalse(mocked_remote_join.called)
539+
540+
# Necessary to fake a remote join.
541+
fake_stream_id = 1
542+
mocked_remote_join.return_value = "fake-event-id", fake_stream_id
543+
fake_remote_host = f"{self.module_api.server_name}-remote"
544+
545+
# Given that the join is to be faked, we expect the relevant join event not to
546+
# be persisted and the module API method to raise that.
547+
self.get_failure(
548+
defer.ensureDeferred(
549+
self.module_api.update_room_membership(
550+
sender=peter,
551+
target=peter,
552+
room_id=f"!nonexistent:{fake_remote_host}",
553+
new_membership="join",
554+
remote_room_hosts=[fake_remote_host],
555+
)
556+
),
557+
NotFoundError,
558+
)
559+
560+
# Check that a remote join was attempted.
561+
self.assertEqual(mocked_remote_join.call_count, 1)
562+
535563
def test_get_room_state(self):
536564
"""Tests that a module can retrieve the state of a room through the module API."""
537565
user_id = self.register_user("peter", "hackme")

0 commit comments

Comments
 (0)