Exemple #1
0
    def setUp(self):
        super(TestMultipleSites, self).setUp()
        root = Page.objects.get(pk=1)
        root_a = Page(
            title='Home A', slug='home-a')
        root.add_child(instance=root_a)

        root_b = Page(
            title='Home B', slug='home-b')
        root.add_child(instance=root_b)

        self.index_a = NewsIndex(title='News A', slug='news-a')
        root_a.add_child(instance=self.index_a)

        self.index_b = NewsIndex(title='News B', slug='news-b')
        root_b.add_child(instance=self.index_b)

        self.site_a = Site.objects.create(
            hostname='site-a.com',
            root_page=root_a)

        self.site_b = Site.objects.create(
            hostname='site-b.org',
            root_page=root_b)

        self.item_a = NewsItem.objects.create(
            newsindex=self.index_a, title='Post A', date=dt(2015, 8, 1))
        self.item_b = NewsItem.objects.create(
            newsindex=self.index_b, title='Post B', date=dt(2015, 8, 2))
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
    def test_get_newsitems(self):
        news = self.root.add_child(instance=NewsIndex(title='Index 1'))
        other_news = self.root.add_child(instance=NewsIndex(title='Index 2'))

        live = NewsItem.objects.create(newsindex=news, title='First')
        draft = NewsItem.objects.create(newsindex=news, title='Draft', live=False)
        future = NewsItem.objects.create(newsindex=news, title='Future', date=timezone.now() + datetime.timedelta(hours=1))
        other = NewsItem.objects.create(newsindex=other_news, title='Other')

        self.assertEqual(list(news.get_newsitems()),
                         [future, draft, live])
        self.assertEqual(list(news.get_newsitems_for_display()),
                         [live])
        self.assertEqual(list(other_news.get_newsitems()),
                         [other])
Exemple #5
0
 def setUp(self):
     super().setUp()
     self.login()
     root_page = Page.objects.get(pk=2)
     self.index = NewsIndex(
         title='News', slug='news')
     root_page.add_child(instance=self.index)
    def test_chooser_multiple_choices(self):
        """
        Test the chooser when there are multiple valid choices, and some
        missing due to lack of permissions.
        """
        root_page = Page.objects.get(pk=2)
        news1 = root_page.add_child(
            instance=NewsIndex(title='Normal News 1', slug='news-1'))
        news2 = root_page.add_child(
            instance=NewsIndex(title='Normal News 2', slug='news-2'))
        secondary_news = root_page.add_child(instance=SecondaryNewsIndex(
            title='Secondary News', slug='secondary-news'))

        response = self.client.get(reverse('wagtailnews:choose'))
        self.assertContains(response, news1.title)
        self.assertContains(response, news2.title)
        self.assertNotContains(response, secondary_news.title)
Exemple #7
0
 def setUp(self):
     super().setUp()
     self.user = self.login()
     root_page = Page.objects.get(pk=2)
     self.index = root_page.add_child(
         instance=NewsIndex(title='News', slug='news'))
     self.second_index = root_page.add_child(instance=SecondaryNewsIndex(
         title='Secondary news', slug='news-the-second'))
Exemple #8
0
 def setUp(self):
     super().setUp()
     self.login()
     root_page = Page.objects.get(pk=2)
     self.index = NewsIndex(title='News', slug='news')
     root_page.add_child(instance=self.index)
     self.newsitem = NewsItem.objects.create(newsindex=self.index,
                                             title='test title')
Exemple #9
0
    def setUp(self):
        super(TestNewsIndexChooser, self).setUp()
        self.login()
        root_page = Page.objects.get(pk=2)

        self.index1 = root_page.add_child(instance=NewsIndex(
            title='Standard index'))
        self.index2 = root_page.add_child(instance=SecondaryNewsIndex(
            title='Secondary index'))
Exemple #10
0
 def setUp(self):
     super(TestNewsItem, 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)
     self.newsitem = NewsItem.objects.create(
         newsindex=self.index,
         title='A post',
         date=timezone.localtime(timezone.now()).replace(2017, 4, 13))
