Пример #1
0
    def test_system_message_from_bot_on_save(self):
        """
        Tests that a system message is always registered as being created
        by the system bot.
        """
        msg = self.set_up_system_message()
        msg.member = MemberFactory()

        msg.save()

        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
        # Reload the message from the database and make sure it is by the bot
        msg = Message.objects.all()[0]
        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
Пример #2
0
    def test_system_message_from_bot_on_save(self):
        """
        Tests that a system message is always registered as being created
        by the system bot.
        """
        msg = self.set_up_system_message()
        msg.member = MemberFactory()

        msg.save()

        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
        # Reload the message from the database and make sure it is by the bot
        msg = Message.objects.all()[0]
        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
Пример #3
0
    def test_system_message_auto_from_bot(self):
        """
        Tests that a system message is always created with the bot user.
        """
        msg = self.set_up_system_message()

        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
Пример #4
0
    def test_system_message_auto_from_bot(self):
        """
        Tests that a system message is always created with the bot user.
        """
        msg = self.set_up_system_message()

        self.assertEquals(SystemMessage.get_bot_user(), msg.member)
Пример #5
0
    def test_get_bot_user(self):
        """
        Tests the ``get_bot_user`` method creates a bot user
        """
        bot = SystemMessage.get_bot_user()

        self.assertEquals("Bot", bot.display_name)
        self.assertEquals("bot", bot.lrz_id)
        self.assertEquals(1, Member.objects.count())
Пример #6
0
    def test_get_bot_user(self):
        """
        Tests the ``get_bot_user`` method creates a bot user
        """
        bot = SystemMessage.get_bot_user()

        self.assertEquals("Bot", bot.display_name)
        self.assertEquals("bot", bot.lrz_id)
        self.assertEquals(1, Member.objects.count())
Пример #7
0
    def set_up_system_message(self, text=None, auto_save=False):
        """
        Helper method which returns a :class:`chat.models.SystemMessage`
        instance.

        :param text: The text of the message to be created.
            If the ``text`` parameter is not provided, a placeholder text
            is used instead.

        :param auto_save: A boolean indicating whether the message should
            already be saved by the method.
        """
        if text is None:
            text = "System message text"

        message = SystemMessage(text=text, chat_room=self.chat_room)
        if auto_save:
            message.save()

        return message
Пример #8
0
    def set_up_system_message(self, text=None, auto_save=False):
        """
        Helper method which returns a :class:`chat.models.SystemMessage`
        instance.

        :param text: The text of the message to be created.
            If the ``text`` parameter is not provided, a placeholder text
            is used instead.

        :param auto_save: A boolean indicating whether the message should
            already be saved by the method.
        """
        if text is None:
            text = "System message text"

        message = SystemMessage(text=text, chat_room=self.chat_room)
        if auto_save:
            message.save()

        return message
Пример #9
0
    def test_create_member_left_notification(self):
        """
        Tests the manager method for creating notifications that a member
        has left a chat room.
        """
        message = SystemMessage.objects.create_member_left(
            self.member, self.chat_room)

        # Message is a system message?
        self.assertEquals(SystemMessage.get_bot_user(), message.member)
        # Correct text generated?
        self.assertEquals(self.get_member_left_text(), message.text)
        # In the correct chat room?
        self.assertEquals(self.chat_room, message.chat_room)
Пример #10
0
    def test_create_member_left_notification(self):
        """
        Tests the manager method for creating notifications that a member
        has left a chat room.
        """
        message = SystemMessage.objects.create_member_left(
            self.member, self.chat_room)

        # Message is a system message?
        self.assertEquals(SystemMessage.get_bot_user(), message.member)
        # Correct text generated?
        self.assertEquals(self.get_member_left_text(), message.text)
        # In the correct chat room?
        self.assertEquals(self.chat_room, message.chat_room)
Пример #11
0
    def test_bot_user_auto_created(self):
        """
        Tests that the bot user is automatically created when it doesn't
        already exist prior to creating a :class:`chat.models.SystemMessage`
        """
        # Sanity check -- the bot does not exist
        self.assertEquals(0, Member.objects.count())

        self.set_up_system_message(auto_save=True)

        # The bot now exists?
        self.assertEquals(1, Member.objects.count())
        bot = Member.objects.all()[0]
        self.assertEquals("Bot", bot.display_name)
        # It is also the same object as returned by the get_bot_user?
        self.assertEquals(SystemMessage.get_bot_user(), bot)
Пример #12
0
    def test_bot_user_auto_created(self):
        """
        Tests that the bot user is automatically created when it doesn't
        already exist prior to creating a :class:`chat.models.SystemMessage`
        """
        # Sanity check -- the bot does not exist
        self.assertEquals(0, Member.objects.count())

        self.set_up_system_message(auto_save=True)

        # The bot now exists?
        self.assertEquals(1, Member.objects.count())
        bot = Member.objects.all()[0]
        self.assertEquals("Bot", bot.display_name)
        # It is also the same object as returned by the get_bot_user?
        self.assertEquals(SystemMessage.get_bot_user(), bot)