예제 #1
0
    def test_mark_as_potential_spam_forum(self):
        author = ProfileFactory()
        staff = StaffProfileFactory()

        _, forum = create_category_and_forum()
        topic = create_topic_in_forum(forum, author)
        PostFactory(topic=topic, author=author.user, position=2)

        comment = topic.last_message

        self.common_test_mark_as_potential_spam(
            url_comments_list=reverse("topic-posts-list",
                                      args=[topic.pk, topic.slug()]),
            url_comment_edit=reverse("post-edit") + f"?message={comment.pk}",
            comment=comment,
            author=author,
            staff=staff,
        )
예제 #2
0
    def test_success_add_participant(self):

        profile3 = ProfileFactory()

        response = self.client.post(
            reverse('mp-edit-participant', args=[self.topic1.pk, self.topic1.slug]),
            {
                'username': profile3.user.username
            },
            follow=True
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.context['messages']))
        self.assertIn(
            profile3.user,
            PrivateTopic.objects.get(pk=self.topic1.pk).participants.all()
        )
예제 #3
0
    def test_success_get_with_multi_username(self):

        profile3 = ProfileFactory()

        response = self.client.get(
            reverse('mp-new') + '?username='******'&username='******'form'].initial['participants'].split(', ')))
        self.assertTrue(self.profile1.user.username not in
                        response.context['form'].initial['participants'])
        self.assertTrue(self.profile2.user.username in
                        response.context['form'].initial['participants'])
        self.assertTrue(profile3.user.username in
                        response.context['form'].initial['participants'])
예제 #4
0
    def test_success_get_with_multi_username(self):

        profile3 = ProfileFactory()

        response = self.client.get(
            reverse("mp-new") + "?username="******"&username="******"form"].initial["participants"].split(", ")))
        self.assertTrue(self.profile1.user.username not in
                        response.context["form"].initial["participants"])
        self.assertTrue(self.profile2.user.username in
                        response.context["form"].initial["participants"])
        self.assertTrue(profile3.user.username in
                        response.context["form"].initial["participants"])
예제 #5
0
    def setUp(self):
        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'
        self.mas = ProfileFactory()
        settings.ZDS_APP['member']['bot_account'] = self.mas.user.username
        self.anonymous = UserFactory(
            username=settings.ZDS_APP["member"]["anonymous_account"],
            password="******")
        self.external = UserFactory(
            username=settings.ZDS_APP["member"]["external_account"],
            password="******")
        self.category1 = CategoryFactory(position=1)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.staff = StaffProfileFactory().user

        self.bot = Group(name=settings.ZDS_APP["member"]["bot_group"])
        self.bot.save()
예제 #6
0
파일: tests.py 프로젝트: maynalysa/zds-site
    def test_alert(self):
        user1 = ProfileFactory().user
        reaction = ReactionFactory(
            article=self.article,
            author=user1,
            position=1)
        login_check = self.client.login(
            username=self.user.username,
            password='******')
        self.assertEqual(login_check, True)
        # signal reaction
        result = self.client.post(
            reverse('zds.article.views.edit_reaction') +
            '?message={0}'.format(
                reaction.pk),
            {
                'signal_text': 'Troll',
                'signal_message': 'Confirmer',
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 1)

        # connect with staff
        login_check = self.client.login(
            username=self.staff.username,
            password='******')
        self.assertEqual(login_check, True)
        # solve alert
        result = self.client.post(
            reverse('zds.article.views.solve_alert'),
            {
                'alert_pk': Alert.objects.first().pk,
                'text': 'Ok',
                'delete_message': 'Resoudre',
            },
            follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 0)
        self.assertEqual(
            PrivateTopic.objects.filter(
                author=self.user).count(),
            1)
        self.assertEquals(len(mail.outbox), 0)
예제 #7
0
파일: tests.py 프로젝트: leroivi/zds-site
    def test_update(self):
        # create topic and content and toggle request
        author = ProfileFactory().user
        category = ForumCategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=author)

        FeaturedRequested.objects.toogle_request(topic, author)

        # ignore
        staff = StaffProfileFactory()
        self.client.force_login(staff.user)

        content_type = ContentType.objects.get_for_model(topic)
        q = FeaturedRequested.objects.get(object_id=topic.pk, content_type__pk=content_type.pk)
        self.assertFalse(q.rejected)

        response = self.client.post(
            reverse("featured-resource-request-update", kwargs={"pk": q.pk}), {"operation": "REJECT"}, follow=False
        )
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertTrue(q.rejected)
        self.assertFalse(q.rejected_for_good)

        response = self.client.post(
            reverse("featured-resource-request-update", kwargs={"pk": q.pk}), {"operation": "CONSIDER"}, follow=False
        )
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertFalse(q.rejected)

        response = self.client.post(
            reverse("featured-resource-request-update", kwargs={"pk": q.pk}),
            {"operation": "REJECT_FOR_GOOD"},
            follow=False,
        )
        self.assertEqual(200, response.status_code)

        q = FeaturedRequested.objects.get(pk=q.pk)
        self.assertTrue(q.rejected)
        self.assertTrue(q.rejected_for_good)
