示例#1
0
 def test_cannot_send_message_to_other_user_if_sent_too_many_emails_2(self):
     self._create_users(users_count=20)
     chats = dict()
     for i in range(4):
         chats[str(i)] = ChatFactory(ent1=self.user_1, ent2=getattr(self, "user_{}".format(3 + i)))
         Message.objects.send_message(from_entity=self.user_1, chat=chats[str(i)], text='*****@*****.**')
         sleep(0.01)
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
     for i in range(15):
         chats[str(4 + i)] = ChatFactory(ent1=self.user_1, ent2=getattr(self, "user_{}".format(4 + 3 + i)))
         Message.objects.send_message(from_entity=self.user_1, chat=chats[str(4 + i)], text='*****@*****.**')
         sleep(0.01)
         self.assertFalse(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
     for i in range(4):
         Message.objects.send_message(from_entity=getattr(self, "user_{}".format(3 + i)), chat=chats[str(i)], text='Hello!')
         sleep(0.01)
         self.assertFalse(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
     for i in range(12):
         Message.objects.send_message(from_entity=getattr(self, "user_{}".format(4 + 3 + i)), chat=chats[str(4 + i)], text='Hello!')
         sleep(0.01)
     self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
     self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
     self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
     self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
示例#2
0
 def set_up(self):
     super().set_up()
     self.user_1 = ActiveUserFactory()
     self.user_2 = ActiveUserFactory()
     self.user_3 = ActiveUserFactory()
     self.chat_1_2 = ChatFactory(ent1=self.user_1, ent2=self.user_2)
     self.chat_1_3 = ChatFactory(ent1=self.user_1, ent2=self.user_3)
示例#3
0
        def test_tag(self):
            user_1 = ActiveUserFactory()
            chats = [
                ChatFactory(ent1=user_1),  # 0 - no messages, no read mark
                ChatFactory(ent1=user_1),  # 1 - no messages, has read mark
                ChatFactory(ent1=user_1),  # 2 - has messages, no read mark
                ChatFactory(ent1=user_1),  # 3 - has messages, has read mark, read
                ChatFactory(ent1=user_1),  # 4 - has messages, has read mark, unread
            ]

            def _message(index):
                Message.objects.send_message(from_entity=chats[index].ent2, chat=chats[index], text='text')
                sleep(0.1)

            def _mark(index):
                chats[index].mark_read(entity=user_1)
                sleep(0.1)

            _message(2)
            _message(3)
            _message(4)
            _mark(1)
            _mark(3)
            _mark(4)
            _message(4)

            output = core_messages_tags_and_filters.annotate_chats_with_read_marks(chat_list=chats, entity=user_1)
            self.assertEqual(first=output, second='')
            self.assertFalse(expr=chats[0].is_unread)
            self.assertFalse(expr=chats[1].is_unread)
            self.assertTrue(expr=chats[2].is_unread)
            self.assertFalse(expr=chats[3].is_unread)
            self.assertTrue(expr=chats[4].is_unread)
示例#4
0
        def test_tag(self):
            user_1 = ActiveUserFactory()
            user_2 = ActiveUserFactory()
            user_3 = ActiveUserFactory()

            chats = [
                ChatFactory(ent1=user_1, ent2=user_2),
                ChatFactory(ent1=user_3, ent2=user_1),
                ChatFactory(ent1=user_2, ent2=user_3),
            ]

            Message.objects.send_message(from_entity=user_1, chat=chats[0], text='text')
            sleep(0.1)
            Message.objects.send_message(from_entity=user_2, chat=chats[0], text='text')
            sleep(0.1)
            Message.objects.send_message(from_entity=user_2, chat=chats[0], text='text')
            sleep(0.1)

            Message.objects.send_message(from_entity=user_3, chat=chats[1], text='text')
            sleep(0.1)
            Message.objects.send_message(from_entity=user_1, chat=chats[1], text='text')
            sleep(0.1)
            Message.objects.send_message(from_entity=user_3, chat=chats[1], text='text')
            sleep(0.1)

            Message.objects.send_message(from_entity=user_2, chat=chats[2], text='text')
            sleep(0.1)
            Message.objects.send_message(from_entity=user_3, chat=chats[2], text='text')
            sleep(0.1)

            self.assertEqual(first=core_messages_tags_and_filters.unread_chats_count(entity=user_1), second=1 + 1 + 0)
            self.assertEqual(first=core_messages_tags_and_filters.unread_chats_count(entity=user_2), second=0 + 0 + 1)
            self.assertEqual(first=core_messages_tags_and_filters.unread_chats_count(entity=user_3), second=0 + 0 + 0)
示例#5
0
 def set_up(self):
     super().set_up()
     ChatFactory(is_group=True)
     self.user1 = ActiveUserFactory()
     self.user2 = ActiveUserFactory()
     self.user3 = ActiveUserFactory()
     self.chat_1_2 = ChatFactory(ent1=self.user1, ent2=self.user2)
     self.chat_1_2_3 = ChatFactory(group=(self.user1, self.user2, self.user3))
示例#6
0
 def set_up(self):
     super().set_up()
     self.user1 = ActiveUserFactory()
     self.user2 = ActiveUserFactory()
     self.user3 = ActiveUserFactory()
     self.chat_1_2 = ChatFactory(ent1=self.user1, ent2=self.user2)
     self.chat_2_3 = ChatFactory(ent1=self.user2, ent2=self.user3)
     self.chat_3_1 = ChatFactory(ent1=self.user3, ent2=self.user1)
示例#7
0
 def test_get_slug_group_chat(self):
     user_1 = self.get_active_user_doron()
     user_2 = self.get_active_user_jennifer()
     user_3 = ActiveUserFactory()
     user_4 = ActiveUserFactory()
     chat = ChatFactory(ent1=None,
                        ent2=None,
                        is_group=True,
                        group=[user_1, user_2, user_3, user_4])
     self.assertEqual(first=chat.get_slug(current_user=user_1),
                      second=chat.id)
示例#8
0
 def set_up(self):
     super().set_up()
     self.user_1 = ActiveUserFactory()
     self.user_2 = ActiveUserFactory()
     self.user_3 = ActiveUserFactory()
     self.chat_1_2 = ChatFactory(ent1=self.user_1, ent2=self.user_2)
     self.chat_2_3 = ChatFactory(ent1=self.user_2, ent2=self.user_3)
     self.chat_3_1 = ChatFactory(ent1=self.user_3, ent2=self.user_1)
     self.chat_url = '/messages/{}/'.format(
         self.chat_1_2.get_slug(current_user=self.user_1))
     self.page_url = '/messages/{}/send/'.format(self.chat_1_2.id)
     self.data = {
         'text': 'Hi Hi Hi',
     }
示例#9
0
        def test_tag(self):
            user1 = ActiveUserFactory()
            user2 = ActiveUserFactory()
            chat = ChatFactory(ent1=user1, ent2=user2)
            messages = [
                Message.objects.send_message(from_entity=user2,
                                             chat=chat,
                                             text='User 2 First Message'),
                Message.objects.send_message(from_entity=user1,
                                             chat=chat,
                                             text='User 1 Message'),
                Message.objects.send_message(from_entity=user2,
                                             chat=chat,
                                             text='User 2 Second Message'),
            ]
            self.assertEqual(first=ReadMark.objects.count(), second=2)

            output = core_messages_tags.annotate_messages_with_read_marks(
                messages, user1)
            self.assertEqual(first=output, second='')
            self.assertFalse(expr=messages[0].is_unread)
            self.assertFalse(expr=messages[1].is_unread)
            self.assertTrue(expr=messages[2].is_unread)

            output = core_messages_tags.annotate_messages_with_read_marks(
                messages, user2)
            self.assertEqual(first=output, second='')
            self.assertFalse(expr=messages[0].is_unread)
            self.assertFalse(expr=messages[1].is_unread)
            self.assertFalse(expr=messages[2].is_unread)
示例#10
0
 def set_up(self):
     super().set_up()
     self.user_1 = ActiveUserFactory()
     self.user_2 = ActiveUserFactory()
     self.user_3 = ActiveUserFactory()
     self.chat_1_2 = ChatFactory(ent1=self.user_1, ent2=self.user_2)
     self.chat_2_3 = ChatFactory(ent1=self.user_2, ent2=self.user_3)
     self.chat_3_1 = ChatFactory(ent1=self.user_3, ent2=self.user_1)
     Message.objects.send_message(from_entity=self.user_1,
                                  chat=self.chat_1_2,
                                  text='My message')
     Message.objects.send_message(from_entity=self.user_2,
                                  chat=self.chat_1_2,
                                  text='First unread message')
     Message.objects.send_message(from_entity=self.user_2,
                                  chat=self.chat_1_2,
                                  text='Second unread message')
     self.page_url = '/messages/{}/'.format(self.chat_1_2.id)
示例#11
0
 def set_up(self):
     super().set_up()
     self.user_1 = ActiveUserFactory()
     self.chat = ChatFactory(ent1=self.user_1)
     self.messages = []
     self.messages.append(
         Message.objects.send_message(from_entity=self.chat.ent1,
                                      chat=self.chat,
                                      text='text'))
     sleep(0.1)
     self.messages.append(
         Message.objects.send_message(from_entity=self.chat.ent2,
                                      chat=self.chat,
                                      text='text'))
     sleep(0.1)
     self.chat_url = '/messages/{}/'.format(
         self.chat.get_slug(current_user=self.user_1))
     self.page_url = '/messages/{}/mark-read/'.format(self.chat.id)
示例#12
0
 def test_tag(self):
     user1 = ActiveUserFactory()
     user2 = ActiveUserFactory()
     chat = ChatFactory(ent1=user1, ent2=user2)
     self.assertEqual(first=core_messages_tags.get_other_participant(
         chat, user1).id,
                      second=user2.id)
     self.assertEqual(first=core_messages_tags.get_other_participant(
         chat, user2).id,
                      second=user1.id)
示例#13
0
 def test_cannot_send_message_to_other_user_if_sent_too_many_emails_3(self):
     self._create_users(users_count=30)
     self.user_1.date_created -= relativedelta(days=30)
     self.user_1.save_user_and_profile()
     chats = dict()
     for i in range(19):
         chats[str(i)] = ChatFactory(ent1=self.user_1, ent2=getattr(self, "user_{}".format(3 + i)))
         Message.objects.send_message(from_entity=self.user_1, chat=chats[str(i)], text='*****@*****.**')
         sleep(0.01)
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
     for i in range(5):
         chats[str(19 + i)] = ChatFactory(ent1=self.user_1, ent2=getattr(self, "user_{}".format(19 + 3 + i)))
         Message.objects.send_message(from_entity=self.user_1, chat=chats[str(19 + i)], text='*****@*****.**')
         sleep(0.01)
         self.assertFalse(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.send_message', obj=self.user_3))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_2))
         self.assertTrue(expr=self.user_1.has_perm(perm='messages.view_send_message_button', obj=self.user_3))
示例#14
0
    class SendMessageToChatViewTestCase(SiteTestCase):
        def set_up(self):
            super().set_up()
            self.user_1 = ActiveUserFactory()
            self.user_2 = ActiveUserFactory()
            self.user_3 = ActiveUserFactory()
            self.chat_1_2 = ChatFactory(ent1=self.user_1, ent2=self.user_2)
            self.chat_2_3 = ChatFactory(ent1=self.user_2, ent2=self.user_3)
            self.chat_3_1 = ChatFactory(ent1=self.user_3, ent2=self.user_1)
            self.chat_url = '/messages/{}/'.format(
                self.chat_1_2.get_slug(current_user=self.user_1))
            self.page_url = '/messages/{}/send/'.format(self.chat_1_2.id)
            self.data = {
                'text': 'Hi Hi Hi',
            }

        def test_visitor_has_no_access(self):
            self.client.logout()
            r = self.client.post(path=self.page_url, data=self.data)
            self.assertEqual(first=r.status_code, second=403)

        def test_get_redirects_to_chat_page(self):
            self.client.login(username=self.user_1.slug,
                              password=tests_settings.USER_PASSWORD)
            r = self.client.get(path=self.page_url)
            self.assertRedirects(response=r,
                                 expected_url=self.chat_url,
                                 status_code=302,
                                 target_status_code=200)

        def test_user_can_write_to_a_chat_they_have_access_to(self):
            self.client.login(username=self.user_1.slug,
                              password=tests_settings.USER_PASSWORD)
            r = self.client.post(path=self.page_url, data=self.data)
            self.assertRedirects(response=r,
                                 expected_url=self.chat_url,
                                 status_code=302,
                                 target_status_code=200)

        def test_cannot_write_to_other_user_if_blocked(self):
            self.client.login(username=self.user_1.slug,
                              password=tests_settings.USER_PASSWORD)
            Block.objects.block(blocker=self.user_1, blocked=self.user_2)
            r = self.client.post(path=self.page_url, data=self.data)
            self.assertEqual(first=r.status_code, second=403)

        def test_cannot_write_to_other_user_if_blocking(self):
            self.client.login(username=self.user_1.slug,
                              password=tests_settings.USER_PASSWORD)
            Block.objects.block(blocker=self.user_2, blocked=self.user_1)
            r = self.client.post(path=self.page_url, data=self.data)
            self.assertEqual(first=r.status_code, second=403)
示例#15
0
 def test_mark(self):
     user = ActiveUserFactory()
     chat = ChatFactory(ent1=user)
     self.assertEqual(first=ReadMark.objects.count(), second=0)
     rmark = ReadMark.objects.mark(chat, user)
     self.assertEqual(first=ReadMark.objects.count(), second=1)
     self.assertEqual(first=rmark.chat, second=chat)
     self.assertEqual(first=rmark.entity.id, second=user.id)
     old_rmark = rmark
     sleep(1)
     rmark = ReadMark.objects.mark(chat, user)
     self.assertEqual(first=rmark.id, second=old_rmark.id)
     self.assertGreater(a=rmark.date_updated, b=old_rmark.date_updated)
示例#16
0
 def test_get_slug_private_chat(self):
     user_1 = self.get_active_user_doron()
     user_2 = self.get_active_user_jennifer()
     chat = ChatFactory(ent1=user_1, ent2=user_2)
     self.assertEqual(first=chat.get_slug(current_user=user_1),
                      second=user_2.slug)
     self.assertEqual(first=chat.get_slug(current_user=user_2),
                      second=user_1.slug)
     self.assertNotEqual(first=chat.get_slug(current_user=user_1),
                         second=user_1.slug)
     self.assertNotEqual(first=chat.get_slug(current_user=user_2),
                         second=user_2.slug)
     self.assertEqual(first=chat.get_slug(current_user=user_1),
                      second="jennifer-connelly")
     self.assertEqual(first=chat.get_slug(current_user=user_2),
                      second="doron-matalon")
示例#17
0
 def test_sending_message_to_existing_chat(self):
     user1 = ActiveUserFactory()
     chat = ChatFactory(ent1=user1)
     self.assertEqual(first=Chat.objects.count(), second=1)
     self.assertEqual(first=ReadMark.objects.count(), second=0)
     message = Message.objects.send_message(from_entity=user1, chat=chat, text='Hello2')
     self.assertEqual(first=Chat.objects.count(), second=1)
     self.assertEqual(first=message.chat, second=chat)
     self.assertEqual(first=message.sender_id, second=user1.id)
     self.assertEqual(first=message.text, second='Hello2')
     self.assertEqual(first=ReadMark.objects.count(), second=1)
     rmark = ReadMark.objects.latest()
     self.assertEqual(first=rmark.chat, second=chat)
     self.assertEqual(first=rmark.entity_id, second=user1.id)
示例#18
0
 def test_form_to_chat_save(self):
     data = {
         'text': 'Hi!',
     }
     user = ActiveUserFactory()
     chat = ChatFactory(ent1=user)
     form = MessageForm(from_entity=user, chat=chat, data=data)
     self.assertTrue(expr=form.is_valid())
     message = form.save()
     self.assertEqual(first=message.chat, second=chat)
     self.assertEqual(first=message.sender.user, second=user)
     self.assertEqual(first=message.text, second='Hi!')
     chat = message.chat
     self.assertEqual(first=chat.last_message, second=message)
示例#19
0
    class MarkChatAsReadViewTestCase(SiteTestCase):
        def set_up(self):
            super().set_up()
            self.user_1 = ActiveUserFactory()
            self.chat = ChatFactory(ent1=self.user_1)
            self.messages = []
            self.messages.append(
                Message.objects.send_message(from_entity=self.chat.ent1,
                                             chat=self.chat,
                                             text='text'))
            sleep(0.1)
            self.messages.append(
                Message.objects.send_message(from_entity=self.chat.ent2,
                                             chat=self.chat,
                                             text='text'))
            sleep(0.1)
            self.chat_url = '/messages/{}/'.format(
                self.chat.get_slug(current_user=self.user_1))
            self.page_url = '/messages/{}/mark-read/'.format(self.chat.id)

        def test_visitor_has_no_access(self):
            self.client.logout()
            r = self.client.post(path=self.page_url)
            self.assertRedirects(response=r,
                                 expected_url='/login/?next={}'.format(
                                     self.page_url),
                                 status_code=302,
                                 target_status_code=200)

        def test_user_can_mark_chat_as_read(self):
            self.client.login(username=self.user_1.slug,
                              password=tests_settings.USER_PASSWORD)
            self.assertLess(
                a=ReadMark.objects.get(entity_id=self.user_1.id).date_updated,
                b=self.messages[1].date_created)
            r = self.client.post(path=self.page_url)
            self.assertRedirects(response=r,
                                 expected_url=self.chat_url,
                                 status_code=302,
                                 target_status_code=200)
            self.assertGreater(
                a=ReadMark.objects.get(entity_id=self.user_1.id).date_updated,
                b=self.messages[1].date_created)
示例#20
0
        def test_tag(self):
            user_1 = ActiveUserFactory()
            user_2 = ActiveUserFactory()
            chat = ChatFactory(ent1=user_1, ent2=user_2)
            messages = []
            messages.append(Message.objects.send_message(from_entity=user_2, chat=chat, text='User 2 First Message'))
            sleep(0.001)
            messages.append(Message.objects.send_message(from_entity=user_1, chat=chat, text='User 1 Message'))
            sleep(0.001)
            messages.append(Message.objects.send_message(from_entity=user_2, chat=chat, text='User 2 Second Message'))
            sleep(0.001)
            self.assertEqual(first=ReadMark.objects.count(), second=2)

            output = core_messages_tags_and_filters.annotate_messages_with_read_marks(message_list=messages, entity=user_1)
            self.assertEqual(first=output, second='')
            self.assertFalse(expr=messages[0].is_unread)
            self.assertFalse(expr=messages[1].is_unread)
            self.assertTrue(expr=messages[2].is_unread)

            output = core_messages_tags_and_filters.annotate_messages_with_read_marks(message_list=messages, entity=user_2)
            self.assertEqual(first=output, second='')
            self.assertFalse(expr=messages[0].is_unread)
            self.assertFalse(expr=messages[1].is_unread)
            self.assertFalse(expr=messages[2].is_unread)
示例#21
0
 def test_str_private_chat(self):
     user_1 = self.get_active_user_doron()
     user_2 = self.get_active_user_jennifer()
     chat = ChatFactory(ent1=user_1, ent2=user_2)
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer (0 messages, senders: None)>'.
             format(chat.id))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly (0 messages, senders: None)>"
             .format(chat.id))
     Message.objects.send_message(from_entity=user_1,
                                  chat=chat,
                                  text='Hello!')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer (1 message, sender: Doron)>'.
             format(chat.id))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly (1 message, sender: Doron Matalon)>"
             .format(chat.id))
     Message.objects.send_message(from_entity=user_1,
                                  chat=chat,
                                  text='Hi.')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer (2 messages, sender: Doron)>'.
             format(chat.id))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly (2 messages, sender: Doron Matalon)>"
             .format(chat.id))
     Message.objects.send_message(from_entity=user_2,
                                  chat=chat,
                                  text='Hi!')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer (3 messages, senders: Doron, Jennifer)>'
             .format(chat.id))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly (3 messages, senders: Doron Matalon, Jennifer Connelly)>"
             .format(chat.id))
