def test_ban_without_room(self, disconnect_user): """ Test banning a user without room """ res = self.chat_command(self.resource, "User") self.assertEqual(len(res), 1) self.assertRegex(res[0], "Unknown user") disconnect_user.assert_not_called() user = UserFactory(online=True, connection=self.connection) target_user = UserFactory(online=True) res = self.chat_command(self.resource, target_user.name) self.assertEqual(len(res), 1) self.assertRegex(res[0], "Not authorize") disconnect_user.assert_not_called() user.rank = self.chat_command.permission.value res = self.chat_command(self.resource, target_user.name) self.assertTrue(models.Ban.is_ban(self.session, user_id=target_user.id)) disconnect_user.assert_called_with(target_user.id) self.assertIsNone(res)
def test_kick_without_room(self, disconnect_user): """ Test banning a user without room """ res = self.chat_command(self.resource, "User") self.assertEqual(len(res), 1) self.assertRegex(res[0], "Unknown user") disconnect_user.assert_not_called() user = UserFactory(online=True, connection=self.connection) target_user = UserFactory(online=True) res = self.chat_command(self.resource, target_user.name) self.assertEqual(len(res), 1) self.assertRegex(res[0], "Not authorize") disconnect_user.assert_not_called() user.rank = self.chat_command.permission.value res = self.chat_command(self.resource, target_user.name) self.assertFalse( models.Ban.is_ban(self.session, user_id=target_user.id)) disconnect_user.assert_called_with(target_user.id) self.assertIsNone(res)
def test_can_without_room(self): """ Test can function without room """ if not self.chat_command.permission: self.assertEqual(self.chat_command.can(self.connection), not self.chat_command.room) return self.assertFalse(self.chat_command.can(self.connection)) user = UserFactory(connection=self.connection, online=True) self.assertFalse(self.chat_command.can(self.connection)) user.rank = self.chat_command.permission.value if self.chat_command.room: self.assertFalse(self.chat_command.can(self.connection)) else: self.assertTrue(self.chat_command.can(self.connection))
def test_can_without_room(self): """ Test can function without room """ if not self.chat_command.permission: self.assertEqual(self.chat_command.can(self.connection), not self.chat_command.room) return self.assertFalse(self.chat_command.can(self.connection)) user = UserFactory(connection=self.connection, online=True) self.assertFalse(self.chat_command.can(self.connection)) user.rank = self.chat_command.permission.value if self.chat_command.room: self.assertFalse(self.chat_command.can(self.connection)) else: self.assertTrue(self.chat_command.can(self.connection))