コード例 #1
0
ファイル: tests_views.py プロジェクト: srhrshr/zds-site
    def setUp(self):
        self.profile1 = ProfileFactory()
        self.profile2 = ProfileFactory()
        self.profile3 = ProfileFactory()

        self.hat, _ = Hat.objects.get_or_create(name__iexact='A hat', defaults={'name': 'A hat'})
        self.profile1.hats.add(self.hat)

        self.topic1 = PrivateTopicFactory(author=self.profile1.user)
        self.topic1.participants.add(self.profile2.user)
        self.post1 = PrivatePostFactory(
            privatetopic=self.topic1,
            author=self.profile1.user,
            position_in_topic=1)

        self.post2 = PrivatePostFactory(
            privatetopic=self.topic1,
            author=self.profile2.user,
            position_in_topic=2)

        self.assertTrue(
            self.client.login(
                username=self.profile1.user.username,
                password='******'
            )
        )
コード例 #2
0
    def test_success_leave_topic_as_participant(self):
        """
        Leaves a private topic when we are just in participants.
        """
        another_profile = ProfileFactory()
        another_private_topic = PrivateTopicFactory(
            author=another_profile.user)
        PrivatePostFactory(author=another_profile.user,
                           privatetopic=another_private_topic,
                           position_in_topic=1)
        another_private_topic.participants.add(self.profile.user)

        self.assertEqual(
            another_profile.user,
            PrivateTopic.objects.get(pk=another_private_topic.id).author)
        self.assertIn(
            self.profile.user,
            PrivateTopic.objects.get(
                pk=another_private_topic.id).participants.all())

        response = self.client.delete(
            reverse('api-mp-detail', args=[another_private_topic.id]))

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(
            another_profile.user,
            PrivateTopic.objects.get(pk=another_private_topic.id).author)
        self.assertNotIn(
            self.profile.user,
            PrivateTopic.objects.get(
                pk=another_private_topic.id).participants.all())
コード例 #3
0
ファイル: tests_views.py プロジェクト: srhrshr/zds-site
    def setUp(self):
        self.profile1 = ProfileFactory()
        self.profile2 = ProfileFactory()
        self.anonymous_account = UserFactory(username=settings.ZDS_APP['member']['anonymous_account'])
        self.bot_group = Group()
        self.bot_group.name = settings.ZDS_APP['member']['bot_group']
        self.bot_group.save()
        self.anonymous_account.groups.add(self.bot_group)
        self.anonymous_account.save()
        self.topic1 = PrivateTopicFactory(author=self.profile1.user)
        self.topic1.participants.add(self.profile2.user)
        self.post1 = PrivatePostFactory(
            privatetopic=self.topic1,
            author=self.profile1.user,
            position_in_topic=1)

        self.post2 = PrivatePostFactory(
            privatetopic=self.topic1,
            author=self.profile2.user,
            position_in_topic=2)

        self.assertTrue(
            self.client.login(
                username=self.profile1.user.username,
                password='******'
            )
        )
コード例 #4
0
ファイル: tests_models.py プロジェクト: Vultik/zds-site
    def test_get_last_answer(self):
        topic = PrivateTopicFactory(author=self.user2)
        PrivatePostFactory(privatetopic=topic, author=self.user2, position_in_topic=1)

        self.assertEqual(self.post2, self.topic1.get_last_answer())
        self.assertNotEqual(self.post1, self.topic1.get_last_answer())

        self.assertIsNone(topic.get_last_answer())
コード例 #5
0
 def setUp(self):
     self.author = ProfileFactory()
     self.user = ProfileFactory()
     self.topic = PrivateTopicFactory(author=self.author.user)
     self.topic.participants.add(self.user.user)
     self.post = PrivatePostFactory(privatetopic=self.topic,
                                    author=self.author.user,
                                    position_in_topic=1)
コード例 #6
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def setUp(self):
        self.profile1 = ProfileFactory()
        self.profile2 = ProfileFactory()
        self.topic1 = PrivateTopicFactory(author=self.profile1.user)
        self.topic1.participants.add(self.profile2.user)
        self.post1 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile1.user, position_in_topic=1)

        self.post2 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile2.user, position_in_topic=2)