예제 #8
0
    def test_signal_post(self):
        """To test when a member quote anyone post."""
        user1 = ProfileFactory().user
        topic1 = TopicFactory(forum=self.forum11, author=self.user)
        PostFactory(topic=topic1, author=self.user, position=1)
        post2 = PostFactory(topic=topic1, author=user1, position=2)
        PostFactory(topic=topic1, author=user1, position=3)

        result = self.client.post(reverse('zds.forum.views.edit_post') +
                                  '?message={0}'.format(post2.pk), {
                                      'signal_text': u'Troll',
                                      'signal_message': 'confirmer'
                                  },
                                  follow=False)

        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 1)
        self.assertEqual(Alert.objects.filter(author=self.user).count(), 1)
        self.assertEqual(Alert.objects.get(author=self.user).text, u'Troll')
예제 #9
0
    def test_fail_new_topic_user_no_active(self):

        profile_inactive = ProfileFactory()
        profile_inactive.user.is_active = False
        profile_inactive.user.save()

        self.assertEqual(0, PrivateTopic.objects.all().count())
        response = self.client.post(
            reverse("mp-new"),
            {
                "participants": "{}".format(profile_inactive.user.username),
                "title": "title",
                "subtitle": "subtitle",
                "text": "text",
            },
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, PrivateTopic.objects.all().count())
예제 #10
0
    def setUp(self):

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.category2 = CategoryFactory(position=2)
        self.category3 = CategoryFactory(position=3)
        self.forum11 = ForumFactory(category=self.category1,
                                    position_in_category=1)
        self.forum12 = ForumFactory(category=self.category1,
                                    position_in_category=2)
        self.forum13 = ForumFactory(category=self.category1,
                                    position_in_category=3)
        self.forum21 = ForumFactory(category=self.category2,
                                    position_in_category=1)
        self.forum22 = ForumFactory(category=self.category2,
                                    position_in_category=2)
        self.user = ProfileFactory().user
예제 #11
0
    def test_filter_member_ip(self):
        """
        Test filter member by ip.
        """

        # create users (one regular and one staff and superuser)
        tester = ProfileFactory()
        staff = StaffProfileFactory()

        # test login normal user
        result = self.client.post(reverse('member-login'), {
            'username': tester.user.username,
            'password': '******',
            'remember': 'remember'
        },
                                  follow=False)
        # good password then redirection
        self.assertEqual(result.status_code, 302)

        # Check that the filter can't be access from normal user
        result = self.client.post(
            reverse('member-from-ip',
                    kwargs={'ip_address': tester.last_ip_address}), {},
            follow=False)
        self.assertEqual(result.status_code, 403)

        # log the staff user
        result = self.client.post(reverse('member-login'), {
            'username': staff.user.username,
            'password': '******',
            'remember': 'remember'
        },
                                  follow=False)
        # good password then redirection
        self.assertEqual(result.status_code, 302)

        # test that we retrieve correctly the 2 members (staff + user) from this ip
        result = self.client.post(
            reverse('member-from-ip',
                    kwargs={'ip_address': staff.last_ip_address}), {},
            follow=False)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(result.context['members']), 2)
