Exemplo n.º 1
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.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()

        self.topicfeed = LastTopicsFeedRSS()
Exemplo n.º 2
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.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()

        self.topicfeed = LastTopicsFeedRSS()
Exemplo n.º 3
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()
Exemplo n.º 4
0
class LastTopicsFeedRSSTest(TestCase):
    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
        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()

        self.topicfeed = LastTopicsFeedRSS()

    def test_is_well_setup(self):
        """ Test that base parameters are Ok """

        self.assertEqual(self.topicfeed.link, '/forums/')
        reftitle = 'Derniers sujets sur {}'.format(
            settings.ZDS_APP['site']['literal_name'])
        self.assertEqual(self.topicfeed.title, reftitle)
        refdescription = ('Les derniers sujets créés '
                          'sur le forum de {}.'.format(
                              settings.ZDS_APP['site']['literal_name']))
        self.assertEqual(self.topicfeed.description, refdescription)

        atom = LastTopicsFeedATOM()
        self.assertEqual(atom.subtitle, refdescription)

    def test_getobjects(self):
        """ Get object should return the given parameteres in an object """

        factory = RequestFactory()
        request = factory.get(
            reverse('topic-feed-rss') + '?forum=fofo&tag=tatag')
        obj = self.topicfeed.get_object(request=request)
        self.assertEqual(obj['forum'], 'fofo')
        self.assertEqual(obj['tag'], 'tatag')

    def test_items_success(self):
        """ test that right items are sent back according to obj """

        # test empty obj
        obj = {}
        # should return all topics
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 2)
        # test with a tag
        obj = {'tag': self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum
        obj = {'forum': self.topic1.forum.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum and a tag
        obj = {'forum': self.topic1.forum.pk, 'tag': self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_items_bad_cases(self):
        """ test that right items are sent back according to obj """

        # test empty values, return value shoulb be empty
        obj = {'forum': -1, 'tag': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {'forum': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {'tag': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        # with a weird object
        obj = {'forum': 'lol'}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_get_pubdate(self):
        """ test the return value of pubdate """

        ref = self.topic2.pubdate
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_pubdate(item=topics[0])
        self.assertEqual(ret.date(), ref.date())

    def test_get_title(self):
        """ test the return value of title """

        ref = '{} dans {}'.format(self.topic2.title, self.topic2.forum.title)
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_title(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_description(self):
        """ test the return value of description """

        ref = self.topic2.subtitle
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_description(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_name(self):
        """ test the return value of author name """

        ref = self.topic2.author.username
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_author_name(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_link(self):
        """ test the return value of author link """

        ref = self.topic2.author.get_absolute_url()
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_author_link(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_item_link(self):
        """ test the return value of item link """

        ref = self.topic2.get_absolute_url()
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_link(item=topics[0])
        self.assertEqual(ret, ref)
Exemplo n.º 5
0
class LastTopicsFeedRSSTest(TestCase):
    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()

    def test_is_well_setup(self):
        """Test that base parameters are Ok"""

        self.assertEqual(self.topicfeed.link, "/forums/")
        reftitle = "Derniers sujets sur {}".format(
            settings.ZDS_APP["site"]["literal_name"])
        self.assertEqual(self.topicfeed.title, reftitle)
        refdescription = "Les derniers sujets créés " "sur le forum de {}.".format(
            settings.ZDS_APP["site"]["literal_name"])
        self.assertEqual(self.topicfeed.description, refdescription)

        atom = LastTopicsFeedATOM()
        self.assertEqual(atom.subtitle, refdescription)

    def test_getobjects(self):
        """Get object should return the given parameteres in an object"""

        factory = RequestFactory()
        request = factory.get(
            reverse("topic-feed-rss") + "?forum=fofo&tag=tatag")
        obj = self.topicfeed.get_object(request=request)
        self.assertEqual(obj["forum"], "fofo")
        self.assertEqual(obj["tag"], "tatag")

    def test_items_success(self):
        """test that right items are sent back according to obj"""

        # test empty obj
        obj = {}
        # should return all topics
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 2)
        # test with a tag
        obj = {"tag": self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum
        obj = {"forum": self.topic1.forum.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum and a tag
        obj = {"forum": self.topic1.forum.pk, "tag": self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_items_bad_cases(self):
        """test that right items are sent back according to obj"""

        # test empty values, return value shoulb be empty
        obj = {"forum": -1, "tag": -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {"forum": -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {"tag": -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        # with a weird object
        obj = {"forum": "lol"}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_get_pubdate(self):
        """test the return value of pubdate"""

        ref = self.topic2.pubdate
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_pubdate(item=topics[0])
        self.assertEqual(ret.date(), ref.date())

    def test_get_title(self):
        """test the return value of title"""

        ref = f"{self.topic2.title} dans {self.topic2.forum.title}"
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_title(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_description(self):
        """test the return value of description"""

        ref = self.topic2.subtitle
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_description(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_name(self):
        """test the return value of author name"""

        ref = self.topic2.author.username
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_author_name(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_link(self):
        """test the return value of author link"""

        ref = self.topic2.author.get_absolute_url()
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_author_link(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_item_link(self):
        """test the return value of item link"""

        ref = self.topic2.get_absolute_url()
        topics = self.topicfeed.items(obj={"tag": self.tag.pk})
        ret = self.topicfeed.item_link(item=topics[0])
        self.assertEqual(ret, ref)
Exemplo n.º 6
0
class LastTopicsFeedRSSTest(TestCase):

    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.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()

        self.topicfeed = LastTopicsFeedRSS()

    def test_is_well_setup(self):
        """ Test that base parameters are Ok """

        self.assertEqual(self.topicfeed.link, '/forums/')
        reftitle = 'Derniers sujets sur {}'.format(settings.ZDS_APP['site']['literal_name'])
        self.assertEqual(self.topicfeed.title, reftitle)
        refdescription = ('Les derniers sujets créés '
                          'sur le forum de {}.'.format(settings.ZDS_APP['site']['literal_name']))
        self.assertEqual(self.topicfeed.description, refdescription)

        atom = LastTopicsFeedATOM()
        self.assertEqual(atom.subtitle, refdescription)

    def test_getobjects(self):
        """ Get object should return the given parameteres in an object """

        factory = RequestFactory()
        request = factory.get(reverse('topic-feed-rss') + '?forum=fofo&tag=tatag')
        obj = self.topicfeed.get_object(request=request)
        self.assertEqual(obj['forum'], 'fofo')
        self.assertEqual(obj['tag'], 'tatag')

    def test_items_success(self):
        """ test that right items are sent back according to obj """

        # test empty obj
        obj = {}
        # should return all topics
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 2)
        # test with a tag
        obj = {'tag': self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum
        obj = {'forum': self.topic1.forum.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 1)
        # test with a forum and a tag
        obj = {'forum': self.topic1.forum.pk, 'tag': self.tag.pk}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_items_bad_cases(self):
        """ test that right items are sent back according to obj """

        # test empty values, return value shoulb be empty
        obj = {'forum': -1, 'tag': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {'forum': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        obj = {'tag': -1}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)
        # with a weird object
        obj = {'forum': 'lol'}
        topics = self.topicfeed.items(obj=obj)
        self.assertEqual(len(topics), 0)

    def test_get_pubdate(self):
        """ test the return value of pubdate """

        ref = self.topic2.pubdate
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_pubdate(item=topics[0])
        self.assertEqual(ret.date(), ref.date())

    def test_get_title(self):
        """ test the return value of title """

        ref = '{} dans {}'.format(self.topic2.title, self.topic2.forum.title)
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_title(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_description(self):
        """ test the return value of description """

        ref = self.topic2.subtitle
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_description(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_name(self):
        """ test the return value of author name """

        ref = self.topic2.author.username
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_author_name(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_author_link(self):
        """ test the return value of author link """

        ref = self.topic2.author.get_absolute_url()
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_author_link(item=topics[0])
        self.assertEqual(ret, ref)

    def test_get_item_link(self):
        """ test the return value of item link """

        ref = self.topic2.get_absolute_url()
        topics = self.topicfeed.items(obj={'tag': self.tag.pk})
        ret = self.topicfeed.item_link(item=topics[0])
        self.assertEqual(ret, ref)