Esempio n. 1
0
class TestCustomFeed(TestCase, WagtailTestUtils):
    """
    Test custom Feed classes on the NewsIndex are used
    """
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        root_page = site.root_page
        self.index = NewsIndex(title='News', slug='news')
        root_page.add_child(instance=self.index)
        now = timezone.now()
        self.newsitem = NewsItem.objects.create(newsindex=self.index,
                                                title='custompost 1',
                                                date=now)

    def test_custom_view(self):
        response = self.client.get(self.index.url +
                                   self.index.reverse_subpage('feed'))

        # check descriptions
        self.assertContains(response, self.newsitem.get_description())
Esempio n. 2
0
class TestNewsList(TestCase, WagtailTestUtils):

    def setUp(self):
        super(TestNewsList, self).setUp()
        site = Site.objects.get(is_default_site=True)
        root_page = site.root_page
        self.index = NewsIndex(
            title='News', slug='news')
        root_page.add_child(instance=self.index)

    def test_index(self):
        item1 = NewsItem.objects.create(
            newsindex=self.index,
            title='One post',
            date=dt(2015, 8, 24, 0, 0, 0))
        item2 = NewsItem.objects.create(
            newsindex=self.index,
            title='Two post',
            date=dt(2015, 8, 24, 0, 0, 0))

        response = self.client.get(self.index.url)
        self.assertIn('newsitem_list', response.context)
        self.assertQuerysetEqual(
            response.context['newsitem_list'],
            [item1, item2], transform=noop)

    def test_archive_year(self):
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015',
            date=dt(2015, 8, 24, 0, 0, 0))
        item2014 = NewsItem.objects.create(
            newsindex=self.index,
            title='2014',
            date=dt(2014, 8, 24, 0, 0, 0))
        NewsItem.objects.create(
            newsindex=self.index,
            title='2013',
            date=dt(2013, 8, 24, 0, 0, 0))

        response = self.client.get(self.index.url + self.index.reverse_subpage(
            'year', kwargs={'year': '2014'}))

        self.assertIn('newsitem_list', response.context)
        self.assertQuerysetEqual(
            response.context['newsitem_list'],
            [item2014], transform=noop)

    def test_archive_month(self):
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015-08-24',
            date=dt(2015, 8, 24, 0, 0, 0))
        item = NewsItem.objects.create(
            newsindex=self.index,
            title='2015-07-24',
            date=dt(2015, 7, 24, 0, 0, 0))
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015-06-24',
            date=dt(2015, 6, 24, 0, 0, 0))
        NewsItem.objects.create(
            newsindex=self.index,
            title='2014-07-24',
            date=dt(2014, 7, 24, 0, 0, 0))

        response = self.client.get(self.index.url + self.index.reverse_subpage(
            'month', kwargs={'year': '2015', 'month': '7'}))

        self.assertIn('newsitem_list', response.context)
        self.assertQuerysetEqual(
            response.context['newsitem_list'],
            [item], transform=noop)

    def test_archive_day(self):
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015-08-24',
            date=dt(2015, 8, 24, 12, 0, 0))
        item = NewsItem.objects.create(
            newsindex=self.index,
            title='2015-08-23',
            date=dt(2015, 8, 23, 12, 0, 0))
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015-08-22',
            date=dt(2015, 8, 22, 12, 0, 0))
        NewsItem.objects.create(
            newsindex=self.index,
            title='2015-07-23',
            date=dt(2015, 7, 23, 12, 0, 0))

        response = self.client.get(self.index.url + self.index.reverse_subpage(
            'day', kwargs={'year': '2015', 'month': '8', 'day': '23'}))

        self.assertIn('newsitem_list', response.context)
        self.assertQuerysetEqual(
            response.context['newsitem_list'],
            [item], transform=noop)