예제 #12
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create a content
        self.content = PublishableContentFactory(
            author_list=[self.author.user])

        # Get information to be reused in tests
        self.form_url = reverse("content:edit-tags",
                                kwargs={"pk": self.content.pk})
        self.error_messages = EditContentTagsForm.declared_fields[
            "tags"].error_messages
        self.success_message = EditContentTags.success_message

        # Log in with an authorized user (e.g the author of the content) to perform the tests
        login_success = self.client.login(username=self.author.user.username,
                                          password="******")
        self.assertTrue(login_success)
예제 #13
0
    def test_last_participation_is_old(self):
        article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")
        newUser = ProfileFactory().user
        reac = ContentReaction(author=self.user_author, position=1, related_content=article)
        reac.update_content("I will find you. And I Will Kill you.")
        reac.save()
        article.last_note = reac
        article.save()

        self.assertFalse(last_participation_is_old(article, newUser))
        ContentRead(user=self.user_author, note=reac, content=article).save()
        reac = ContentReaction(author=newUser, position=2, related_content=article)
        reac.update_content("I will find you. And I Will Kill you.")
        reac.save()
        article.last_note = reac
        article.save()
        ContentRead(user=newUser, note=reac, content=article).save()
        self.assertFalse(last_participation_is_old(article, newUser))
        self.assertTrue(last_participation_is_old(article, self.user_author))
예제 #14
0
파일: tests.py 프로젝트: Vultik/zds-site
 def test_success_initial_content_topic(self):
     author = ProfileFactory().user
     category = ForumCategoryFactory(position=1)
     forum = ForumFactory(category=category, position_in_category=1)
     topic = TopicFactory(forum=forum, author=author)
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password="******")
     self.assertTrue(login_check)
     response = self.client.get(
         "{}?content_type=topic&content_id={}".format(
             reverse("featured-resource-create"), topic.id))
     initial_dict = response.context["form"].initial
     self.assertEqual(initial_dict["title"], topic.title)
     self.assertEqual(initial_dict["authors"], str(author))
     self.assertEqual(initial_dict["type"], _("Un sujet"))
     self.assertEqual(
         initial_dict["url"],
         "http://testserver{}".format(topic.get_absolute_url()))
예제 #15
0
    def setUp(self):
        # prepare a user and 2 Topic (with and without tags)

        settings.EMAIL_BACKEND = \
            'django.core.mail.backends.locmem.EmailBackend'

        self.category1 = CategoryFactory(position=1)
        self.forum = ForumFactory(
            category=self.category1,
            position_in_category=1)
        self.forum2 = ForumFactory(
            category=self.category1,
            position_in_category=2)
        self.forum3 = ForumFactory(
            category=self.category1,
            position_in_category=3)

        self.user = ProfileFactory().user
        log = self.client.login(
            username=self.user.username,
            password='******')
        self.assertEqual(log, True)

        self.tag = TagFactory()
        self.topic1 = TopicFactory(forum=self.forum, author=self.user)
        self.topic2 = TopicFactory(forum=self.forum2, author=self.user)
        self.topic2.tags.add(self.tag)
        self.topic2.save()

        # create 2 posts un each forum
        PostFactory(topic=self.topic1, author=self.user, position=1)
        PostFactory(topic=self.topic1, author=self.user, position=2)
        PostFactory(topic=self.topic2, author=self.user, position=1)
        PostFactory(topic=self.topic2, author=self.user, position=2)

        # and last topic + post alone
        self.tag2 = TagFactory()
        self.topic3 = TopicFactory(forum=self.forum3, author=self.user)
        self.post3 = PostFactory(topic=self.topic3, author=self.user, position=1)
        self.topic3.tags.add(self.tag2)
        self.topic3.save()

        self.postfeed = LastPostsFeedRSS()
