Esempio n. 1
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password='******')
     self.assertTrue(login_check)
     response = self.client.get('{}{}'.format(
         reverse('featured-resource-create'),
         '?content_type=published_content&content_id={}'.format(
             tutorial.pk)))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], tutorial.title)
     self.assertEqual(initial_dict['authors'],
                      '{}, {}'.format(author, author2))
     self.assertEqual(initial_dict['type'], _('Un tutoriel'))
     self.assertEqual(
         initial_dict['url'],
         'http://testserver{}'.format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict['image_url'],
         'http://testserver{}'.format(image.physical['featured'].url))
Esempio n. 2
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(username=staff.user.username,
                                     password="******")
     self.assertTrue(login_check)
     response = self.client.get("{}{}".format(
         reverse("featured-resource-create"),
         "?content_type=published_content&content_id={}".format(
             tutorial.pk)))
     initial_dict = response.context["form"].initial
     self.assertEqual(initial_dict["title"], tutorial.title)
     self.assertEqual(initial_dict["authors"],
                      "{}, {}".format(author, author2))
     self.assertEqual(initial_dict["type"], _("Un tutoriel"))
     self.assertEqual(
         initial_dict["url"],
         "http://testserver{}".format(tutorial.get_absolute_url_online()))
     self.assertEqual(
         initial_dict["image_url"],
         "http://testserver{}".format(image.physical["featured"].url))
Esempio n. 3
0
 def test_success_initial_content(self):
     author = ProfileFactory().user
     author2 = ProfileFactory().user
     tutorial = PublishedContentFactory(author_list=[author, author2])
     gallery = GalleryFactory()
     image = ImageFactory(gallery=gallery)
     tutorial.image = image
     tutorial.save()
     staff = StaffProfileFactory()
     login_check = self.client.login(
         username=staff.user.username,
         password='******'
     )
     self.assertTrue(login_check)
     response = self.client.get('{}{}'.format(reverse('featured-resource-create'),
                                              '?content_type=published_content&content_id={}'.format(tutorial.pk)))
     initial_dict = response.context['form'].initial
     self.assertEqual(initial_dict['title'], tutorial.title)
     self.assertEqual(initial_dict['authors'], '{}, {}'.format(author, author2))
     self.assertEqual(initial_dict['type'], _('Un tutoriel'))
     self.assertEqual(initial_dict['url'], 'http://testserver{}'.format(tutorial.get_absolute_url_online()))
     self.assertEqual(initial_dict['image_url'], image.physical.url)
