|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 |
| -from unittest.mock import Mock |
| 14 | +from unittest.mock import Mock, patch |
15 | 15 |
|
16 | 16 | from twisted.internet import defer
|
17 | 17 |
|
18 | 18 | from synapse.api.constants import EduTypes, EventTypes
|
| 19 | +from synapse.api.errors import NotFoundError |
19 | 20 | from synapse.events import EventBase
|
20 | 21 | from synapse.federation.units import Transaction
|
21 | 22 | from synapse.handlers.presence import UserPresenceState
|
@@ -409,7 +410,8 @@ def test_send_local_online_presence_to_federation(self):
|
409 | 410 |
|
410 | 411 | self.assertTrue(found_update)
|
411 | 412 |
|
412 |
| - def test_update_membership(self): |
| 413 | + @patch("synapse.handlers.room_member.RoomMemberMasterHandler._remote_join") |
| 414 | + def test_update_membership(self, mocked_remote_join): |
413 | 415 | """Tests that the module API can update the membership of a user in a room."""
|
414 | 416 | peter = self.register_user("peter", "hackme")
|
415 | 417 | lesley = self.register_user("lesley", "hackme")
|
@@ -532,6 +534,32 @@ def test_update_membership(self):
|
532 | 534 | self.assertEqual(res["displayname"], "simone")
|
533 | 535 | self.assertIsNone(res["avatar_url"])
|
534 | 536 |
|
| 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 | + |
535 | 563 | def test_get_room_state(self):
|
536 | 564 | """Tests that a module can retrieve the state of a room through the module API."""
|
537 | 565 | user_id = self.register_user("peter", "hackme")
|
|
0 commit comments