예제 #16
0
    def test_top_tags(self):
        """Unit testing top_categories method """

        user = ProfileFactory().user

        # Create some topics
        topic = TopicFactory(forum=self.forum11, author=user)
        topic.add_tags({'C#'})

        topic1 = TopicFactory(forum=self.forum11, author=user)
        topic1.add_tags({'C#'})

        topic2 = TopicFactory(forum=self.forum11, author=user)
        topic2.add_tags({'C#'})

        topic3 = TopicFactory(forum=self.forum11, author=user)
        topic3.add_tags({'PHP'})

        topic4 = TopicFactory(forum=self.forum11, author=user)
        topic4.add_tags({'PHP'})

        topic5 = TopicFactory(forum=self.forum12, author=user)
        topic5.add_tags({'stafftag'})

        # Now call the function, should be "C#", "PHP"
        top_tags = top_categories(user).get('tags')

        # Assert
        self.assertEqual(top_tags[0].title, 'c#')
        self.assertEqual(top_tags[1].title, 'php')
        self.assertEqual(len(top_tags), 2)

        # Admin should see theirs specifics tags
        top_tags_for_staff = top_categories(self.staff1.user).get('tags')
        self.assertEqual(top_tags_for_staff[2].title, 'stafftag')

        # Now we want to exclude a tag
        settings.ZDS_APP['forum']['top_tag_exclu'] = {'php'}
        top_tags = top_categories(user).get('tags')

        # Assert that we should only have one tags
        self.assertEqual(top_tags[0].title, 'c#')
        self.assertEqual(len(top_tags), 1)
예제 #17
0
파일: tests.py 프로젝트: sylafrs/zds-site
 def test_success_initial_content_topic(self):
     author = ProfileFactory().user
     category = CategoryFactory(position=1)
     forum = ForumFactory(category=category, position_in_category=1)
     topic = TopicFactory(forum=forum, author=author)
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password='******')
     self.assertTrue(login_check)
     response = self.client.get(
         '{}?content_type=topic&content_id={}'.format(
             reverse('featured-resource-create'), topic.id))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], topic.title)
     self.assertEqual(initial_dict['authors'], str(author))
     self.assertEqual(initial_dict['type'], _('Un sujet'))
     self.assertEqual(
         initial_dict['url'],
         'http://testserver{}'.format(topic.get_absolute_url()))
예제 #18
0
    def test_success_add_participant(self):

        profile3 = ProfileFactory()

        response = self.client.post(
            reverse('zds.mp.views.add_participant'),
            {
                'topic_pk': self.topic1.pk,
                'user_pk': profile3.user.username
            },
            follow=True
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.context['messages']))
        self.assertIn(
            profile3.user,
            PrivateTopic.objects.get(pk=self.topic1.pk).participants.all()
        )
예제 #19
0
    def test_get_avatar_url(self):
        # if no url was specified -> gravatar !
        self.assertEqual(
            self.user1.get_avatar_url(),
            "https://secure.gravatar.com/avatar/{}?d=identicon".format(
                md5(self.user1.user.email.lower().encode()).hexdigest()),
        )
        # if an url is specified -> take it !
        user2 = ProfileFactory()
        testurl = "http://test.com/avatar.jpg"
        user2.avatar_url = testurl
        self.assertEqual(user2.get_avatar_url(), testurl)

        # if url is relative, send absolute url
        gallerie_avtar = GalleryFactory()
        image_avatar = ImageFactory(gallery=gallerie_avtar)
        user2.avatar_url = image_avatar.physical.url
        self.assertNotEqual(user2.get_avatar_url(), image_avatar.physical.url)
        self.assertIn("http", user2.get_avatar_url())
예제 #20
0
    def test_collaborative_article_edition_and_editor_persistence(self):
        selenium = self.selenium
        find_element = selenium.find_element_by_css_selector

        author = ProfileFactory()

        article = PublishableContentFactory(type='ARTICLE',
                                            author_list=[author.user])

        versioned_article = article.load_version()
        article.sha_draft = versioned_article.repo_update('article',
                                                          '',
                                                          '',
                                                          update_slug=False)
        article.save()

        article_edit_url = reverse('content:edit',
                                   args=[article.pk, article.slug])

        self.login(author)

        selenium.get(self.live_server_url + article_edit_url)

        intro = find_element('.md-editor#id_introduction')
        intro.send_keys('intro')

        selenium.refresh()

        self.assertEqual(
            'intro',
            find_element('.md-editor#id_introduction').get_attribute('value'))

        article.sha_draft = versioned_article.repo_update('article',
                                                          'new intro',
                                                          '',
                                                          update_slug=False)
        article.save()

        selenium.refresh()

        self.assertEqual(
            'new intro',
            find_element('.md-editor#id_introduction').get_attribute('value'))