Esempio n. 4
0
    def test_toggle(self):
        author = ProfileFactory()
        login_check = self.client.login(username=author.user.username,
                                        password='******')
        self.assertTrue(login_check)

        # create topic and toggle request
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=author.user)

        response = self.client.post(reverse('topic-edit') +
                                    '?topic={}'.format(topic.pk),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(200, response.status_code)

        self.assertEqual(FeaturedRequested.objects.count(), 1)
        r = FeaturedRequested.objects.last()
        self.assertEqual(r.content_object, topic)
        self.assertIn(author.user, r.users_voted.all())

        # lock topic: cannot vote anymore
        topic.is_locked = True
        topic.save()

        response = self.client.post(reverse('topic-edit') +
                                    '?topic={}'.format(topic.pk),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(403, response.status_code)
        self.assertEqual(FeaturedRequested.objects.count(), 1)

        # create tutorial and toggle request
        tutorial = PublishedContentFactory(author_list=[author.user])
        gallery = GalleryFactory()
        image = ImageFactory(gallery=gallery)
        tutorial.image = image
        tutorial.save()

        response = self.client.post(reverse('content:request-featured',
                                            kwargs={'pk': tutorial.pk}),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(200, response.status_code)

        self.assertEqual(FeaturedRequested.objects.count(), 2)
        r = FeaturedRequested.objects.last()
        self.assertEqual(r.content_object, tutorial)
        self.assertIn(author.user, r.users_voted.all())

        # create opinion: cannot toggle request!
        opinion = PublishedContentFactory(type='OPINION',
                                          author_list=[author.user])
        gallery = GalleryFactory()
        image = ImageFactory(gallery=gallery)
        opinion.image = image
        opinion.save()

        response = self.client.post(reverse('content:request-featured',
                                            kwargs={'pk': opinion.pk}),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(403, response.status_code)
        self.assertEqual(FeaturedRequested.objects.count(), 2)

        # set tutorial as obsolete: cannot toggle
        tutorial.is_obsolete = True
        tutorial.save()

        response = self.client.post(reverse('content:request-featured',
                                            kwargs={'pk': tutorial.pk}),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(403, response.status_code)

        r = FeaturedRequested.objects.get(pk=r.pk)
        self.assertEqual(r.content_object, tutorial)
        self.assertIn(author.user, r.users_voted.all())

        # reject tutorial proposition
        tutorial.is_obsolete = False  # can vote again
        tutorial.save()

        r = FeaturedRequested.objects.get(pk=r.pk)
        r.rejected = True
        r.save()

        # upvote with other user
        other = ProfileFactory()
        login_check = self.client.login(username=other.user.username,
                                        password='******')
        self.assertTrue(login_check)

        response = self.client.post(reverse('content:request-featured',
                                            kwargs={'pk': tutorial.pk}),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(200, response.status_code)

        r = FeaturedRequested.objects.get(pk=r.pk)
        self.assertIn(other.user, r.users_voted.all())
        self.assertFalse(r.rejected)  # not rejected anymore

        # reject for good, cannot vote anymore!
        r.rejected_for_good = True
        r.save()

        response = self.client.post(reverse('content:request-featured',
                                            kwargs={'pk': tutorial.pk}),
                                    {'request_featured': 1},
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(403, response.status_code)

        r = FeaturedRequested.objects.get(pk=r.pk)
        self.assertIn(other.user, r.users_voted.all())
Esempio n. 5
0
    def test_filters(self):
        # create topic and content and toggle request
        author = ProfileFactory().user
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=author)

        FeaturedRequested.objects.toogle_request(topic, author)

        tutorial = PublishedContentFactory(author_list=[author])
        gallery = GalleryFactory()
        image = ImageFactory(gallery=gallery)
        tutorial.image = image
        tutorial.save()

        FeaturedRequested.objects.toogle_request(tutorial, author)

        # without filter
        staff = StaffProfileFactory()
        login_check = self.client.login(username=staff.user.username,
                                        password='******')
        self.assertTrue(login_check)

        response = self.client.get(reverse('featured-resource-requests'))
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']), 2)
        self.assertTrue(
            any(r.content_object == topic
                for r in response.context['featured_request_list']))
        self.assertTrue(
            any(r.content_object == tutorial
                for r in response.context['featured_request_list']))

        # filter topic
        response = self.client.get(
            reverse('featured-resource-requests') + '?type=topic')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']), 1)
        self.assertTrue(
            any(r.content_object == topic
                for r in response.context['featured_request_list']))
        self.assertFalse(
            any(r.content_object == tutorial
                for r in response.context['featured_request_list']))

        # filter tuto
        response = self.client.get(
            reverse('featured-resource-requests') + '?type=content')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']), 1)
        self.assertFalse(
            any(r.content_object == topic
                for r in response.context['featured_request_list']))
        self.assertTrue(
            any(r.content_object == tutorial
                for r in response.context['featured_request_list']))

        # reject topic
        content_type = ContentType.objects.get_for_model(topic)
        q = FeaturedRequested.objects.get(object_id=topic.pk,
                                          content_type__pk=content_type.pk)
        q.rejected = True
        q.save()

        response = self.client.get(
            reverse('featured-resource-requests') + '?type=topic')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']), 0)

        # filter ignored
        response = self.client.get(
            reverse('featured-resource-requests') + '?type=ignored')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']), 1)
        self.assertTrue(
            any(r.content_object == topic
                for r in response.context['featured_request_list']))

        # put back vote count to 0 for tutorial
        FeaturedRequested.objects.toogle_request(tutorial, author)
        response = self.client.get(
            reverse('featured-resource-requests') + '?type=content')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']),
                         0)  # does not appear with no votes

        # upvote topic
        other = ProfileFactory().user
        FeaturedRequested.objects.toogle_request(topic, other)

        response = self.client.get(
            reverse('featured-resource-requests') + '?type=topic')
        self.assertEqual(200, response.status_code)

        self.assertEqual(len(response.context['featured_request_list']),
                         1)  # it is back!