def test_future_hero_article_not_in_latest(self): promote_date = timezone.now() + timezone.timedelta(days=2) demote_date = timezone.now() + timezone.timedelta(days=4) future_article = ArticlePage(title="Future article", promote_date=promote_date, demote_date=demote_date, depth="1", path="0003", featured_in_latest=True, feature_as_hero_article=True) self.yourmind.add_child(instance=future_article) future_article.save() main = Main.objects.all().first() self.assertQuerysetEqual(main.latest_articles(), []) promote_date = timezone.now() + timezone.timedelta(days=-2) demote_date = timezone.now() + timezone.timedelta(days=-1) present_article = ArticlePage( title="Present article", promote_date=promote_date, demote_date=demote_date, depth="1", path="0004", featured_in_latest_start_date=promote_date, feature_as_hero_article=True) self.yourmind.add_child(instance=present_article) present_article.save() promote_articles() self.assertQuerysetEqual(main.latest_articles(), [ repr(present_article), ])
def test_article_only_site_specific_artcles_show_under_tag(self): tag = self.mk_tag(parent=self.tag_index) tag.feature_in_homepage = True tag.save_revision().publish() articles = self.mk_articles( parent=self.yourmind, featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now(), count=5) for article in articles: ArticlePageTags.objects.create(page=article, tag=tag) promote_articles() self.user = self.login() response = self.client.post(reverse( 'wagtailadmin_pages:copy', args=(self.main.id,)), data={ 'new_title': 'blank', 'new_slug': 'blank', 'new_parent_page': self.root.id, 'copy_subpages': 'true', 'publish_copies': 'true'}) self.assertEqual(response.status_code, 302) response = self.client.get('/tags/' + tag.slug + '/') self.assertEqual(len(response.context['object_list']), 5) for article in response.context['object_list']: self.assertEqual(article.get_site().pk, self.main.get_site().pk) response = self.client.get('/tags/bogus/') self.assertEqual(response.status_code, 404)
def test_future_hero_article_not_in_latest(self): promote_date = timezone.now() + timezone.timedelta(days=2) demote_date = timezone.now() + timezone.timedelta(days=4) future_article = ArticlePage( title="Future article", promote_date=promote_date, demote_date=demote_date, depth="1", path="0003", featured_in_latest=True, feature_as_hero_article=True ) self.yourmind.add_child(instance=future_article) future_article.save() main = Main.objects.all().first() self.assertQuerysetEqual(main.latest_articles(), []) promote_date = timezone.now() + timezone.timedelta(days=-2) demote_date = timezone.now() + timezone.timedelta(days=-1) present_article = ArticlePage( title="Present article", promote_date=promote_date, demote_date=demote_date, depth="1", path="0004", featured_in_latest_start_date=promote_date, feature_as_hero_article=True ) self.yourmind.add_child(instance=present_article) present_article.save() promote_articles() self.assertQuerysetEqual( main.latest_articles(), [repr(present_article), ])
def test_that_only_translated_sections_show_with_tag_navigation(self): site_settings = SiteSettings.for_site(self.main.get_site()) site_settings.enable_tag_navigation = True site_settings.show_only_translated_pages = True site_settings.save() self.mk_section_translation(self.english_section, self.french, title=self.english_section.title + ' in french') article1 = self.mk_article( self.english_section, title='English article1 in English Section', featured_in_homepage_start_date=timezone.now(), featured_in_homepage=True) self.mk_article_translation( article1, self.french, title=article1.title + ' in french', ) promote_articles() response = self.client.get('/') self.assertContains(response, 'English section') response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section-in-french/"' ' class="section-listing__theme-bg-link">' 'English section in french</a>')
def test_latest_rotation_no_start_or_end_date(self): """This test that if the weekdays and times are set for content rotation, that the content doesn't rotates with no dates set""" site = Site.objects.get(is_default_site=True) settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.monday_rotation = True site_settings.tuesday_rotation = True site_settings.wednesday_rotation = True site_settings.thursday_rotation = True site_settings.friday_rotation = True site_settings.saturday_rotation = True site_settings.sunday_rotation = True site_settings.save() for i in range(5): self.footer = FooterPage(title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles(self.yourmind_sub, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False) self.assertEqual(self.main.latest_articles().count(), 10) first_article_old = self.main.latest_articles()[0].pk last_article_old = self.main.latest_articles()[9].pk rotate_content() self.assertEqual(first_article_old, self.main.latest_articles()[0].pk) self.assertEqual(last_article_old, self.main.latest_articles()[9].pk)
def test_latest_articles_translated_when_tag_navigation_enabled(self): article_1 = self.mk_article( self.yourmind, title='article-1', featured_in_latest_start_date=( timezone.now() - timedelta(days=1)), featured_in_latest=True, featured_in_homepage_start_date=timezone.now()) article_2 = self.mk_article( self.yourmind, title='article-2', featured_in_latest_start_date=( timezone.now() - timedelta(days=1)), featured_in_latest=True, featured_in_homepage_start_date=timezone.now()) tag = self.mk_tag(parent=self.tag_index) ArticlePageTags.objects.create(page=article_1, tag=tag) ArticlePageTags.objects.create(page=article_2, tag=tag) # make the translation for the article and the tag fr_article_1 = self.mk_article_translation( article_1, self.french, title=article_1.title + ' in french',) self.mk_tag_translation( tag, self.french, title=tag.title + ' in french',) tag.feature_in_homepage = True tag.save_revision().publish() promote_articles() self.client.get('/locale/fr/') response = self.client.get('/') latest_articles = response.context['tag_nav_data']['latest_articles'] self.assertTrue(fr_article_1 in latest_articles) self.assertTrue(article_2 in latest_articles) self.assertFalse(article_1 in latest_articles)
def test_latest_rotation_no_start_or_end_date(self): """This test that if the weekdays and times are set for content rotation, that the content doesn't rotates with no dates set""" site = Site.objects.get(is_default_site=True) settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.monday_rotation = True site_settings.tuesday_rotation = True site_settings.wednesday_rotation = True site_settings.thursday_rotation = True site_settings.friday_rotation = True site_settings.saturday_rotation = True site_settings.sunday_rotation = True site_settings.save() for i in range(5): self.footer = FooterPage( title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles( self.yourmind_sub, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False) self.assertEqual(self.main.latest_articles().count(), 10) first_article_old = self.main.latest_articles()[0].pk last_article_old = self.main.latest_articles()[9].pk rotate_content() self.assertEqual(first_article_old, self.main.latest_articles()[0].pk) self.assertEqual(last_article_old, self.main.latest_articles()[9].pk)
def test_new_tag_article_relations_made_when_copying_site(self): tag = self.mk_tag(parent=self.tag_index) tag.feature_in_homepage = True tag.save_revision().publish() articles = self.mk_articles( parent=self.yourmind, featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now(), count=30) for article in articles: ArticlePageTags.objects.create(page=article, tag=tag) promote_articles() self.user = self.login() response = self.client.post(reverse( 'wagtailadmin_pages:copy', args=(self.main.id,)), data={ 'new_title': 'blank', 'new_slug': 'blank', 'new_parent_page': self.root.id, 'copy_subpages': 'true', 'publish_copies': 'true'}) self.assertEqual(response.status_code, 302) main3 = Main.objects.get(slug='blank') new_articles = ArticlePage.objects.descendant_of(main3) new_article_tags = ArticlePageTags.objects.filter( page__in=new_articles) for article_tag_relation in new_article_tags: self.assertEqual( article_tag_relation.tag.get_site().pk, main3.get_site().pk)
def test_that_only_translated_sections_show_with_tag_navigation(self): site_settings = SiteSettings.for_site(self.main.get_site()) site_settings.enable_tag_navigation = True site_settings.show_only_translated_pages = True site_settings.save() self.mk_section_translation( self.english_section, self.french, title=self.english_section.title + ' in french') article1 = self.mk_article( self.english_section, title='English article1 in English Section', featured_in_homepage_start_date=timezone.now(), featured_in_homepage=True) self.mk_article_translation( article1, self.french, title=article1.title + ' in french',) promote_articles() response = self.client.get('/') self.assertContains(response, 'English section') response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section-in-french/"' ' class="section-listing__theme-bg-link">' 'English section in french</a>')
def test_order_by_promote_date_latest(self): article = self.mk_article(self.yourmind, title='article', slug='article') article.featured_in_latest_start_date = timezone.now() article.save() article2 = self.mk_article(self.yourmind, title='article2', slug='article2') article2.featured_in_latest_start_date = timezone.now() article2.save() article3 = self.mk_article(self.yourmind, title='article3', slug='article3') article3.featured_in_latest_start_date = timezone.now() article3.save() demote_articles() promote_articles() latest_articles = Main.objects.all().first().latest_articles() self.assertEqual(latest_articles[0].title, 'article3') article2.featured_in_latest_start_date = timezone.now() article2.save() demote_articles() promote_articles() latest_articles = Main.objects.all().first().latest_articles() self.assertEqual(latest_articles[0].title, 'article2')
def test_order_by_promote_date_homepage(self): article = self.mk_article(self.yourmind, title='article', slug='article') article.featured_in_homepage_start_date = timezone.now() article.save() article2 = self.mk_article(self.yourmind, title='article2', slug='article2') article2.featured_in_homepage_start_date = timezone.now() article2.save() article3 = self.mk_article(self.yourmind, title='article3', slug='article3') article3.featured_in_homepage_start_date = timezone.now() article3.save() demote_articles() promote_articles() homepage_articles = load_descendant_articles_for_section( {}, self.yourmind, featured_in_homepage=True, count=5) self.assertEqual(homepage_articles[0].title, 'article3') article2.featured_in_homepage_start_date = timezone.now() article2.save() demote_articles() promote_articles() homepage_articles = load_descendant_articles_for_section( {}, self.yourmind, featured_in_homepage=True, count=5) self.assertEqual(homepage_articles[0].title, 'article2')
def test_latest_rotation_no_valid_days(self): """This test that if the date range and times are set for content rotation, that it doesn't rotate without any weekdays set""" site = Site.objects.get(is_default_site=True) settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.monday_rotation = True site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1}, {'type': 'time', 'value': time2}]) site_settings.save() for i in range(5): self.footer = FooterPage( title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles( self.yourmind_sub, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False) self.assertEqual(self.main.latest_articles().count(), 10) first_article_old = self.main.latest_articles()[0].pk last_article_old = self.main.latest_articles()[9].pk rotate_content(4) self.assertEqual(first_article_old, self.main.latest_articles()[0].pk) self.assertEqual(last_article_old, self.main.latest_articles()[9].pk)
def test_order_by_promote_date_homepage(self): article = self.mk_article( self.yourmind, title='article', slug='article') article.featured_in_homepage_start_date = timezone.now() article.save() article2 = self.mk_article( self.yourmind, title='article2', slug='article2') article2.featured_in_homepage_start_date = timezone.now() article2.save() article3 = self.mk_article( self.yourmind, title='article3', slug='article3') article3.featured_in_homepage_start_date = timezone.now() article3.save() demote_articles() promote_articles() homepage_articles = load_descendant_articles_for_section( {}, self.yourmind, featured_in_homepage=True, count=5) self.assertEqual(homepage_articles[0].title, 'article3') article2.featured_in_homepage_start_date = timezone.now() article2.save() demote_articles() promote_articles() homepage_articles = load_descendant_articles_for_section( {}, self.yourmind, featured_in_homepage=True, count=5) self.assertEqual(homepage_articles[0].title, 'article2')
def test_latest_rotation_on_multisite(self): """This test that if the date range, weekdays and times are set for content rotation, that the content rotates accordingly""" # sets the site settings site = self.main2.get_site() settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1 }, { 'type': 'time', 'value': time2 }]) site_settings.monday_rotation = True site_settings.save() # creates articles and pages, some set to feature in latest, others not for i in range(5): self.footer = FooterPage(title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles(self.yourmind_sub22, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub22, count=10, featured_in_latest=False) self.assertEqual(self.main2.latest_articles().count(), 10) # gets the first and last articles of the list before it rotates first_article_old = self.main2.latest_articles()[0].pk last_article_old = self.main2.latest_articles()[9].pk rotate_content(day=0) # checks to see that the number of latest articles has not increased self.assertEqual(self.main2.latest_articles().count(), 10) # checks to see the the old first articles is not still the first one self.assertNotEqual(first_article_old, self.main2.latest_articles()[0].pk) # checks to see the old first article has moved up 2 places self.assertEqual(first_article_old, self.main2.latest_articles()[2].pk) # checks to see the the old last article is not still last self.assertNotEqual(last_article_old, self.main2.latest_articles()[8].pk) featured_from_main1 = self.main2.latest_articles().descendant_of( self.main).count() self.assertEqual(featured_from_main1, 0)
def test_promote_articles_section(self): article = self.mk_article( self.yourmind, title='article', slug='article') article.featured_in_section_start_date = timezone.now() article.save() demote_articles() promote_articles() article = ArticlePage.objects.all().first() self.assertTrue(article.featured_in_section)
def test_latest_rotation_on_draft_articles(self): site = Site.objects.get(is_default_site=True) site_settings = SiteSettings.for_site(site) site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1 }, { 'type': 'time', 'value': time2 }]) site_settings.monday_rotation = True site_settings.save() article = self.mk_article(self.yourmind, title='article', slug='article') article.featured_in_latest_start_date = timezone.now() article.save() article2 = self.mk_article(self.yourmind, title='article2', slug='article2') article2.featured_in_latest_start_date = timezone.now() article2.save() article3 = self.mk_article(self.yourmind, title='article3', slug='article3') article3.save() promote_articles() article.refresh_from_db() article2.refresh_from_db() article3.refresh_from_db() self.assertTrue(article.live) self.assertTrue(article2.live) self.assertTrue(article3.live) article.unpublish() article.refresh_from_db() self.assertTrue(article.featured_in_latest) self.assertTrue(article2.featured_in_latest) self.assertFalse(article3.featured_in_latest) rotate_content(0) article.refresh_from_db() article2.refresh_from_db() article3.refresh_from_db() self.assertFalse(article.live) self.assertTrue(article2.live) self.assertTrue(article3.live)
def test_homepage_rotation_subcategories(self): def get_featured_articles(section): return section.featured_in_homepage_articles() non_rotating_articles = self.mk_articles(self.yourmind_sub, count=3, featured_in_homepage=False) rotate_content() for article in non_rotating_articles: self.assertFalse(article.featured_in_latest) self.assertEqual(get_featured_articles(self.yourmind).count(), 0) self.mk_articles(self.yourmind_sub2, count=5, featured_in_homepage_start_date=timezone.now()) self.mk_articles(self.yourmind_sub3, count=5, featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_homepage=False) self.mk_articles(self.yourmind_sub2, count=10, featured_in_homepage=False) self.mk_articles(self.yourmind_sub3, count=10, featured_in_homepage=False) self.assertEqual(get_featured_articles(self.yourmind_sub).count(), 0) self.assertEqual(get_featured_articles(self.yourmind_sub2).count(), 5) self.assertEqual(get_featured_articles(self.yourmind_sub3).count(), 5) self.yourmind_sub.content_rotation_start_date = timezone.now() self.yourmind_sub.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] self.yourmind_sub.time = dumps([{ 'type': 'time', 'value': time1 }, { 'type': 'time', 'value': time2 }]) self.yourmind_sub.monday_rotation = True self.yourmind_sub.tuesday_rotation = True self.yourmind_sub.wednesday_rotation = True self.yourmind_sub.thursday_rotation = True self.yourmind_sub.friday_rotation = True self.yourmind_sub.saturday_rotation = True self.yourmind_sub.sunday_rotation = True self.yourmind_sub.save_revision().publish() rotate_content() self.assertEqual( ArticlePage.objects.live().filter( featured_in_homepage=True).count(), 11) self.assertTrue(ArticlePage.objects.live().filter( featured_in_homepage=True).child_of(self.yourmind_sub).exists())
def test_promote_articles_section(self): article = self.mk_article(self.yourmind, title='article', slug='article') article.featured_in_section_start_date = timezone.now() article.save() demote_articles() promote_articles() article = ArticlePage.objects.all().first() self.assertTrue(article.featured_in_section)
def test_latest_rotation_on_multisite(self): """This test that if the date range, weekdays and times are set for content rotation, that the content rotates accordingly""" # sets the site settings site = self.main2.get_site() settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1}, {'type': 'time', 'value': time2}]) site_settings.monday_rotation = True site_settings.save() # creates articles and pages, some set to feature in latest, others not for i in range(5): self.footer = FooterPage( title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles( self.yourmind_sub22, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub22, count=10, featured_in_latest=False) self.assertEqual(self.main2.latest_articles().count(), 10) # gets the first and last articles of the list before it rotates first_article_old = self.main2.latest_articles()[0].pk last_article_old = self.main2.latest_articles()[9].pk rotate_content(day=0) # checks to see that the number of latest articles has not increased self.assertEqual(self.main2.latest_articles().count(), 10) # checks to see the the old first articles is not still the first one self.assertNotEqual( first_article_old, self.main2.latest_articles()[0].pk) # checks to see the old first article has moved up 2 places self.assertEqual( first_article_old, self.main2.latest_articles()[2].pk) # checks to see the the old last article is not still last self.assertNotEqual( last_article_old, self.main2.latest_articles()[8].pk) featured_from_main1 = self.main2.latest_articles().descendant_of( self.main).count() self.assertEqual(featured_from_main1, 0)
def test_if_mexican_spanish_translated_pages_are_shown_on_front_end(self): en_section2 = self.mk_section( self.section_index, title='English section2') self.mk_section_translation( en_section2, self.spanish_mexico, title=en_section2.title + ' in Mexican Spanish') en_page = self.mk_article( en_section2, title='English article1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) promote_articles() en_page = ArticlePage.objects.get(pk=en_page.pk) self.mk_article_translation( en_page, self.spanish_mexico, title=en_page.title + ' in Mexican Spanish',) response = self.client.get('/') self.assertContains( response, 'English section2') self.assertNotContains( response, 'English section2 in Mexican Spanish') self.assertContains( response, '<a href="/sections-main-1/english-section2/english-article1/" ' 'class="promoted-article-list__anchor ' 'promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1</h3></a>', html=True) self.assertNotContains( response, 'English article1 in Mexican Spanish') response = self.client.get('/locale/es-mx/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-mexican-spanish/"' ' class="section-listing__theme-bg-link">' 'English section2 in Mexican Spanish</a>') self.assertContains( response, '<a href="/sections-main-1/english-section2/' 'english-article1-in-mexican-spanish/"' ' class="promoted-article-list__anchor ' 'promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in Mexican Spanish</h3></a>', html=True)
def test_if_mexican_spanish_translated_pages_are_shown_on_front_end(self): en_section2 = self.mk_section(self.section_index, title='English section2') self.mk_section_translation(en_section2, self.spanish_mexico, title=en_section2.title + ' in Mexican Spanish') en_page = self.mk_article( en_section2, title='English article1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) promote_articles() en_page = ArticlePage.objects.get(pk=en_page.pk) self.mk_article_translation( en_page, self.spanish_mexico, title=en_page.title + ' in Mexican Spanish', ) response = self.client.get('/') self.assertContains(response, 'English section2') self.assertNotContains(response, 'English section2 in Mexican Spanish') self.assertContains( response, '<a href="/sections-main-1/english-section2/english-article1/" ' 'class="promoted-article-list__anchor ' 'promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1</h3></a>', html=True) self.assertNotContains(response, 'English article1 in Mexican Spanish') response = self.client.get('/locale/es-mx/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-mexican-spanish/"' ' class="section-listing__theme-bg-link">' 'English section2 in Mexican Spanish</a>') self.assertContains(response, '<a href="/sections-main-1/english-section2/' 'english-article1-in-mexican-spanish/"' ' class="promoted-article-list__anchor ' 'promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in Mexican Spanish</h3></a>', html=True)
def test_homepage_rotation_subcategories(self): def get_featured_articles(section): return section.featured_in_homepage_articles() non_rotating_articles = self.mk_articles( self.yourmind_sub, count=3, featured_in_homepage=False) rotate_content() for article in non_rotating_articles: self.assertFalse(article.featured_in_latest) self.assertEqual(get_featured_articles(self.yourmind).count(), 0) self.mk_articles( self.yourmind_sub2, count=5, featured_in_homepage_start_date=timezone.now()) self.mk_articles( self.yourmind_sub3, count=5, featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_articles( self.yourmind_sub, count=10, featured_in_homepage=False) self.mk_articles( self.yourmind_sub2, count=10, featured_in_homepage=False) self.mk_articles( self.yourmind_sub3, count=10, featured_in_homepage=False) self.assertEqual( get_featured_articles(self.yourmind_sub).count(), 0) self.assertEqual( get_featured_articles(self.yourmind_sub2).count(), 5) self.assertEqual( get_featured_articles(self.yourmind_sub3).count(), 5) self.yourmind_sub.content_rotation_start_date = timezone.now() self.yourmind_sub.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] self.yourmind_sub.time = dumps([{ 'type': 'time', 'value': time1}, {'type': 'time', 'value': time2}]) self.yourmind_sub.monday_rotation = True self.yourmind_sub.tuesday_rotation = True self.yourmind_sub.wednesday_rotation = True self.yourmind_sub.thursday_rotation = True self.yourmind_sub.friday_rotation = True self.yourmind_sub.saturday_rotation = True self.yourmind_sub.sunday_rotation = True self.yourmind_sub.save_revision().publish() rotate_content() self.assertEqual( ArticlePage.objects.live().filter( featured_in_homepage=True).count(), 11) self.assertTrue(ArticlePage.objects.live().filter( featured_in_homepage=True).child_of(self.yourmind_sub).exists())
def test_latest_rotation_on_draft_articles(self): site = Site.objects.get(is_default_site=True) site_settings = SiteSettings.for_site(site) site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1}, {'type': 'time', 'value': time2}]) site_settings.monday_rotation = True site_settings.save() article = self.mk_article( self.yourmind, title='article', slug='article') article.featured_in_latest_start_date = timezone.now() article.save() article2 = self.mk_article( self.yourmind, title='article2', slug='article2') article2.featured_in_latest_start_date = timezone.now() article2.save() article3 = self.mk_article( self.yourmind, title='article3', slug='article3') article3.save() promote_articles() article.refresh_from_db() article2.refresh_from_db() article3.refresh_from_db() self.assertTrue(article.live) self.assertTrue(article2.live) self.assertTrue(article3.live) article.unpublish() article.refresh_from_db() self.assertTrue(article.featured_in_latest) self.assertTrue(article2.featured_in_latest) self.assertFalse(article3.featured_in_latest) rotate_content(0) article.refresh_from_db() article2.refresh_from_db() article3.refresh_from_db() self.assertFalse(article.live) self.assertTrue(article2.live) self.assertTrue(article3.live)
def test_home_index(self): articles = self.mk_articles(parent=self.yourmind, count=30) for article in articles[:12]: article.featured_in_latest_start_date = timezone.now() article.save() promote_articles() articles = ArticlePage.objects.all() response = self.client.get('/home-index/?page=2') for article in articles[12:24]: self.assertContains(response, article.title) for article in articles[24:]: self.assertNotContains(response, article.title) response = self.client.get('/home-index/?page=3') for article in articles[24:]: self.assertContains(response, article.title) for article in articles[12:24]: self.assertNotContains(response, article.title) self.assertNotContains(response, 'More')
def test_homepage_rotation(self): def get_featured_articles(section): return section.featured_in_homepage_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_homepage=False) self.assertEqual(get_featured_articles(self.yourmind_sub).count(), 10) first_article_old = get_featured_articles(self.yourmind_sub)[0].pk last_article_old = get_featured_articles(self.yourmind_sub)[9].pk self.yourmind.content_rotation_start_date = timezone.now() self.yourmind.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] self.yourmind.time = dumps([{ 'type': 'time', 'value': time1 }, { 'type': 'time', 'value': time2 }]) self.yourmind.monday_rotation = True self.yourmind.tuesday_rotation = True self.yourmind.wednesday_rotation = True self.yourmind.thursday_rotation = True self.yourmind.friday_rotation = True self.yourmind.saturday_rotation = True self.yourmind.sunday_rotation = True self.yourmind.save_revision().publish() rotate_content() self.assertEqual(ArticlePage.objects.count(), 20) self.assertEqual(get_featured_articles(self.yourmind_sub).count(), 10) self.assertNotEqual(first_article_old, get_featured_articles(self.yourmind_sub)[0].pk) self.assertEqual(first_article_old, get_featured_articles(self.yourmind_sub)[2].pk) self.assertNotEqual(last_article_old, get_featured_articles(self.yourmind_sub)[9].pk)
def test_latest_articles_get_priority_when_tag_navigation_enabled(self): tag = self.mk_tag(parent=self.tag_index) tag.feature_in_homepage = True tag.save_revision().publish() articles = self.mk_articles( parent=self.yourmind, featured_in_latest_start_date=( timezone.now() - timedelta(days=1)), featured_in_homepage_start_date=timezone.now(), count=30) latest_of_latest_articles = self.mk_article( parent=self.yourmind, featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) for article in articles: ArticlePageTags.objects.create(page=article, tag=tag) promote_articles() response = self.client.get('/') latest_articles = response.context['tag_nav_data']['latest_articles'] self.assertEqual(latest_articles[0].pk, latest_of_latest_articles.pk)
def test_homepage_rotation(self): def get_featured_articles(section): return section.featured_in_homepage_articles() self.mk_articles( self.yourmind_sub, count=10, featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_articles( self.yourmind_sub, count=10, featured_in_homepage=False) self.assertEqual( get_featured_articles(self.yourmind_sub).count(), 10) first_article_old = get_featured_articles(self.yourmind_sub)[0].pk last_article_old = get_featured_articles(self.yourmind_sub)[9].pk self.yourmind.content_rotation_start_date = timezone.now() self.yourmind.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] self.yourmind.time = dumps([{ 'type': 'time', 'value': time1}, {'type': 'time', 'value': time2}]) self.yourmind.monday_rotation = True self.yourmind.tuesday_rotation = True self.yourmind.wednesday_rotation = True self.yourmind.thursday_rotation = True self.yourmind.friday_rotation = True self.yourmind.saturday_rotation = True self.yourmind.sunday_rotation = True self.yourmind.save_revision().publish() rotate_content() self.assertEqual( ArticlePage.objects.count(), 20) self.assertEqual( get_featured_articles(self.yourmind_sub).count(), 10) self.assertNotEqual( first_article_old, get_featured_articles(self.yourmind_sub)[0].pk) self.assertEqual( first_article_old, get_featured_articles(self.yourmind_sub)[2].pk) self.assertNotEqual( last_article_old, get_featured_articles(self.yourmind_sub)[9].pk)
def test_latest_rotation_no_valid_days(self): """This test that if the date range and times are set for content rotation, that it doesn't rotate without any weekdays set""" site = Site.objects.get(is_default_site=True) settings = SettingsProxy(site) site_settings = settings['core']['SiteSettings'] site_settings.monday_rotation = True site_settings.content_rotation_start_date = timezone.now() site_settings.content_rotation_end_date = timezone.now() + timedelta( days=1) time1 = str(timezone.now().time())[:8] time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8] site_settings.time = dumps([{ 'type': 'time', 'value': time1 }, { 'type': 'time', 'value': time2 }]) site_settings.save() for i in range(5): self.footer = FooterPage(title='Footer Page %s', slug='footer-page-%s' % (i, )) self.footer_index.add_child(instance=self.footer) self.assertEqual(FooterPage.objects.live().count(), 5) self.assertEqual(self.main.latest_articles().count(), 0) self.mk_articles(self.yourmind_sub, count=10, featured_in_latest_start_date=timezone.now()) promote_articles() self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False) self.assertEqual(self.main.latest_articles().count(), 10) first_article_old = self.main.latest_articles()[0].pk last_article_old = self.main.latest_articles()[9].pk rotate_content(4) self.assertEqual(first_article_old, self.main.latest_articles()[0].pk) self.assertEqual(last_article_old, self.main.latest_articles()[9].pk)
def test_order_by_promote_date_latest(self): article = self.mk_article( self.yourmind, title='article', slug='article') article.featured_in_latest_start_date = timezone.now() article.save() article2 = self.mk_article( self.yourmind, title='article2', slug='article2') article2.featured_in_latest_start_date = timezone.now() article2.save() article3 = self.mk_article( self.yourmind, title='article3', slug='article3') article3.featured_in_latest_start_date = timezone.now() article3.save() demote_articles() promote_articles() latest_articles = Main.objects.all().first().latest_articles() self.assertEqual(latest_articles[0].title, 'article3') article2.featured_in_latest_start_date = timezone.now() article2.save() demote_articles() promote_articles() latest_articles = Main.objects.all().first().latest_articles() self.assertEqual(latest_articles[0].title, 'article2')
def test_site_exists_if_no_iems_translated_for_translated_only(self): site_settings = SiteSettings.for_site(self.main.get_site()) site_settings.enable_tag_navigation = True site_settings.show_only_translated_pages = True site_settings.save() tag = self.mk_tag(parent=self.tag_index) tag.feature_in_homepage = True tag.save_revision().publish() articles = self.mk_articles( parent=self.english_section, featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now(), count=30) for article in articles: ArticlePageTags.objects.create(page=article, tag=tag) promote_articles() response = self.client.get('/') self.assertEqual(response.status_code, 200) response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertEqual(response.status_code, 200)
def test_article_not_repeated_when_tag_navigation_enabled_homepage(self): tag = self.mk_tag(parent=self.tag_index) tag.feature_in_homepage = True tag.save_revision().publish() articles = self.mk_articles( parent=self.yourmind, featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now(), count=30) for article in articles: ArticlePageTags.objects.create(page=article, tag=tag) promote_articles() response = self.client.get('/') data = response.context['tag_nav_data'] hoempage_articles = [] for section, section_list in data['sections']: homepage_articles = list(chain(hoempage_articles, section_list)) for tag, tag_list in data['tags_list']: homepage_articles = list(chain(homepage_articles, tag_list)) homepage_articles = list(chain( homepage_articles, data['latest_articles'])) self.assertTrue(self.unique(homepage_articles))
def test_if_main_lang_page_unpublished_translated_page_still_shows(self): eng_section2 = self.mk_section(self.section_index, title='English section2') self.mk_section_translation(eng_section2, self.french, title=eng_section2.title + ' in french') eng_section2.unpublish() self.mk_article(eng_section2, title='English article1 in section 2', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) en_page = self.mk_article( self.english_section, title='English article1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_article_translation( en_page, self.french, title=en_page.title + ' in french', ) en_page2 = self.mk_article( self.english_section, title='English article2', featured_in_latest_start_date=timezone.now()) promote_articles() en_page2 = ArticlePage.objects.get(title=en_page2.title) self.mk_article_translation( en_page2, self.french, title=en_page2.title + ' in french', ) en_page2.unpublish() # tests that on home page users will only # see the pages that are published response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertNotContains( response, '<a href="/sections-main-1/english-section2/"' ' class="section-listing__theme-bg-link">English section2</a>') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading ' 'promoted-article-list__heading">' ' English article1</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' ' English article2</h3></a>', html=True) response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2/"' ' class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2</h3></a>', html=True) # tests that when switching to a child language # users will see all the published translated pages # even if the main language page is unpublished response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-french/"' ' class="section-listing__theme-bg-link">' 'English section2 in french</a>') self.assertContains(response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in french</h3>', html=True) self.assertContains(response, '<a href="/sections-main-1/english-section2/' 'english-article1-in-section-2/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in section 2</h3></a>', html=True) response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/"' ' class="promoted-article-list__anchor">' '<h3 class="heading' ' promoted-article__title">English article1 in french</h3></a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article2-in-french/"' ' class="promoted-article-list__anchor">' '<h3 class="heading' ' promoted-article__title">English article2 in french</h3></a>', html=True)
def test_that_only_translated_pages_are_shown_on_front_end(self): # set the site settings show_only_translated_pages to True default_site = Site.objects.get(is_default_site=True) setting = SiteSettings.objects.create(site=default_site) setting.show_only_translated_pages = True setting.save() eng_section2 = self.mk_section(self.section_index, title='English section2') self.mk_section_translation(eng_section2, self.french, title=eng_section2.title + ' in french') article1 = self.mk_article( eng_section2, title='English article1 in section 2', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) self.mk_article_translation( article1, self.french, title=article1.title + ' in french', ) article2 = self.mk_article( self.english_section, title='English article2 in section 1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) self.mk_article_translation( article2, self.french, title=article2.title + ' in french', ) promote_articles() # tests that in Home page users will only see the sections # that have been translated response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertContains( response, '<a href="/sections-main-1/english-section2/"' ' class="section-listing__theme-bg-link">English section2</a>') response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-french/"' ' class="section-listing__theme-bg-link">' 'English section2 in french</a>') self.assertNotContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') en_page = self.mk_article(self.english_section, title='English article1', featured_in_latest_start_date=timezone.now()) promote_articles() en_page = ArticlePage.objects.get(title=en_page.title) self.mk_article_translation( en_page, self.french, title=en_page.title + ' in french', ) self.mk_article(self.english_section, title='English article2', featured_in_latest_start_date=timezone.now()) promote_articles() # tests that in english section users will only see the articles # that have been translated response = self.client.get('/locale/en/') response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1' '</h3></a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/english-article2-2/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2' '</h3></a>', html=True) response = self.client.get('/locale/fr/') response = self.client.get('/sections-main-1/english-section/') self.assertContains(response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1 in french' '</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2-2/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2' '</h3></a>', html=True) # tests that in latest block users will only see the articles # that have been translated response = self.client.get('/') self.assertContains(response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">' 'English article1 in french' '</h5></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-3/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">' 'English article1' '</h5></a>', html=True) response = self.client.get('/locale/en/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">English article1</h5>' '</a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/english-article2-2/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">English article2</h5>' '</a>', html=True)
def test_homepage_content_demotions(self): def get_featured_articles(section): return ArticlePage.objects.live().filter( featured_in_homepage=True, ).descendant_of(section) local_time = timezone.localtime().replace(year=2017, month=1, day=1) self.mk_articles(self.yourmind_sub, count=2, featured_in_homepage_start_date=local_time) self.mk_articles( self.yourmind_sub, count=1, featured_in_homepage_start_date=local_time.replace(day=2)) self.mk_articles(self.yourmind_sub, count=4, featured_in_homepage=False) promote_articles() self.mk_articles( self.mylife, count=2, featured_in_homepage_start_date=local_time.replace(day=3)) self.mk_articles( self.mylife, count=1, featured_in_homepage_start_date=local_time.replace(day=4)) self.mk_articles(self.mylife, count=4, featured_in_homepage=False) promote_articles() self.assertEqual(get_featured_articles(self.yourmind).count(), 3) self.assertEqual(get_featured_articles(self.mylife).count(), 3) self.yourmind.content_rotation_start_date = timezone.now() self.yourmind.content_rotation_end_date = timezone.now() + \ timedelta(days=1) self.mylife.content_rotation_start_date = timezone.now() self.mylife.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] self.yourmind.time = dumps([{'type': 'time', 'value': time1}]) self.yourmind.monday_rotation = True self.yourmind.tuesday_rotation = True self.yourmind.wednesday_rotation = True self.yourmind.thursday_rotation = True self.yourmind.friday_rotation = True self.yourmind.saturday_rotation = True self.yourmind.sunday_rotation = True self.yourmind.save_revision().publish() self.mylife.time = dumps([ { 'type': 'time', 'value': time1 }, ]) self.mylife.monday_rotation = True self.mylife.tuesday_rotation = True self.mylife.wednesday_rotation = True self.mylife.thursday_rotation = True self.mylife.friday_rotation = True self.mylife.saturday_rotation = True self.mylife.sunday_rotation = True self.mylife.save_revision().publish() rotate_content() self.assertEqual(ArticlePage.objects.count(), 14) self.assertEqual(get_featured_articles(self.yourmind).count(), 3) self.assertEqual(get_featured_articles(self.mylife).count(), 3)
def test_homepage_content_demotions(self): def get_featured_articles(section): return ArticlePage.objects.live().filter( featured_in_homepage=True,).descendant_of(section) self.mk_articles( self.yourmind_sub, count=2, featured_in_homepage_start_date=timezone.datetime(2017, 1, 1, 1)) self.mk_articles( self.yourmind_sub, count=1, featured_in_homepage_start_date=timezone.datetime(2017, 1, 2, 1)) self.mk_articles( self.yourmind_sub, count=4, featured_in_homepage=False) promote_articles() self.mk_articles( self.mylife, count=2, featured_in_homepage_start_date=timezone.datetime(2017, 1, 3, 1)) self.mk_articles( self.mylife, count=1, featured_in_homepage_start_date=timezone.datetime(2017, 1, 4, 1)) self.mk_articles( self.mylife, count=4, featured_in_homepage=False) promote_articles() self.assertEqual( get_featured_articles(self.yourmind).count(), 3) self.assertEqual( get_featured_articles(self.mylife).count(), 3) self.yourmind.content_rotation_start_date = timezone.now() self.yourmind.content_rotation_end_date = timezone.now() + \ timedelta(days=1) self.mylife.content_rotation_start_date = timezone.now() self.mylife.content_rotation_end_date = timezone.now() + \ timedelta(days=1) time1 = str(timezone.now().time())[:8] self.yourmind.time = dumps([{ 'type': 'time', 'value': time1}]) self.yourmind.monday_rotation = True self.yourmind.tuesday_rotation = True self.yourmind.wednesday_rotation = True self.yourmind.thursday_rotation = True self.yourmind.friday_rotation = True self.yourmind.saturday_rotation = True self.yourmind.sunday_rotation = True self.yourmind.save_revision().publish() self.mylife.time = dumps([{ 'type': 'time', 'value': time1}, ]) self.mylife.monday_rotation = True self.mylife.tuesday_rotation = True self.mylife.wednesday_rotation = True self.mylife.thursday_rotation = True self.mylife.friday_rotation = True self.mylife.saturday_rotation = True self.mylife.sunday_rotation = True self.mylife.save_revision().publish() rotate_content() self.assertEqual( ArticlePage.objects.count(), 14) self.assertEqual( get_featured_articles(self.yourmind).count(), 3) self.assertEqual( get_featured_articles(self.mylife).count(), 3)
def test_that_only_translated_pages_are_shown_on_front_end(self): # set the site settings show_only_translated_pages to True default_site = Site.objects.get(is_default_site=True) setting = SiteSettings.objects.create(site=default_site) setting.show_only_translated_pages = True setting.save() eng_section2 = self.mk_section( self.section_index, title='English section2') self.mk_section_translation( eng_section2, self.french, title=eng_section2.title + ' in french') article1 = self.mk_article( eng_section2, title='English article1 in section 2', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) self.mk_article_translation( article1, self.french, title=article1.title + ' in french',) article2 = self.mk_article( self.english_section, title='English article2 in section 1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) self.mk_article_translation( article2, self.french, title=article2.title + ' in french',) promote_articles() # tests that in Home page users will only see the sections # that have been translated response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertContains( response, '<a href="/sections-main-1/english-section2/"' ' class="section-listing__theme-bg-link">English section2</a>') response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-french/"' ' class="section-listing__theme-bg-link">' 'English section2 in french</a>') self.assertNotContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') en_page = self.mk_article(self.english_section, title='English article1', featured_in_latest_start_date=timezone.now()) promote_articles() en_page = ArticlePage.objects.get(title=en_page.title) self.mk_article_translation( en_page, self.french, title=en_page.title + ' in french',) self.mk_article(self.english_section, title='English article2', featured_in_latest_start_date=timezone.now()) promote_articles() # tests that in english section users will only see the articles # that have been translated response = self.client.get('/locale/en/') response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1' '</h3></a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/english-article2-2/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2' '</h3></a>', html=True) response = self.client.get('/locale/fr/') response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1 in french' '</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2-2/" ' 'class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2' '</h3></a>', html=True) # tests that in latest block users will only see the articles # that have been translated response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">' 'English article1 in french' '</h5></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-3/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">' 'English article1' '</h5></a>', html=True) response = self.client.get('/locale/en/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">English article1</h5>' '</a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/english-article2-2/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-headings">' '<h5 class="heading' ' promoted-article__title--theme-headings">English article2</h5>' '</a>', html=True)
def test_if_main_lang_page_unpublished_translated_page_still_shows(self): eng_section2 = self.mk_section( self.section_index, title='English section2') self.mk_section_translation( eng_section2, self.french, title=eng_section2.title + ' in french') eng_section2.unpublish() self.mk_article( eng_section2, title='English article1 in section 2', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) en_page = self.mk_article( self.english_section, title='English article1', featured_in_latest_start_date=timezone.now(), featured_in_homepage_start_date=timezone.now()) promote_articles() self.mk_article_translation( en_page, self.french, title=en_page.title + ' in french',) en_page2 = self.mk_article( self.english_section, title='English article2', featured_in_latest_start_date=timezone.now()) promote_articles() en_page2 = ArticlePage.objects.get(title=en_page2.title) self.mk_article_translation( en_page2, self.french, title=en_page2.title + ' in french',) en_page2.unpublish() # tests that on home page users will only # see the pages that are published response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertNotContains( response, '<a href="/sections-main-1/english-section2/"' ' class="section-listing__theme-bg-link">English section2</a>') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading ' 'promoted-article-list__heading">' ' English article1</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2-3/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' ' English article2</h3></a>', html=True) response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/english-article1-3/"' ' class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article1</h3></a>', html=True) self.assertNotContains( response, '<a href="/sections-main-1/english-section/english-article2/"' ' class="promoted-article-list__anchor">' '<h3 class="heading promoted-article__title">' 'English article2</h3></a>', html=True) # tests that when switching to a child language # users will see all the published translated pages # even if the main language page is unpublished response = self.client.get('/locale/fr/') response = self.client.get('/') self.assertContains( response, '<a href="/sections-main-1/english-section/"' ' class="section-listing__theme-bg-link">English section</a>') self.assertContains( response, '<a href="/sections-main-1/english-section2-in-french/"' ' class="section-listing__theme-bg-link">' 'English section2 in french</a>') self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/"' ' class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in french</h3>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section2/' 'english-article1-in-section-2/" ' 'class="promoted-article-list__anchor' ' promoted-article-list__anchor--theme-bg">' '<h3 class="heading' ' promoted-article-list__heading">' 'English article1 in section 2</h3></a>', html=True) response = self.client.get('/sections-main-1/english-section/') self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article1-in-french/"' ' class="promoted-article-list__anchor">' '<h3 class="heading' ' promoted-article__title">English article1 in french</h3></a>', html=True) self.assertContains( response, '<a href="/sections-main-1/english-section/' 'english-article2-in-french/"' ' class="promoted-article-list__anchor">' '<h3 class="heading' ' promoted-article__title">English article2 in french</h3></a>', html=True)