예제 #21
0
    def test_fail_new_topic_user_no_active(self):

        profile_inactive = ProfileFactory()
        profile_inactive.user.is_active = False
        profile_inactive.user.save()

        self.assertEqual(0, PrivateTopic.objects.all().count())
        response = self.client.post(
            reverse('mp-new'),
            {
                'participants': '{}'.format(profile_inactive.user.username),
                'title': 'title',
                'subtitle': 'subtitle',
                'text': 'text'
            }
        )

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, PrivateTopic.objects.all().count())
예제 #22
0
    def setUp(self):
        self.staff = StaffProfileFactory()
        self.dummy_author = ProfileFactory()

        self.category = ForumCategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category, position_in_category=1)
        self.topic = TopicFactory(forum=self.forum, author=self.dummy_author.user)
        self.post = PostFactory(topic=self.topic, author=self.dummy_author.user, position=1)

        self.alerts = []
        for i in range(20):
            alert = Alert(
                author=self.dummy_author.user,
                comment=self.post,
                scope="FORUM",
                text="pouet-{}".format(i),
                pubdate=(datetime.now() + timedelta(minutes=i)),
            )
            alert.save()
            self.alerts.append(alert)
예제 #23
0
    def test_dislike_post(self):
        """Test when a member dislike any post."""
        user1 = ProfileFactory().user
        topic1 = TopicFactory(forum=self.forum11, author=self.user)
        post1 = PostFactory(topic=topic1, author=self.user, position=1)
        post2 = PostFactory(topic=topic1, author=user1, position=2)
        post3 = PostFactory(topic=topic1, author=self.user, position=3)

        result = self.client.get(reverse('zds.forum.views.dislike_post') +
                                 '?message={0}'.format(post2.pk),
                                 follow=False)

        self.assertEqual(result.status_code, 302)
        self.assertEqual(CommentDislike.objects.all().count(), 0)
        self.assertEqual(Post.objects.get(pk=post1.pk).like, 0)
        self.assertEqual(Post.objects.get(pk=post2.pk).like, 0)
        self.assertEqual(Post.objects.get(pk=post3.pk).like, 0)
        self.assertEqual(Post.objects.get(pk=post1.pk).dislike, 0)
        self.assertEqual(Post.objects.get(pk=post2.pk).dislike, 0)
        self.assertEqual(Post.objects.get(pk=post3.pk).dislike, 0)
예제 #24
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create licenses
        self.license_1 = LicenceFactory()
        self.license_2 = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(
            author_list=[self.author.user], add_license=False)

        # Get information to be reused in tests
        self.form_url = reverse('content:edit-license',
                                kwargs={'pk': self.content.pk})

        # Log in with an authorized user (e.g the author of the content) to perform the tests
        login_success = self.client.login(username=self.author.user.username,
                                          password='******')
        self.assertTrue(login_success)
예제 #25
0
    def test_char_count_after_publication(self):
        """Test the ``get_char_count()`` function.

        Special care should be taken with this function, since:

        - The username of the author is, by default "Firmxxx" where "xxx" depends on the tests before ;
        - The titles (!) also contains a number that also depends on the number of tests before ;
        - The date is ``datetime.now()`` and contains the months, which is never a fixed number of letters.
        """

        author = ProfileFactory().user
        author.username = '******'
        author.save()

        len_date_now = len(date(datetime.now(), 'd F Y'))

        article = PublishedContentFactory(type='ARTICLE',
                                          author_list=[author],
                                          title='Un titre')
        published = PublishedContent.objects.filter(content=article).first()
        self.assertEqual(published.get_char_count(), 160 + len_date_now)

        tuto = PublishableContentFactory(type='TUTORIAL',
                                         author_list=[author],
                                         title='Un titre')

        # add a chapter, so it becomes a middle tutorial
        tuto_draft = tuto.load_version()
        chapter1 = ContainerFactory(parent=tuto_draft,
                                    db_object=tuto,
                                    title='Un chapitre')
        ExtractFactory(container=chapter1, db_object=tuto, title='Un extrait')
        published = publish_content(tuto, tuto_draft, is_major_update=True)

        tuto.sha_public = tuto_draft.current_version
        tuto.sha_draft = tuto_draft.current_version
        tuto.public_version = published
        tuto.save()

        published = PublishedContent.objects.filter(content=tuto).first()
        self.assertEqual(published.get_char_count(), 335 + len_date_now)
