async def test_respond_user_role(self): existing_power_levels = { "ban": 50, "events": {"m.room.name": 100, "m.room.power_levels": 100}, "events_default": 0, "invite": 50, "kick": 50, "notifications": {"room": 20}, "redact": 50, "state_default": 50, "users": {"@example:localhost": 100}, "users_default": 0, } role_events = [ ( events.UserRole( 75, target="!test:localhost", user_id="@test:localhost" ), 75, ), ( events.UserRole( "mod", target="!test:localhost", user_id="@test:localhost" ), 50, ), ( events.UserRole( "admin", target="!test:localhost", user_id="@test:localhost" ), 100, ), ] for event, pl in role_events: with OpsDroid() as opsdroid, amock.patch( api_string.format("send_state_event") ) as patched_send: with amock.patch( api_string.format("get_power_levels") ) as patched_power_levels: opsdroid.connectors = [self.connector] patched_power_levels.return_value = asyncio.Future() patched_power_levels.return_value.set_result(existing_power_levels) patched_send.return_value = asyncio.Future() patched_send.return_value.set_result({}) await self.connector.send(event) modified_power_levels = deepcopy(existing_power_levels) modified_power_levels["users"]["@test:localhost"] = pl assert patched_send.called_once_with( "!test:localhost", "m.room.power_levels", existing_power_levels, state_key=None, )
async def test_invalid_role(self): with self.assertRaises(ValueError): await self.connector._set_user_role( events.UserRole("wibble", target="!test:localhost"))