示例#22
0
 def test_str_group_chat(self):
     user_1 = self.get_active_user_doron()
     user_2 = self.get_active_user_jennifer()
     user_3 = ActiveUserFactory()
     user_4 = ActiveUserFactory()
     chat = ChatFactory(ent1=None,
                        ent2=None,
                        is_group=True,
                        group=[user_1, user_2, user_3, user_4])
     self.assertEqual(
         first=str(chat),
         second="<Chat {}: {}, {}, {}, {} (0 messages, senders: None)>".
         format(chat.id, user_1.name, user_2.name, user_3.name,
                user_4.name))
     self.assertEqual(
         first=str(chat),
         second="<Chat {}: {}, {}, {}, {} (0 messages, senders: None)>".
         format(chat.id, user_1.profile.get_name(),
                user_2.profile.get_name(), user_3.profile.get_name(),
                user_4.profile.get_name()))
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron, Jennifer, {}, {} (0 messages, senders: None)>"
             .format(chat.id, user_3.name, user_4.name))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly, {}, {} (0 messages, senders: None)>"
             .format(chat.id, user_3.name, user_4.name))
     Message.objects.send_message(from_entity=user_1,
                                  chat=chat,
                                  text='Hello!')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer, {}, {} (1 message, sender: Doron)>'
             .format(chat.id, user_3.name, user_4.name))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly, {}, {} (1 message, sender: Doron Matalon)>"
             .format(chat.id, user_3.name, user_4.name))
     Message.objects.send_message(from_entity=user_1,
                                  chat=chat,
                                  text='Hi.')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer, {}, {} (2 messages, sender: Doron)>'
             .format(chat.id, user_3.name, user_4.name))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly, {}, {} (2 messages, sender: Doron Matalon)>"
             .format(chat.id, user_3.name, user_4.name))
     Message.objects.send_message(from_entity=user_2,
                                  chat=chat,
                                  text='Hi!')
     if (django_settings.SITE_ID == django_settings.SPEEDY_MATCH_SITE_ID
         ):
         self.assertEqual(
             first=str(chat),
             second=
             '<Chat {}: Doron, Jennifer, {}, {} (3 messages, senders: Doron, Jennifer)>'
             .format(chat.id, user_3.name, user_4.name))
     else:
         self.assertEqual(
             first=str(chat),
             second=
             "<Chat {}: Doron Matalon, Jennifer Connelly, {}, {} (3 messages, senders: Doron Matalon, Jennifer Connelly)>"
             .format(chat.id, user_3.name, user_4.name))
示例#23
0
 def test_id_length(self):
     chat = ChatFactory()
     self.assertEqual(first=len(chat.id), second=20)