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'))
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'))
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_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)
def test_get_template_custom(self): index = self.root.add_child(instance=SecondaryNewsIndex( title='News index')) self.assertEqual( index.get_template(self.rf.get('/news/'), view='all'), ['app/secondaryindex_all.jade', 'app/secondaryindex.jade'])