Exemple #11
0
 def setUp(self):
     super(TestNewsItem, 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)
     ni_date = timezone.make_aware(datetime.datetime(2017, 4, 13, 12, 0, 0))
     self.newsitem = NewsItem.objects.create(newsindex=self.index,
                                             title='A post',
                                             date=ni_date)
    def test_chooser_no_perms(self):
        """
        Test the chooser when there are no valid choices.
        """
        root_page = Page.objects.get(pk=2)
        root_page.add_child(instance=NewsIndex(title='News', slug='news'))
        root_page.add_child(instance=SecondaryNewsIndex(title='Secondary News',
                                                        slug='secondary-news'))

        response = self.client.get(reverse('wagtailnews:choose'))
        self.assertEqual(response.status_code, 403)
    def test_chooser_one_choice(self):
        """
        Test the chooser when there is a single valid choice, and some
        missing due to lack of permissions.
        """
        root_page = Page.objects.get(pk=2)
        news = root_page.add_child(
            instance=NewsIndex(title='News', slug='news'))
        root_page.add_child(instance=SecondaryNewsIndex(title='Secondary News',
                                                        slug='secondary-news'))

        response = self.client.get(reverse('wagtailnews:choose'))
        self.assertRedirects(
            response, reverse('wagtailnews:index', kwargs={'pk': news.pk}))
    def test_multiple_newsindexes(self):
        """
        Check that the news items for the correct news index are used
        """
        second_index = self.root_page.add_child(instance=NewsIndex(
            title='News II', slug='news-2'))
        newsitem = NewsItem.objects.create(
            newsindex=second_index,
            title='Post on the second index',
            date=timezone.now())

        first_response = self.client.get(self.index.url + self.index.reverse_subpage('feed'))
        second_response = self.client.get(second_index.url + second_index.reverse_subpage('feed'))

        self.assertContains(first_response, 'post number 0')
        self.assertNotContains(first_response, newsitem.title)

        self.assertNotContains(second_response, 'post number 0')
        self.assertContains(second_response, newsitem.title)
Exemple #15
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())
Exemple #16
0
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        self.root_page = site.root_page
        self.index = self.root_page.add_child(
            instance=NewsIndex(title='News', slug='news'))

        now = timezone.now()
        for items in range(5):
            NewsItem.objects.create(newsindex=self.index,
                                    title='post number {}'.format(items),
                                    date=now - datetime.timedelta(days=items))
        self.future_newsitem = NewsItem.objects.create(
            newsindex=self.index,
            title='future post',
            date=now + datetime.timedelta(days=1))
        self.unpublished_newsitem = NewsItem.objects.create(
            newsindex=self.index,
            title='unpublished post',
            date=now,
            live=False)
Exemple #17
0
 def test_newsitem_app_model(self):
     NewsIndex.newsitem_model = 'app.SecondaryNewsItem'
     self.assertIs(NewsIndex.get_newsitem_model(), SecondaryNewsItem)
Exemple #18
0
 def test_bad_newsitem_string(self):
     NewsIndex.newsitem_model = 'NoSuchModel'
     with self.assertRaises(LookupError):
         NewsIndex.get_newsitem_model()
Exemple #19
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)
Exemple #20
0
 def setUp(self):
     super(TestNewsItemWithTags, self).setUp()
     root_page = Page.objects.get(pk=2)
     self.index = NewsIndex(title='News', slug='news')
     root_page.add_child(instance=self.index)
Exemple #21
0
 def test_get_template(self):
     index = self.root.add_child(instance=NewsIndex(title='News index'))
     self.assertEqual(
         index.get_template(self.rf.get('/news/'), view='month'),
         ['app/news_index_month.html', 'app/news_index.html'])
Exemple #22
0
 def test_newsitem_just_model(self):
     NewsIndex.newsitem_model = 'NewsItem'
     self.assertIs(NewsIndex.get_newsitem_model(), NewsItem)
Exemple #23
0
 def test_newsitem_model_class(self):
     NewsIndex.newsitem_model = NewsItem
     self.assertIs(NewsIndex.get_newsitem_model(), NewsItem)