def setUp(self): self.request = mock.MagicMock() self.request.site.hostname = 'localhost:8000' self.limit = 10 self.sublanding_page = SublandingPage(title='title') helpers.publish_page(child=self.sublanding_page) self.post1 = BrowseFilterablePage(title='post 1') self.post2 = BrowseFilterablePage(title='post 2') # the content of this post has both a full_width_text # and a filter_controls self.post1.content = StreamValue(self.post1.content.stream_block, [atomic.full_width_text, atomic.filter_controls], True) # this one only has a filter_controls self.post2.content = StreamValue(self.post1.content.stream_block, [atomic.filter_controls], True) helpers.save_new_page(self.post1, self.sublanding_page) helpers.save_new_page(self.post2, self.sublanding_page) # manually set the publication date of the posts to ensure consistent # order of retrieval in test situations, otherwise the `date_published` # can vary due to commit order self.child1_of_post1 = AbstractFilterPage(title='child 1 of post 1', date_published=dt.date(2016, 9, 1)) self.child2_of_post1 = AbstractFilterPage(title='child 2 of post 1', date_published=dt.date(2016, 9, 2)) self.child1_of_post2 = AbstractFilterPage(title='child 1 of post 2', date_published=dt.date(2016, 9, 3)) helpers.save_new_page(self.child1_of_post1, self.post1) helpers.save_new_page(self.child2_of_post1, self.post1) helpers.save_new_page(self.child1_of_post2, self.post2)
class TestFilterableList(TestCase): def alphabetical_topics(self): controls['value']['topic_filtering'] = 'sort_alphabetically' return controls def topics_by_frequency(self): controls['value']['topic_filtering'] = 'sort_by_frequency' return controls def set_up_published_pages(self): page1 = BlogPage(title='test page 1') page1.tags.add(u'C-tag-3-instances') page2 = EventPage(title='test page 2', start_dt=datetime.now(timezone('UTC'))) page2.tags.add(u'B-tag-2-instances') page2.tags.add(u'C-tag-3-instances') page3 = BlogPage(title='test page 3') page3.tags.add(u'A-tag-1-instance') page3.tags.add(u'B-tag-2-instances') page3.tags.add(u'C-tag-3-instances') helpers.publish_page(page1) helpers.publish_page(page2) helpers.publish_page(page3) filterable_pages = AbstractFilterPage.objects.live() self.page_ids = filterable_pages.values_list('id', flat=True) def set_up_filterable_list_page(self, value): self.page = BrowseFilterablePage(title='Browse filterable page') self.page.content = StreamValue(self.page.content.stream_block, [value], True) helpers.publish_page(child=self.page) self.block = self.page.filterable_list_wagtail_block() def test_get_filterable_topics_sort_by_frequency(self): self.set_up_filterable_list_page(self.topics_by_frequency()) self.set_up_published_pages() topics = FilterableList().get_filterable_topics( self.page_ids, self.block.value) expected_topics = [ 'C-tag-3-instances', 'B-tag-2-instances', 'A-tag-1-instance' ] self.assertEqual([x[1] for x in topics], expected_topics) def test_get_filterable_topics_sort_alphabetically(self): self.set_up_filterable_list_page(self.alphabetical_topics()) self.set_up_published_pages() topics = FilterableList().get_filterable_topics( self.page_ids, self.block.value) expected_topics = [ 'A-tag-1-instance', 'B-tag-2-instances', 'C-tag-3-instances' ] self.assertEqual([x[1] for x in topics], expected_topics)
def test_nav_includes_browse_filterable_sibling_pages(self): browse_filterable_page = BrowseFilterablePage( title='Browse filterable page') helpers.publish_page(child=browse_filterable_page) nav, has_children = util.get_secondary_nav_items( self.request, self.browse_page1) self.assertEqual(len(nav), 3) self.assertEqual(nav[0]['title'], self.browse_page1.title) self.assertEqual(nav[1]['title'], self.browse_page2.title) self.assertEqual(nav[2]['title'], browse_filterable_page.title)
def test_has_children_is_true_for_browse_page_with_browse_filterable_child( self): browse_filterable_page = BrowsePage(title='Non-browse page') helpers.publish_page(child=browse_filterable_page) browse_filterable_page_child = BrowseFilterablePage( title='Child of non-browse page') helpers.save_new_page(browse_filterable_page_child, browse_filterable_page) nav, has_children = util.get_secondary_nav_items( self.request, browse_filterable_page) self.assertEqual(has_children, True)
def setUp(self): self.limit = 10 self.sublanding_page = SublandingPage(title='title') helpers.publish_page(child=self.sublanding_page) # This post has both a FullWidthText and a FilterableList. self.post1 = BrowseFilterablePage(title='post 1', content=json.dumps([ atomic.full_width_text, atomic.filter_controls ])) helpers.save_new_page(self.post1, self.sublanding_page) # This one only has a FilterableList. self.post2 = BrowseFilterablePage(title='post 2', content=json.dumps( [atomic.filter_controls])) helpers.save_new_page(self.post2, self.sublanding_page) # manually set the publication date of the posts to ensure consistent # order of retrieval in test situations, otherwise the `date_published` # can vary due to commit order self.child1_of_post1 = AbstractFilterPage(title='child 1 of post 1', date_published=dt.date( 2016, 9, 1)) self.child2_of_post1 = AbstractFilterPage(title='child 2 of post 1', date_published=dt.date( 2016, 9, 2)) self.child1_of_post2 = AbstractFilterPage(title='child 1 of post 2', date_published=dt.date( 2016, 9, 3)) helpers.save_new_page(self.child1_of_post1, self.post1) helpers.save_new_page(self.child2_of_post1, self.post1) helpers.save_new_page(self.child1_of_post2, self.post2) self.rebuild_elasticsearch_index('v1', stdout=StringIO())
def set_up_filterable_list_page(self, value): self.page = BrowseFilterablePage(title='Browse filterable page') self.page.content = StreamValue(self.page.content.stream_block, [value], True) helpers.publish_page(child=self.page) self.block = self.page.filterable_list_wagtail_block()
def run(): print('Running script \'scripts.initial_data\' ...') admin_user = None site_root = None events = None admin_user = User.objects.filter(username='******') if not admin_user: admin_user = User(username='******', password=make_password( os.environ.get('WAGTAIL_ADMIN_PW')), is_superuser=True, is_active=True, is_staff=True) admin_user.save() else: admin_user = admin_user[0] # Creates a new site root `CFGov` site_root = HomePage.objects.filter(title='CFGOV') if not site_root: root = Page.objects.first() site_root = HomePage(title='CFGOV', slug='home-page', depth=2, owner=admin_user) site_root.live = True root.add_child(instance=site_root) latest = site_root.save_revision(user=admin_user, submitted_for_moderation=False) latest.save() else: site_root = site_root[0] # Setting new site root if not Site.objects.filter(hostname='content.localhost').exists(): site = Site.objects.first() site.port = 8000 site.root_page_id = site_root.id site.save() content_site = Site(hostname='content.localhost', port=8000, root_page_id=site_root.id) content_site.save() # Clean Up old_site_root = Page.objects.filter(id=2)[0] if old_site_root: old_site_root.delete() # Events Browse Page required for event `import-data` command if not BrowseFilterablePage.objects.filter(title='Events').exists(): events = BrowseFilterablePage(title='Events', slug='events', owner=admin_user) site_root.add_child(instance=events) revision = events.save_revision( user=admin_user, submitted_for_moderation=False, ) revision.publish() # Archived Events Browse Filterable Page if not BrowseFilterablePage.objects.filter(title='Archive').exists(): archived_events = BrowseFilterablePage(title='Archive', slug='archive', owner=admin_user) if not events: events = BrowseFilterablePage.objects.get(title='Events') events.add_child(instance=archived_events) revision = archived_events.save_revision( user=admin_user, submitted_for_moderation=False, ) revision.publish()