コード例 #7
0
 def create_multiple_private_topics_for_member(
         self,
         user,
         number_of_users=settings.REST_FRAMEWORK['PAGINATE_BY']):
     return [
         PrivateTopicFactory(author=user)
         for private_topic in xrange(0, number_of_users)
     ]
コード例 #8
0
 def test_detail_private_post_with_wrong_identifiers(self):
     """
     Tries to get details of a private post in a wrong private topic.
     """
     another_private_topic = PrivateTopicFactory(author=self.profile.user)
     response = self.client.get(
         reverse('api-mp-message-detail',
                 args=[another_private_topic.id, self.private_post.id]))
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #9
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def test_fail_cite_post_not_in_current_topic(self):
        another_topic = PrivateTopicFactory(author=self.profile2.user)
        another_post = PrivatePostFactory(privatetopic=another_topic, author=self.profile2.user, position_in_topic=1)

        response = self.client.get(
            reverse("private-posts-new", args=[self.topic1.pk, self.topic1.slug()]) + "?cite={}".format(another_post.pk)
        )

        self.assertEqual(403, response.status_code)
コード例 #10
0
ファイル: tests_views.py プロジェクト: leroivi/zds-site
    def test_success_delete_topic_no_participants(self):
        topic = PrivateTopicFactory(author=self.profile1.user)
        self.client.force_login(self.profile1.user)
        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        response = self.client.post(reverse("mp-list-delete"),
                                    {"items": [topic.pk]})

        self.assertEqual(302, response.status_code)
        self.assertEqual(0, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #11
0
ファイル: tests_views.py プロジェクト: leroivi/zds-site
    def test_fail_delete_topic_not_belong_to_user(self):
        topic = PrivateTopicFactory(author=self.profile1.user)

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        self.client.force_login(self.profile2.user)

        self.client.post(reverse("mp-list-delete"), {"items": [topic.pk]})

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #12
0
    def setUp(self):
        self.profile = ProfileFactory()
        self.client = APIClient()
        client_oauth2 = create_oauth2_client(self.profile.user)
        authenticate_client(self.client, client_oauth2,
                            self.profile.user.username, 'hostel77')

        self.private_topic = PrivateTopicFactory(author=self.profile.user)

        get_cache(extensions_api_settings.DEFAULT_USE_CACHE).clear()
コード例 #13
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def test_success_delete_topic_no_participants(self):
        topic = PrivateTopicFactory(author=self.profile1.user)
        login_check = self.client.login(username=self.profile1.user.username, password="******")
        self.assertTrue(login_check)
        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        response = self.client.post(reverse("mp-list-delete"), {"items": [topic.pk]})

        self.assertEqual(302, response.status_code)
        self.assertEqual(0, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #14
0
    def test_create_post_not_in_participants(self):
        """
        Creates a post in a topic with no authorized permission (the user is not in the allowed participants)
        """
        other_profile = ProfileFactory()
        another_topic = PrivateTopicFactory(author=other_profile.user)

        data = {'text': 'Welcome to this private post!'}
        response = self.client.post(
            reverse('api-mp-message-list', args=[another_topic.id]), data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
コード例 #15
0
    def test_delete_private_topic_not_in_participants(self):
        """
        Gets an error 403 when the member doesn't have permission to display details about the private topic.
        """
        another_profile = ProfileFactory()
        another_private_topic = PrivateTopicFactory(
            author=another_profile.user)

        response = self.client.delete(
            reverse('api-mp-detail', args=[another_private_topic.id]), {})
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
コード例 #16
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def setUp(self):
        self.profile1 = ProfileFactory()
        self.profile2 = ProfileFactory()

        self.topic1 = PrivateTopicFactory(author=self.profile1.user)
        self.topic1.participants.add(self.profile2.user)
        self.post1 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile1.user, position_in_topic=1)

        self.post2 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile2.user, position_in_topic=2)

        self.assertTrue(self.client.login(username=self.profile1.user.username, password="******"))
コード例 #17
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def test_fail_delete_topic_not_belong_to_user(self):
        topic = PrivateTopicFactory(author=self.profile1.user)

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        login_check = self.client.login(username=self.profile2.user.username, password="******")
        self.assertTrue(login_check)

        self.client.post(reverse("mp-list-delete"), {"items": [topic.pk]})

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #18
0
ファイル: tests_views.py プロジェクト: srhrshr/zds-site
    def test_fail_topic_no_permission(self):
        topic = PrivateTopicFactory(author=self.profile1.user)

        login_check = self.client.login(
            username=self.profile2.user.username,
            password='******'
        )
        self.assertTrue(login_check)

        response = self.client.get(reverse('private-posts-list', args=[topic.pk, topic.slug]), follow=True)

        self.assertEqual(403, response.status_code)
コード例 #19
0
ファイル: tests_models.py プロジェクト: Vultik/zds-site
    def setUp(self):
        # scenario - topic1 :
        # post1 - user1 - unread
        # post2 - user2 - unread

        self.profile1 = ProfileFactory()
        self.profile2 = ProfileFactory()
        self.topic1 = PrivateTopicFactory(author=self.profile1.user)
        self.topic1.participants.add(self.profile2.user)
        self.post1 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile1.user, position_in_topic=1)

        self.post2 = PrivatePostFactory(privatetopic=self.topic1, author=self.profile2.user, position_in_topic=2)
