def make_page_with_category(self, category_name): page = AbstractFilterPage(title='test', slug='test') save_new_page(page) category = CFGOVPageCategory.objects.create(name=category_name, page=page) page.categories.add(category)
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)
def test_answer_context_with_nested_journey_referrer(self): """If the referrer is a nested Buying a House journey page, breadcrumbs should reflect the BAH page hierarchy.""" bah_page = BrowsePage(title='Buying a House', slug='owning-a-home') helpers.publish_page(child=bah_page) journey_path = JOURNEY_PATHS[0] journey_page = BrowsePage( title='Journey page', slug=journey_path.strip('/').split('/')[-1] ) helpers.save_new_page(journey_page, bah_page) journey_child_page = BrowsePage( title='Journey child page', slug='child' ) helpers.save_new_page(journey_child_page, journey_page) page = self.page1 mock_site = mock.Mock() mock_site.root_page = HomePage.objects.get(slug='cfgov') request = HttpRequest() request.META['HTTP_REFERER'] = \ 'https://www.consumerfinance.gov' + journey_path + '/child' request.site = mock_site context = page.get_context(request) breadcrumbs = context['breadcrumb_items'] self.assertEqual(len(breadcrumbs), 3) self.assertEqual(breadcrumbs[0]['title'], 'Buying a House') self.assertEqual(breadcrumbs[1]['title'], 'Journey page') self.assertEqual(breadcrumbs[2]['title'], 'Journey child page')
def test_answer_context_with_nested_journey_referrer(self): """If the referrer is a nested Buying a House journey page, breadcrumbs should reflect the BAH page hierarchy.""" bah_page = BrowsePage(title='Buying a House', slug='owning-a-home') helpers.publish_page(child=bah_page) journey_path = JOURNEY_PATHS[0] journey_page = BrowsePage(title='Journey page', slug=journey_path.strip('/').split('/')[-1]) helpers.save_new_page(journey_page, bah_page) journey_child_page = BrowsePage(title='Journey child page', slug='child') helpers.save_new_page(journey_child_page, journey_page) page = self.page1 mock_site = mock.Mock() mock_site.root_page = HomePage.objects.get(slug='cfgov') request = HttpRequest() request.META['HTTP_REFERER'] = \ 'https://www.consumerfinance.gov' + journey_path + '/child' request.site = mock_site context = page.get_context(request) breadcrumbs = context['breadcrumb_items'] self.assertEqual(len(breadcrumbs), 3) self.assertEqual(breadcrumbs[0]['title'], 'Buying a House') self.assertEqual(breadcrumbs[1]['title'], 'Journey page') self.assertEqual(breadcrumbs[2]['title'], 'Journey child page')
def test_answer_context_with_journey_referrer_and_default_category(self): """ If the referrer is a Buying a House journey page and 'mortgages' category does not appear on answer page, breadcrumbs should lead back to BAH & referrer pages, and category should default to first category on answer.""" bah_page = BrowsePage(title='Buying a House', slug='owning-a-home') helpers.publish_page(child=bah_page) journey_path = JOURNEY_PATHS[0] journey_page = BrowsePage( title='Journey page', slug=journey_path.strip('/').split('/')[-1] ) helpers.save_new_page(journey_page, bah_page) answer = self.answer1234 page = answer.english_page page.category.add(self.category) mock_site = mock.Mock() mock_site.root_page = HomePage.objects.get(slug='cfgov') request = HttpRequest() request.META['HTTP_REFERER'] = \ 'https://www.consumerfinance.gov' + journey_path request.site = mock_site context = page.get_context(request) breadcrumbs = context['breadcrumb_items'] self.assertEqual(len(breadcrumbs), 2) self.assertEqual(breadcrumbs[0]['title'], 'Buying a House') self.assertEqual(breadcrumbs[1]['title'], 'Journey page') self.assertEqual(context['category'], self.category)
def test_answer_context_with_process_segment_in_journey_referrer(self): """If the referrer is a nested Buying a House journey page, breadcrumbs should reflect the BAH page hierarchy.""" bah_page = BrowsePage(title='Buying a House', slug='owning-a-home') helpers.publish_page(child=bah_page) journey_page = BrowsePage( title='Compare page', slug='compare' ) helpers.save_new_page(journey_page, bah_page) page = self.page1 mock_site = mock.Mock() mock_site.root_page = HomePage.objects.get(slug='cfgov') request = HttpRequest() request.META['HTTP_REFERER'] = \ 'https://www.consumerfinance.gov/owning-a-home/process/compare/' request.site = mock_site context = page.get_context(request) breadcrumbs = context['breadcrumb_items'] self.assertEqual(len(breadcrumbs), 2) self.assertEqual(breadcrumbs[0]['title'], 'Buying a House') self.assertEqual(breadcrumbs[1]['title'], 'Compare page')
def test_related_posts_events_archive(self): """ Tests whether related posts from archived events are retrieved. Events have no specific categories associated with them so it doesn't matter what that value is set to. Here, we save an archived event child, and thus we expect that we should retrieve both the original event child and the archive event child. We also expect that no other categories (newsroom, blog) have any posts in them. """ helpers.save_new_page(self.events_child2, self.archive_events_parent) self.block.value['relate_posts'] = False self.block.value['relate_newsroom'] = False self.block.value['relate_events'] = True self.block.value['specific_categories'] = ['anything', 'can', 'be', 'here'] related_posts = self.page_with_authors.related_posts(self.block, self.hostname) self.assertIn('Events', related_posts) self.assertEqual(len(related_posts['Events']), 2) self.assertNotIn('Blog', related_posts) self.assertNotIn('Newsroom', related_posts) self.assertEqual(related_posts['Events'][0], self.events_child1) self.assertEqual(related_posts['Events'][1], self.events_child2)
def test_answer_context_with_journey_referrer_and_default_category(self): """ If the referrer is a Buying a House journey page and 'mortgages' category does not appear on answer page, breadcrumbs should lead back to BAH & referrer pages, and category should default to first category on answer.""" bah_page = BrowsePage(title='Buying a House', slug='owning-a-home') helpers.publish_page(child=bah_page) journey_path = JOURNEY_PATHS[0] journey_page = BrowsePage(title='Journey page', slug=journey_path.strip('/').split('/')[-1]) helpers.save_new_page(journey_page, bah_page) answer = self.answer1234 page = answer.english_page page.category.add(self.category) mock_site = mock.Mock() mock_site.root_page = HomePage.objects.get(slug='cfgov') request = HttpRequest() request.META['HTTP_REFERER'] = \ 'https://www.consumerfinance.gov' + journey_path request.site = mock_site context = page.get_context(request) breadcrumbs = context['breadcrumb_items'] self.assertEqual(len(breadcrumbs), 2) self.assertEqual(breadcrumbs[0]['title'], 'Buying a House') self.assertEqual(breadcrumbs[1]['title'], 'Journey page') self.assertEqual(context['category'], self.category)
def setUp(self): from v1.tests.wagtail_pages.helpers import save_new_page page_stub_30 = MortgagePerformancePage( slug='mortgages-30-89-days-delinquent', title='Mortgage Charts') self.chart_page_30 = save_new_page(page_stub_30).as_page_object() page_stub_90 = MortgagePerformancePage( slug='mortgages-90-days-delinquent', title='Mortgage Maps') self.map_page_90 = save_new_page(page_stub_90).as_page_object()
def setUp(self): self.page = EventPage( title='Super fun event', venue_city='Boston', venue_state='MA' ) save_new_page(self.page) self.migration = import_module( 'v1.migrations.0155_add_venue_coords_to_existing_events' )
def setUp(self): self.page = EventPage(title='Super fun event', start_dt=datetime.now(timezone('UTC')), venue_city='Boston', venue_state='MA') save_new_page(self.page) self.migration = import_module( 'v1.migrations.0155_add_venue_coords_to_existing_events')
def test_get_page_from_content(self): new_page = Page(title='test', slug='foo') save_new_page(new_page, root=self.root) self.assertEqual( get_url_parts_for_site(new_page, self.content), (self.content.id, self.content.root_url, '/foo/') )
def test_page_includes_rss_feed_of_parent(self): parent_page = SublandingFilterablePage(title='test', slug='test') save_new_page(parent_page) child_page = BlogPage(title='test', slug='test') save_new_page(child_page, root=parent_page) response = self.client.get('/test/test/') self.assertContains(response, 'href="/test/feed/')
def test_past_event_with_video_includes_video_js(self): page = EventPage( title='Past event with youtube_url', start_dt=datetime.datetime(2011, 1, 1, tzinfo=pytz.UTC), end_dt=datetime.datetime(2011, 1, 2, tzinfo=pytz.UTC), youtube_url='https://www.youtube.com/embed/Aa1Bb2Cc3Dc4') save_new_page(page) self.assertEqual('past', page.event_state) self.assertIn('video-player.js', page.page_js)
def make_page_with_category(self, category_name): page = AbstractFilterPage(title='test', slug='test') save_new_page(page) category = CFGOVPageCategory.objects.create( name=category_name, page=page ) page.categories.add(category)
def test_render_both_child_and_parent_page_provide_feed(self): parent_page = SublandingFilterablePage(title='test', slug='test') save_new_page(parent_page) child_page = SublandingFilterablePage(title='test', slug='test') save_new_page(child_page, root=parent_page) html = self.render(context={'page': child_page}) self.assertHTMLContainsLinkToPageFeed(html, child_page)
def test_draft_page(self): """Draft page should not load in www""" draft = LandingPage( title='Draft Page', slug='draft', live=False, ) save_new_page(child=draft) www_response = django_client.get('/draft/') self.assertEqual(www_response.status_code, 404)
def setUp(self): self.root = Page.objects.get(slug='cfgov') self.page = StreamPage(title="Test Page", slug="testpage") save_new_page(self.page, self.root) set_stream_data(self.page, 'body', [ {'type': 'text', 'value': 'some text'} ]) self.revision = self.page.save_revision() self.page.save()
def setUp(self): self.request = mock.MagicMock() self.browse_page1 = BrowsePage(title='Browse page 1') self.browse_page2 = BrowsePage(title='Browse page 2') helpers.publish_page(child=self.browse_page1) helpers.publish_page(child=self.browse_page2) self.child_of_browse_page1 = BrowsePage(title='Child of browse page 1') self.child_of_browse_page2 = BrowsePage(title='Child of browse page 2') helpers.save_new_page(self.child_of_browse_page1, self.browse_page1) helpers.save_new_page(self.child_of_browse_page2, self.browse_page2)
def setUp(self): self.site = Site.objects.first() self.root_page = self.site.root_page self.page_with_tags = CFGOVPage(title='Tagged', slug='tagged', live=True) save_new_page(self.page_with_tags, root=self.root_page) self.page_with_tags.tags.add('tag1') self.page_with_tags.authors.add('author1') self.page_with_tags.save()
def test_get_related_activities_url_with_no_topics(self): # Arrange activity_page = self.create_activity_detail_page('Test 2', 'test-2', topic_list=[]) save_new_page(activity_page, self.index_page) # Act actual_url = activity_page.get_related_activities_url() # Assert self.assertEqual(actual_url, '/test-index/?q=&grade_level=2')
def test_has_children_is_false_for_browse_page_with_only_non_browse_children(self): browse_page3 = BrowsePage(title='Browse page 3') helpers.publish_page(child=browse_page3) child_of_browse_page3 = CFGOVPage(title='Non-browse child of browse page') helpers.save_new_page(child_of_browse_page3, browse_page3) nav, has_children = util.get_secondary_nav_items( self.request, browse_page3 ) self.assertEqual(has_children, False)
def test_get_related_activities_url(self): # Arrange activity_page = self.create_activity_detail_page( 'Test', 'test', ) save_new_page(activity_page, self.index_page) # Act actual_url = activity_page.get_related_activities_url() # Assert self.assertEqual(actual_url, '/test-index/?q=&topic=7&grade_level=2')
def make_page_with_grades(self, *grades): page = self.prepare_job_listing_page() save_new_page(page) for grade in grades: panel = GradePanel.objects.create(grade=mommy.make( Grade, grade=str(grade)), job_listing=page) page.grades.add(panel) return page
def test_past_event_with_video_includes_video_js(self): page = EventPage(title='Past event with archive_video_id', start_dt=datetime.datetime(2011, 1, 1, tzinfo=pytz.UTC), end_dt=datetime.datetime(2011, 1, 2, tzinfo=pytz.UTC), archive_video_id='Aa1Bb2Cc3Dc') save_new_page(page) self.assertEqual('past', page.event_state) self.assertIn('video-player.js', page.page_js)
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 test_serve_post_returns_400_for_invalid_form_id_no_form_present(self): page = BrowsePage(title='test', slug='test') page.content = blocks.StreamValue(page.content.stream_block, [{ 'type': 'full_width_text', 'value': [] }], True) save_new_page(page) request = self.factory.post('/', {'form_id': 'form-content-0'}) response = page.serve_post(request) self.assertIsInstance(response, HttpResponseBadRequest)
def make_page_with_grades(self, *grades): page = self.prepare_job_listing_page() save_new_page(page) for grade in grades: panel = GradePanel.objects.create( grade=mommy.make(Grade, grade=str(grade)), job_listing=page ) page.grades.add(panel) return page
def test_forward_mapper_explicit_path_pas_link(self): page = CFGOVPage( title='Privacy Act statement', slug='privacy-act-statement', ) save_new_page(page) data = { 'text': u'Our email newsletter has tips and info to help you ...', 'gd_code': u'USCFPB_127', 'heading': u'Buying a home?', 'form_field': [{ 'info': u'<p><a href="/privacy-act-statement/">PAS</a></p>', 'inline_info': True, 'required': True, 'label': u'Email address', 'btn_text': u'Sign up', 'placeholder': u'*****@*****.**', 'type': u'email' }], 'default_heading': False } migrated = self.migration.forward_mapper('unused param', data) self.assertEqual( migrated, { 'heading': u'Buying a home?', 'default_heading': False, 'text': u'Our email newsletter has tips and info to help you ...', 'gd_code': u'USCFPB_127', 'disclaimer_page': page.pk, 'form_field': [{ 'type': u'email', 'inline_info': True, 'btn_text': u'Sign up', 'info': u'<p><a href="/privacy-act-statement/">PAS</a></p>', 'label': u'Email address', 'required': True, 'placeholder': u'*****@*****.**' }] })
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 test_present_event_with_livestream_includes_video_js(self): page = EventPage(title='Present event with live_stream_date', start_dt=datetime.datetime(2011, 1, 2, tzinfo=pytz.UTC), end_dt=datetime.datetime(2011, 1, 4, tzinfo=pytz.UTC), live_stream_date=datetime.datetime(2011, 1, 2, tzinfo=pytz.UTC)) save_new_page(page) self.assertEqual('present', page.event_state) self.assertIn('video-player.js', page.page_js)
def setUp(self): self.request = mock.MagicMock() self.browse_page1 = BrowsePage(title='Browse page 1') self.browse_page2 = BrowsePage(title='Browse page 2') helpers.publish_page(child=self.browse_page1) helpers.publish_page(child=self.browse_page2) self.child_of_browse_page1 = BrowsePage( title='Child of browse page 1' ) self.child_of_browse_page2 = BrowsePage( title='Child of browse page 2' ) helpers.save_new_page(self.child_of_browse_page1, self.browse_page1) helpers.save_new_page(self.child_of_browse_page2, self.browse_page2)
def test_page_renders_block_safely(self): """ Test to make sure that a page with a jobs list block renders it in a safe way, meaning as raw HTML vs. as a quoted string. """ page = SublandingPage(title='title', slug='slug') save_new_page(page) set_stream_data(page, 'sidebar_breakout', [job_listing_list]) self.assertPageIncludesHtml(page, ( '><aside class="m-jobs-list" data-qa-hook="openings-section">' '.*' '</aside><' ))
def test_page_renders_block_safely(self): """ Test to make sure that a page with a jobs list block renders it in a safe way, meaning as raw HTML vs. as a quoted string. """ page = SublandingPage(title='title', slug='slug') save_new_page(page) set_stream_data(page, 'sidebar_breakout', [job_listing_list]) self.assertPageIncludesHtml( page, ('><aside class="m-jobs-list" data-qa-hook="openings-section">' '.*' '</aside><'))
def test_page_renders_block_safely(self): """ Test to make sure that a page with a jobs list block renders it in a safe way, meaning as raw HTML vs. as a quoted string. """ page = SublandingPage(title='title', slug='slug') save_new_page(page) set_stream_data(page, 'sidebar_breakout', [job_listing_list]) request = RequestFactory().get('/') rendered_html = force_str(page.serve(request).render().content) self.assertInHTML( ('<aside class="m-jobs-list" data-qa-hook="openings-section">' '<h3 class="short-desc">There are no current openings at this ' 'time.</h3></aside>'), rendered_html)
def test_live_draft_page(self): """ Live draft page should not display unpublished content""" live_draft = LandingPage( title='Page Before Updates', slug='page', live=False, ) save_new_page(live_draft).publish() live_draft.title = 'Draft Page Updates' live_draft.save_revision() www_response = django_client.get('/page/') self.assertNotContains(www_response, 'Draft Page Updates') self.assertContains(www_response, 'Page Before Updates')
def test_usajobs_application_link_ordering(self): page = self.prepare_job_listing_page() save_new_page(page) page.usajobs_application_links = [ USAJobsApplicationLink( announcement_number='1', applicant_type=baker.make(ApplicantType, applicant_type='1'), ), USAJobsApplicationLink( announcement_number='2', applicant_type=baker.make(ApplicantType, applicant_type='2'), ), ] result = page.usajobs_application_links.order_by('applicant_type') self.assertEqual(result.first().announcement_number, '1')
def test_save_calls_get_venue_coords(self): api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)') data_json = { 'features': [{ 'geometry': { 'coordinates': ['123.456', '321.654'] } }] } responses.add(responses.GET, api_url_re, json=data_json) page = EventPage(title='Super fun event', venue_city='Boston', venue_state='MA') save_new_page(page) self.assertEqual(page.venue_coords, '123.456,321.654') self.assertIn('static/123.456,321.654', page.location_image_url())
def test_returns_form_block(self): page = BrowsePage(title='test', slug='test') revision = save_new_page(page) registration_form_block = atomic.conference_registration_form set_stream_data(page, 'content', [registration_form_block]) self.assertEqual(get_registration_form_from_page(revision.page_id), registration_form_block)
def test_page_renders_block_safely(self): """ Test to make sure that a page with a jobs list block renders it in a safe way, meaning as raw HTML vs. as a quoted string. """ page = SublandingPage(title='title', slug='slug') save_new_page(page) set_stream_data(page, 'sidebar_breakout', [job_listing_list]) request = RequestFactory().get('/') request.user = Mock() rendered_html = force_text(page.serve(request).render().content) self.assertInHTML( ('<aside class="m-jobs-list" data-qa-hook="openings-section">' '<h3 class="short-desc">There are no current openings at this ' 'time.</h3></aside>'), rendered_html )
def test_forward_mapper_explicit_path_pas_link(self): page = CFGOVPage( title='Privacy Act statement', slug='privacy-act-statement', ) save_new_page(page) data = { 'text': u'Our email newsletter has tips and info to help you ...', 'gd_code': u'USCFPB_127', 'heading': u'Buying a home?', 'form_field': [{ 'info': u'<p><a href="/privacy-act-statement/">PAS</a></p>', 'inline_info': True, 'required': True, 'label': u'Email address', 'btn_text': u'Sign up', 'placeholder': u'*****@*****.**', 'type': u'email' }], 'default_heading': False } migrated = self.migration.forward_mapper( 'unused param', data ) self.assertEqual(migrated, { 'heading': u'Buying a home?', 'default_heading': False, 'text': u'Our email newsletter has tips and info to help you ...', 'gd_code': u'USCFPB_127', 'disclaimer_page': page.pk, 'form_field': [{ 'type': u'email', 'inline_info': True, 'btn_text': u'Sign up', 'info': u'<p><a href="/privacy-act-statement/">PAS</a></p>', 'label': u'Email address', 'required': True, 'placeholder': u'*****@*****.**' }] })
def test_returns_form_block(self): page = BrowsePage(title='test', slug='test') revision = save_new_page(page) registration_form_block = atomic.conference_registration_form set_stream_data(page, 'content', [registration_form_block]) self.assertEqual( get_registration_form_from_page(revision.page_id), registration_form_block )
def setUp(self): self.page = mock.Mock() self.request = mock.Mock() self.page_versions = [ mock.Mock(**{'content_json': {'live': False, 'shared': False}}), # draft mock.Mock(**{'content_json': {'live': False, 'shared': True}}), # shared mock.Mock(**{'content_json': {'live': True, 'shared': False}}), # live mock.Mock(**{'content_json': {'live': True, 'shared': True}}), # live and shared ] self.page.revisions.all().order_by.return_value = self.page_versions self.new_page = CFGOVPage(title='a cfgov page') self.new_page.live = False self.new_page.shared = False helpers.save_new_page(self.new_page) content_json = json.loads(self.new_page.to_json()) # create the various page revisions # revision 1 content_json['title'] = 'revision 1' content_json['live'] = True content_json['shared'] = True self.revision_1 = self.new_page.revisions.create(content_json=json.dumps(content_json)) # rev 2 content_json['title'] = 'revision 2' content_json['live'] = True content_json['shared'] = False self.revision_2 = self.new_page.revisions.create(content_json=json.dumps(content_json)) # rev 3 content_json['title'] = 'revision 3' content_json['live'] = False content_json['shared'] = True self.revision_3 = self.new_page.revisions.create(content_json=json.dumps(content_json)) # rev 4 content_json['title'] = 'revision 4' content_json['live'] = False content_json['shared'] = False self.revision_4 = self.new_page.revisions.create(content_json=json.dumps(content_json))
def make_page_with_form(code='TEST_CODE', capacity=999): page = BrowsePage(title='test', slug='test') revision = save_new_page(page) block = atomic.conference_registration_form.copy() block['value'].update({ 'code': code, 'capacity': capacity, }) set_stream_data(page, 'content', [block]) return revision.page_id
def run(): default_site = Site.objects.get(is_default_site=True) root_page = default_site.root_page try: about_us = Page.objects.get(slug='about-us') except Page.DoesNotExist: logger.info('Creating page: About Us') about_us = LandingPage(title='About Us', slug='about-us', live=False) save_new_page(about_us, root=root_page) try: careers = Page.objects.get(slug='careers') except Page.DoesNotExist: logger.info('Creating page: Careers') careers = SublandingPage(title='Careers', slug='careers', live=False) save_new_page(careers, root=about_us) child_pages = [ ('Working at the CFPB', 'working-at-cfpb'), ('Job Application Process', 'application-process'), ('Students and Graduates', 'students-and-graduates'), ('Current Openings', 'current-openings'), ] for title, slug in child_pages: try: child_page = Page.objects.get(slug=slug) except Page.DoesNotExist: logger.info('Creating page: {}'.format(title)) child_page = BrowsePage(title=title, slug=slug, live=False) save_new_page(child_page, careers)
def test_save_calls_get_venue_coords(self): api_url_re = re.compile('https://api.mapbox.com/geocoding/(.*)') data_json = { 'features': [{ 'geometry': { 'coordinates': [ '123.456', '321.654' ] } }] } responses.add(responses.GET, api_url_re, json=data_json) page = EventPage( title='Super fun event', venue_city='Boston', venue_state='MA' ) save_new_page(page) self.assertEqual(page.venue_coords, '123.456,321.654') self.assertIn('static/123.456,321.654', page.location_image_url())
def setUp(self): """ Create a new page, a User, and a couple of mock objects that simulate the context and request. There are also a couple of side effect functions for accessing the mocks as dictionaries. Also an object that is not a page and doesn't do anything, but has a `.specific` member variable. """ self.page = CFGOVPage(title='a very nice cfgov page') self.page.shared = False self.page.live = False self.not_a_page = mock.MagicMock() self.not_a_page.specific = mock.MagicMock() helpers.save_new_page(self.page) self.user = User(first_name='A', last_name='User') self.user.save() self.context = mock.MagicMock() self.request = mock.MagicMock() self.context_dict = {} def context_getitem(name): return self.context_dict[name] def context_setitem(name, value): self.context_dict[name] = value self.context.__getitem__.side_effect = context_getitem self.context.__setitem__.side_effect = context_setitem self.request.user = self.user self.site_objects = Site.objects.all()
def test_serve_post_valid_calls_feedback_block_handler(self): """A valid post should call the feedback block handler. This returns a redirect to the calling page and also uses the Django messages framework to set a message. """ page = BrowsePage(title='test', slug='test') page.content = blocks.StreamValue( page.content.stream_block, [{'type': 'feedback', 'value': 'something'}], True ) save_new_page(page) request = self.factory.post('/', {'form_id': 'form-content-0'}) SessionMiddleware().process_request(request) MessageMiddleware().process_request(request) response = page.serve_post(request) self.assertEqual( (response.status_code, response['Location']), (302, request.path) )
def test_live_shared_with_another_live_page(self): page = CFGOVPage(title='test', slug='test', live=True, shared=False) save_new_page(page) self.check_live_shared_counts(on_live_host=2, on_staging_host=2)
def test_no_root_returns_correctly(self): page = CFGOVPage(title='Test page') helpers.save_new_page(page) self.assertEqual(util.get_page_from_path('/test-page/'), page)
def test_with_root_returns_correctly(self): page = CFGOVPage(title='Test page 2') helpers.save_new_page(page) root = HomePage.objects.get(title='CFGov') self.assertEqual(util.get_page_from_path('/test-page-2/', root), page)