Exemple #1
0
class TellTests(unittest.TestCase):

    def get_jid(self, nick):
        if nick == 'myself': return '*****@*****.**'
        if nick == 'ZhuLi': return '*****@*****.**'
        if nick == 'Sweetiebot': return '*****@*****.**'
        if nick == 'sender': return '*****@*****.**'

    def setUp(self):
        self.bot = MagicMock()
        self.bot.get_jid_from_nick.side_effect = self.get_jid
        self.store = FakeRedis()

        self.tell = SweetieTell(self.bot, self.store)

    def test_can_tell_someone_a_thing(self):
        response = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Message received for [email protected]', response)

        response = self.tell.get_messages_for(create_message_zhuli('hello there'))
        self.assertEqual('ZhuLi, sender left you a message: Do the thing!', response)

        response = self.tell.get_messages_for(create_message_myself('anybody left me a message?'))
        self.assertIsNone(response)

        response = self.tell.get_messages_for(create_message_zhuli('another thing'))
        # zhuli shouldn't get pinged a second time
        self.assertIsNone(response)

    def test_denies_telling_someone_two_things(self):
        r1 = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        r2 = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Sorry, you\'ve already left a message for ZhuLi', r2)

    def test_denies_tell_in_pm(self):
        response = self.tell.tell(create_message('!tell ZhuLi Do another thing!', is_pm=True))
        self.assertEqual('Sorry, you can\'t use !tell in a PM', response)

    def test_denies_tell_self(self):
        response = self.tell.tell(create_message_myself('!tell myself to do a thing'))
        self.assertEqual('Talking to yourself is more efficient in real life than on jabber', response)

    def test_denies_tell_bot(self):
        response = self.tell.tell(create_message_myself('!tell Sweetiebot to do a thing'))
        self.assertEqual('I\'m right here, you know', response)

    def test_denies_tell_to_unknown_person(self):
        response = self.tell.tell(create_message('!tell nobody to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'nobody\' is', response)

    def test_can_remember_nicks_not_in_chat(self):
        response = self.tell.tell(create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'AfkPerson\' is', response)

        self.tell.nicktojid.on_presence(Presence('[email protected]/AfkPerson', '*****@*****.**', None, None))

        response = self.tell.tell(create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Message received for [email protected]', response)
Exemple #2
0
class TellTests(unittest.TestCase):
    def get_jid(self, nick):
        if nick == 'myself': return '*****@*****.**'
        if nick == 'ZhuLi': return '*****@*****.**'
        if nick == 'Sweetiebot': return '*****@*****.**'
        if nick == 'sender': return '*****@*****.**'

    def setUp(self):
        self.bot = MagicMock()
        self.bot.get_jid_from_nick.side_effect = self.get_jid
        self.store = FakeRedis()

        self.tell = SweetieTell(self.bot, self.store)

    def test_can_tell_someone_a_thing(self):
        response = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Message received for [email protected]', response)

        response = self.tell.get_messages_for(
            create_message_zhuli('hello there'))
        self.assertEqual('ZhuLi, sender left you a message: Do the thing!',
                         response)

        response = self.tell.get_messages_for(
            create_message_myself('anybody left me a message?'))
        self.assertIsNone(response)

        response = self.tell.get_messages_for(
            create_message_zhuli('another thing'))
        # zhuli shouldn't get pinged a second time
        self.assertIsNone(response)

    def test_can_tell_someone_two_things(self):
        r1 = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Message received for [email protected]', r1)

        r2 = self.tell.tell(create_message('!tell ZhuLi Do another thing!'))
        self.assertEqual(
            'Message received for [email protected] (appended to previous message)',
            r2)

        r3 = self.tell.get_messages_for(create_message_zhuli('hello~~'))
        self.assertEqual(
            'ZhuLi, sender left you a message: Do the thing!\nDo another thing!',
            r3)

    def test_denies_tell_in_pm(self):
        response = self.tell.tell(
            create_message('!tell ZhuLi Do another thing!', is_pm=True))
        self.assertEqual('Sorry, you can\'t use !tell in a PM', response)

    def test_denies_tell_self(self):
        response = self.tell.tell(
            create_message_myself('!tell myself to do a thing'))
        self.assertEqual(
            'Talking to yourself is more efficient in real life than on jabber',
            response)

    def test_denies_tell_bot(self):
        response = self.tell.tell(
            create_message_myself('!tell Sweetiebot to do a thing'))
        self.assertEqual('I\'m right here, you know', response)

    def test_denies_tell_to_unknown_person(self):
        response = self.tell.tell(create_message('!tell nobody to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'nobody\' is', response)

    def test_denies_tell_with_empty_message(self):
        response = self.tell.tell(create_message('!tell ZhuLi'))
        self.assertEqual('A message is required', response)

    def test_can_remember_nicks_not_in_chat(self):
        response = self.tell.tell(
            create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'AfkPerson\' is', response)

        self.tell.nicktojid.on_presence(
            Presence('[email protected]/AfkPerson', '*****@*****.**',
                     None, None))

        response = self.tell.tell(
            create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Message received for [email protected]', response)

    def test_message_length_cannot_exceed_limit(self):
        response = self.tell.tell(
            create_message('!tell ZhuLi ' + ('do a thing' * 1000)))
        self.assertEqual('Sorry, that message is too long (1000 char maximum)',
                         response)

    def test_combined_message_length_cannot_exceed_limit(self):
        r1 = self.tell.tell(
            create_message('!tell ZhuLi ' + ('do a thing' * 90)))
        r2 = self.tell.tell(
            create_message('!tell ZhuLi ' + ('do a thing' * 11)))
        # the count here is technically inaccurate because the message text contains 'sender left you a message:'
        self.assertEqual(
            'Sorry, that message is too long (1000 char maximum; you\'ve already used ~927)',
            r2)
Exemple #3
0
class TellTests(unittest.TestCase):

    def get_jid(self, nick):
        if nick == 'myself': return '*****@*****.**'
        if nick == 'ZhuLi': return '*****@*****.**'
        if nick == 'Sweetiebot': return '*****@*****.**'
        if nick == 'sender': return '*****@*****.**'

    def setUp(self):
        self.bot = MagicMock()
        self.bot.get_jid_from_nick.side_effect = self.get_jid
        self.store = FakeRedis()

        self.tell = SweetieTell(self.bot, self.store)

    def test_can_tell_someone_a_thing(self):
        response = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Message received for [email protected]', response)

        response = self.tell.get_messages_for(create_message_zhuli('hello there'))
        self.assertEqual('ZhuLi, sender left you a message: Do the thing!', response)

        response = self.tell.get_messages_for(create_message_myself('anybody left me a message?'))
        self.assertIsNone(response)

        response = self.tell.get_messages_for(create_message_zhuli('another thing'))
        # zhuli shouldn't get pinged a second time
        self.assertIsNone(response)

    def test_can_tell_someone_two_things(self):
        r1 = self.tell.tell(create_message('!tell ZhuLi Do the thing!'))
        self.assertEqual('Message received for [email protected]', r1)

        r2 = self.tell.tell(create_message('!tell ZhuLi Do another thing!'))
        self.assertEqual('Message received for [email protected] (appended to previous message)', r2)

        r3 = self.tell.get_messages_for(create_message_zhuli('hello~~'))
        self.assertEqual('ZhuLi, sender left you a message: Do the thing!\nDo another thing!', r3)

    def test_denies_tell_in_pm(self):
        response = self.tell.tell(create_message('!tell ZhuLi Do another thing!', is_pm=True))
        self.assertEqual('Sorry, you can\'t use !tell in a PM', response)

    def test_denies_tell_self(self):
        response = self.tell.tell(create_message_myself('!tell myself to do a thing'))
        self.assertEqual('Talking to yourself is more efficient in real life than on jabber', response)

    def test_denies_tell_bot(self):
        response = self.tell.tell(create_message_myself('!tell Sweetiebot to do a thing'))
        self.assertEqual('I\'m right here, you know', response)

    def test_denies_tell_to_unknown_person(self):
        response = self.tell.tell(create_message('!tell nobody to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'nobody\' is', response)

    def test_denies_tell_with_empty_message(self):
        response = self.tell.tell(create_message('!tell ZhuLi'))
        self.assertEqual('A message is required', response)

    def test_can_remember_nicks_not_in_chat(self):
        response = self.tell.tell(create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Sorry, I don\'t know who \'AfkPerson\' is', response)

        self.tell.nicktojid.on_presence(Presence('[email protected]/AfkPerson', '*****@*****.**', None, None))

        response = self.tell.tell(create_message('!tell AfkPerson to do a thing'))
        self.assertEqual('Message received for [email protected]', response)

    def test_message_length_cannot_exceed_limit(self):
        response = self.tell.tell(create_message('!tell ZhuLi ' + ('do a thing' * 1000)))
        self.assertEqual('Sorry, that message is too long (1000 char maximum)', response)

    def test_combined_message_length_cannot_exceed_limit(self):
        r1 = self.tell.tell(create_message('!tell ZhuLi ' + ('do a thing' * 90)))
        r2 = self.tell.tell(create_message('!tell ZhuLi ' + ('do a thing' * 11)))
        # the count here is technically inaccurate because the message text contains 'sender left you a message:'
        self.assertEqual('Sorry, that message is too long (1000 char maximum; you\'ve already used ~927)', r2)