コード例 #20
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def test_unicode_subtitle_answer(self):
        """To test unicode subtitle."""

        unicode_topic = PrivateTopicFactory(author=self.profile1.user, subtitle="Subtitle with accent àéè")
        unicode_topic.participants.add(self.profile2.user)
        unicode_post = PrivatePostFactory(privatetopic=unicode_topic, author=self.profile1.user, position_in_topic=1)

        response = self.client.post(
            reverse("private-posts-new", args=[unicode_topic.pk, unicode_topic.slug]),
            {"text": "answer", "last_post": unicode_post.pk},
            follow=True,
        )
        self.assertEqual(response.status_code, 200)
コード例 #21
0
ファイル: tests_views.py プロジェクト: Vultik/zds-site
    def test_topic_get_page_too_far(self):
        """ get a page that is too far yet"""

        login_check = self.client.login(username=self.profile1.user.username, password="******")
        self.assertTrue(login_check)

        # create many subjects (at least two pages)
        for i in range(1, settings.ZDS_APP["forum"]["topics_per_page"] + 5):
            topic = PrivateTopicFactory(author=self.profile1.user)
            topic.participants.add(self.profile2.user)
            PrivatePostFactory(privatetopic=topic, author=self.profile1.user, position_in_topic=1)

        response = self.client.get(reverse("mp-list") + "?page=42")
        self.assertEqual(response.status_code, 404)
