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))
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 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_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])
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)
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().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')
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 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))
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)
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())
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)
def test_newsitem_app_model(self): NewsIndex.newsitem_model = 'app.SecondaryNewsItem' self.assertIs(NewsIndex.get_newsitem_model(), SecondaryNewsItem)
def test_bad_newsitem_string(self): NewsIndex.newsitem_model = 'NoSuchModel' with self.assertRaises(LookupError): NewsIndex.get_newsitem_model()
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)
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)
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'])
def test_newsitem_just_model(self): NewsIndex.newsitem_model = 'NewsItem' self.assertIs(NewsIndex.get_newsitem_model(), NewsItem)
def test_newsitem_model_class(self): NewsIndex.newsitem_model = NewsItem self.assertIs(NewsIndex.get_newsitem_model(), NewsItem)