예제 #26
0
    def test_signal_post(self):
        """To test when a member signal a post."""
        user1 = ProfileFactory().user
        topic1 = TopicFactory(forum=self.forum11, author=self.user)
        PostFactory(topic=topic1, author=self.user, position=1)
        post2 = PostFactory(topic=topic1, author=user1, position=2)
        PostFactory(topic=topic1, author=user1, position=3)

        result = self.client.post(reverse('zds.forum.views.edit_post') +
                                  '?message={0}'.format(post2.pk), {
                                      'signal_text': u'Troll',
                                      'signal_message': 'confirmer'
                                  },
                                  follow=False)

        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 1)
        self.assertEqual(Alert.objects.filter(author=self.user).count(), 1)
        self.assertEqual(Alert.objects.get(author=self.user).text, u'Troll')

        # and test that staff can solve but not user
        alert = Alert.objects.get(comment=post2.pk)
        # try as a normal user
        result = self.client.post(reverse('zds.forum.views.solve_alert'), {
            'alert_pk': alert.pk,
        },
                                  follow=False)
        self.assertEqual(result.status_code, 403)
        # login as staff
        staff1 = StaffProfileFactory().user
        self.assertEqual(
            self.client.login(username=staff1.username, password='******'),
            True)
        # try again as staff
        result = self.client.post(reverse('zds.forum.views.solve_alert'), {
            'alert_pk': alert.pk,
            'text': u'Everything is Ok kid'
        },
                                  follow=False)
        self.assertEqual(result.status_code, 302)
        self.assertEqual(Alert.objects.all().count(), 0)
예제 #27
0
    def setUp(self):
        # prepare a user and 2 Topic (with and without tags)

        settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"

        self.category1 = ForumCategoryFactory(position=1)
        self.forum = ForumFactory(category=self.category1,
                                  position_in_category=1)
        self.forum2 = ForumFactory(category=self.category1,
                                   position_in_category=2)

        self.user = ProfileFactory().user
        self.client.force_login(self.user)

        self.tag = TagFactory()
        self.topic1 = TopicFactory(forum=self.forum, author=self.user)
        self.topic2 = TopicFactory(forum=self.forum2, author=self.user)
        self.topic2.tags.add(self.tag)
        self.topic2.save()

        self.topicfeed = LastTopicsFeedRSS()
예제 #28
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create a license
        self.license = LicenceFactory()

        # Create a content
        self.content = PublishableContentFactory(
            author_list=[self.author.user], add_license=False)

        # Get information to be reused in tests
        self.form_url = reverse("content:edit-license",
                                kwargs={"pk": self.content.pk})
        self.error_messages = EditContentLicenseForm.declared_fields[
            "license"].error_messages
        self.success_message_license = EditContentLicense.success_message_license
        self.success_message_profile_update = EditContentLicense.success_message_profile_update

        # Log in with an authorized user (e.g the author of the content) to perform the tests
        self.client.force_login(self.author.user)
예제 #29
0
    def test_login(self):
        """To test user login."""
        user = ProfileFactory()

        result = self.client.post(reverse('zds.member.views.login_view'), {
            'username': user.user.username,
            'password': '******',
            'remember': 'remember'
        },
                                  follow=False)
        # bad password then no redirection
        self.assertEqual(result.status_code, 200)

        result = self.client.post(reverse('zds.member.views.login_view'), {
            'username': user.user.username,
            'password': '******',
            'remember': 'remember'
        },
                                  follow=False)
        # good password then redirection
        self.assertEqual(result.status_code, 302)
예제 #30
0
    def setUp(self):
        # Create a user
        self.author = ProfileFactory()

        # Create tags
        self.tag_0 = TagFactory()
        self.tag_1 = TagFactory()
        self.tag_from_other_content = TagFactory()
        self.tags_name = [self.tag_0.title, self.tag_1.title, self.tag_from_other_content.title]

        # Create contents
        self.content = PublishableContentFactory(author_list=[self.author.user])
        self.other_content = PublishableContentFactory(author_list=[self.author.user])
        self.other_content.tags.add(self.tag_from_other_content)
        self.other_content.save()

        # Get information to be reused in tests
        self.form_url = reverse("content:edit-tags", kwargs={"pk": self.content.pk})

        # Log in with an authorized user (e.g the author of the content) to perform the tests
        self.client.force_login(self.author.user)