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

Commit

Permalink
Add - unit test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
buffless-matt committed Aug 4, 2022
1 parent 216dd62 commit 2514694
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest.mock import Mock
from unittest.mock import Mock, patch

from twisted.internet import defer

from synapse.api.constants import EduTypes, EventTypes
from synapse.api.errors import NotFoundError
from synapse.events import EventBase
from synapse.federation.units import Transaction
from synapse.handlers.presence import UserPresenceState
Expand Down Expand Up @@ -409,7 +410,8 @@ def test_send_local_online_presence_to_federation(self):

self.assertTrue(found_update)

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

# Check that no remote join attempts have occurred thus far.
self.assertFalse(mocked_remote_join.called)

# Necessary to fake a remote join.
fake_stream_id = 1
mocked_remote_join.return_value = "fake-event-id", fake_stream_id
fake_remote_host = f"{self.module_api.server_name}-remote"

# Given that the join is to be faked, we expect the relevant join event not to
# be persisted and the module API method to raise that.
self.get_failure(
defer.ensureDeferred(
self.module_api.update_room_membership(
sender=peter,
target=peter,
room_id=f"!nonexistent:{fake_remote_host}",
new_membership="join",
remote_room_hosts=[fake_remote_host],
)
),
NotFoundError,
)

# Check that a remote join was attempted.
self.assertEqual(mocked_remote_join.call_count, 1)

def test_get_room_state(self):
"""Tests that a module can retrieve the state of a room through the module API."""
user_id = self.register_user("peter", "hackme")
Expand Down

0 comments on commit 2514694

Please sign in to comment.