示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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")