def test_callback_message_with_prefix_optional(self): self.dummy = DummyBackend({'BOT_PREFIX_OPTIONAL_ON_CHAT': True}) m = self.makemessage("return_args_as_str one two") self.dummy.callback_message(m) self.assertEquals("one two", self.dummy.pop_message().body) # Groupchat should still require the prefix m.type = "groupchat" m.frm = SimpleMUCOccupant("someone", "room") self.dummy.callback_message(m) self.assertRaises(Empty, self.dummy.pop_message, *[], **{'block': False}) m = self.makemessage("!return_args_as_str one two", from_=SimpleMUCOccupant("someone", "room"), type="groupchat") self.dummy.callback_message(m) self.assertEquals("one two", self.dummy.pop_message().body)
def __init__(self, name, occupants=None, topic=None, bot=None): """ :param name: Name of the room :param occupants: Occupants of the room :param topic: The MUC's topic """ if occupants is None: occupants = [] self._occupants = occupants self._topic = topic self._bot = bot self._name = name self._bot_mucid = SimpleMUCOccupant( self._bot.bot_config.BOT_IDENTITY['username'], self._name)
def test_access_controls(self): tests = [ dict(message=self.makemessage("!command"), acl={}, acl_default={}, expected_response="Regular command"), dict(message=self.makemessage("!regex command with prefix"), acl={}, acl_default={}, expected_response="Regex command"), dict( message=self.makemessage("!command"), acl={}, acl_default={ 'allowmuc': False, 'allowprivate': False }, expected_response= "You're not allowed to access this command via private message to me" ), dict( message=self.makemessage("regex command without prefix"), acl={}, acl_default={ 'allowmuc': False, 'allowprivate': False }, expected_response= "You're not allowed to access this command via private message to me" ), dict( message=self.makemessage("!command"), acl={}, acl_default={ 'allowmuc': True, 'allowprivate': False }, expected_response= "You're not allowed to access this command via private message to me" ), dict(message=self.makemessage("!command"), acl={}, acl_default={ 'allowmuc': False, 'allowprivate': True }, expected_response="Regular command"), dict(message=self.makemessage("!command"), acl={'command': { 'allowprivate': True }}, acl_default={ 'allowmuc': False, 'allowprivate': False }, expected_response="Regular command"), dict(message=self.makemessage("!command", type="groupchat", from_=SimpleMUCOccupant( "someone", "room")), acl={'command': { 'allowrooms': ('room', ) }}, acl_default={}, expected_response="Regular command"), dict( message=self.makemessage("!command", type="groupchat", from_=SimpleMUCOccupant( "someone", "room")), acl={'command': { 'allowrooms': ('anotherroom@localhost', ) }}, acl_default={}, expected_response= "You're not allowed to access this command from this room", ), dict( message=self.makemessage("!command", type="groupchat", from_=SimpleMUCOccupant( "someone", "room")), acl={'command': { 'denyrooms': ('room', ) }}, acl_default={}, expected_response= "You're not allowed to access this command from this room", ), dict(message=self.makemessage("!command", type="groupchat", from_=SimpleMUCOccupant( "someone", "room")), acl={'command': { 'denyrooms': ('anotherroom', ) }}, acl_default={}, expected_response="Regular command"), ] for test in tests: self.dummy.bot_config.ACCESS_CONTROLS_DEFAULT = test['acl_default'] self.dummy.bot_config.ACCESS_CONTROLS = test['acl'] logger = logging.getLogger(__name__) logger.info("** message: {}".format(test['message'].body)) logger.info("** acl: {!r}".format(test['acl'])) logger.info("** acl_default: {!r}".format(test['acl_default'])) self.dummy.callback_message(test['message']) self.assertEqual(test['expected_response'], self.dummy.pop_message().body)
def test_occupants(self): # noqa room = self.bot.rooms()[0] assert len(room.occupants) == 1 assert SimpleMUCOccupant('err', 'testroom') in room.occupants
def test_mucidentifier_ineq2(self): a = SimpleMUCOccupant("foo", "room1") b = SimpleMUCOccupant("foo", "room2") self.assertFalse(a == b) self.assertNotEqual(a, b)
def test_mucidentifier_eq(self): a = SimpleMUCOccupant("foo", "room") b = SimpleMUCOccupant("foo", "room") self.assertTrue(a == b) self.assertEqual(a, b)