コード例 #22
0
    def test_success_delete_topic_no_participants(self):
        topic = PrivateTopicFactory(author=self.profile1.user)
        login_check = self.client.login(username=self.profile1.user.username,
                                        password='******')
        self.assertTrue(login_check)
        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        response = self.client.post(reverse('zds.mp.views.index'), {
            'delete': '',
            'items': [topic.pk]
        })

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #23
0
    def test_list_of_private_topics_unread(self):
        """
        Gets list of private topics unread of a member.
        """
        private_topic = PrivateTopicFactory(author=self.another_profile.user)
        private_topic.participants.add(self.profile.user)
        private_topic.save()

        response = self.client.get(reverse('api-mp-list-unread'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get('count'), 1)
        self.assertEqual(len(response.data.get('results')), 1)
        self.assertIsNone(response.data.get('next'))
        self.assertIsNone(response.data.get('previous'))
コード例 #24
0
    def test_list_of_private_posts_with_x_data_format_markdown(self):
        """
        Gets list of private posts with a Markdown value for X-Data-Format header.
        """
        private_topic = PrivateTopicFactory(author=self.profile.user)
        self.create_multiple_private_posts_for_member(self.profile.user,
                                                      private_topic, 1)

        response = self.client.get(
            reverse('api-mp-message-list', args=[private_topic.id]),
            **{'HTTP_X_DATA_FORMAT': 'Markdown'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIsNotNone(response.data.get('results')[0].get('text'))
        self.assertIsNone(response.data.get('results')[0].get('text_html'))
コード例 #25
0
    def test_fail_delete_topic_not_belong_to_user(self):
        topic = PrivateTopicFactory(author=self.profile1.user)

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())

        login_check = self.client.login(username=self.profile2.user.username,
                                        password='******')
        self.assertTrue(login_check)

        self.client.post(reverse('zds.mp.views.index'), {
            'delete': '',
            'items': [topic.pk]
        })

        self.assertEqual(1, PrivateTopic.objects.filter(pk=topic.pk).count())
コード例 #26
0
    def test_list_of_private_posts_with_several_pages(self):
        """
        Gets list of private posts of a member with several pages.
        """
        private_topic = PrivateTopicFactory(author=self.profile.user)
        self.create_multiple_private_posts_for_member(
            self.profile.user, private_topic,
            settings.REST_FRAMEWORK['PAGINATE_BY'] + 1)

        response = self.client.get(
            reverse('api-mp-message-list', args=[private_topic.id]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get('count'),
                         settings.REST_FRAMEWORK['PAGINATE_BY'] + 1)
        self.assertIsNotNone(response.data.get('next'))
        self.assertIsNone(response.data.get('previous'))
コード例 #27
0
    def test_detail_of_private_post_not_in_participants(self):
        """
        Gets an error 403 when the member doesn't have permission to display details about the private post.
        """
        another_profile = ProfileFactory()
        another_private_topic = PrivateTopicFactory(
            author=another_profile.user)
        another_private_post = PrivatePostFactory(
            author=self.profile.user,
            privatetopic=another_private_topic,
            position_in_topic=1)

        response = self.client.get(
            reverse('api-mp-message-detail',
                    args=[another_private_topic.id, another_private_post.id]))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
コード例 #28
0
    def setUp(self):
        self.profile = ProfileFactory()
        self.private_topic = PrivateTopicFactory(author=self.profile.user)
        self.private_post = PrivatePostFactory(author=self.profile.user,
                                               privatetopic=self.private_topic,
                                               position_in_topic=1)
        self.client = APIClient()
        client_oauth2 = create_oauth2_client(self.profile.user)
        authenticate_client(self.client, client_oauth2,
                            self.profile.user.username, 'hostel77')

        self.bot_group = Group()
        self.bot_group.name = ZDS_APP["member"]["bot_group"]
        self.bot_group.save()

        get_cache(extensions_api_settings.DEFAULT_USE_CACHE).clear()
コード例 #29
0
    def test_list_of_private_posts_for_a_page_given(self):
        """
        Gets list of private posts with several pages and gets a page different that the first one.
        """
        private_topic = PrivateTopicFactory(author=self.profile.user)
        self.create_multiple_private_posts_for_member(
            self.profile.user, private_topic,
            settings.REST_FRAMEWORK['PAGINATE_BY'] + 1)

        response = self.client.get(
            reverse('api-mp-message-list', args=[private_topic.id]) +
            '?page=2')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.get('count'), 11)
        self.assertEqual(len(response.data.get('results')), 1)
        self.assertIsNone(response.data.get('next'))
        self.assertIsNotNone(response.data.get('previous'))
コード例 #30
0
    def test_unicode_subtitle_answer(self):
        """To test unicode subtitle."""

        unicodeTopic = PrivateTopicFactory(
            author=self.profile1.user, subtitle=u'Subtitle with accent àéè')
        unicodeTopic.participants.add(self.profile2.user)
        unicodePost = PrivatePostFactory(privatetopic=unicodeTopic,
                                         author=self.profile1.user,
                                         position_in_topic=1)

        response = self.client.post(reverse('zds.mp.views.answer') +
                                    '?sujet=' + str(unicodeTopic.pk), {
                                        'text': 'answer',
                                        'last_post': unicodePost.pk
                                    },
                                    follow=True)
        self.assertEqual(response.status_code, 200)