def test_basepage_can_exist_under(root_page): page = IndustryPageFactory(parent=root_page) assert isinstance(page, BasePage) dummy_ctype = ContentType.objects.create(app_label='blah', model='blah') test_parent = Page(slug='basic', title='Page') test_parent.content_type = dummy_ctype assert page.can_exist_under(test_parent) is False
def translated_fas_industry_page(settings, fas_industry_landing_page): page = IndustryPageFactory( parent=fas_industry_landing_page, title_en_gb='ENGLISH', title_de='GERMAN', title_ja='JAPANESE', title_zh_hans='SIMPLIFIED CHINESE', title_fr='FRENCH', title_es='SPANISH', title_pt='PORTUGUESE', title_pt_br='BRAZILIAN', title_ar='ARABIC', breadcrumbs_label_en_gb='label', introduction_text_en_gb='lede', search_description_en_gb='description', hero_text_en_gb='hero text', introduction_column_one_text_en_gb='lede column one', introduction_column_two_text_en_gb='lede column two', introduction_column_three_text_en_gb='lede column three', company_list_call_to_action_text_en_gb='view all', company_list_text_en_gb='the title', search_filter_sector=['FOOD_AND_DRINK'], ) field_names = page.get_required_translatable_fields() language_codes = settings.LANGUAGES for field_name, (language_code, _) in product(field_names, language_codes): localized_name = build_localized_fieldname(field_name, language_code) if not getattr(page, localized_name): setattr(page, localized_name, localized_name + '-v') page.save() return page
def test_get_site_returns_none_when_page_not_routable( root_page, django_assert_num_queries ): Site.objects.all().delete() # ensures pages are not routable page = IndustryPageFactory(parent=root_page, slug='industry') result = page.get_site() assert result is None
def test_delete_same_slug_different_services(root_page): page_one = IndustryPageFactory(slug='foo', parent=root_page) page_two = SectorPageFactory(slug='foo', parent=root_page) assert page_one.slug == 'foo' assert page_two.slug == 'foo' page_one.delete() assert Page.objects.filter(pk=page_one.pk).exists() is False
def test_page_paths(root_page): invest_app = InvestAppFactory(parent=root_page) invest_page_one = SectorLandingPageFactory(parent=invest_app) invest_page_two = SectorPageFactory(slug='foo', parent=invest_page_one) invest_page_three = SectorPageFactory(slug='bar', parent=invest_page_two) assert invest_page_two.full_path == '/industries/foo/' assert invest_page_three.full_path == '/industries/foo/bar/' fas_app = FindASupplierAppFactory(parent=root_page) fas_industry_landing_page = IndustryLandingPageFactory(parent=fas_app) fas_industry_one = IndustryPageFactory( slug='foo', parent=fas_industry_landing_page) fas_industry_two = IndustryPageFactory( slug='bar', parent=fas_industry_landing_page) fas_industry_article = IndustryArticlePageFactory( slug='article', parent=fas_industry_two) assert fas_industry_one.full_path == '/industries/foo/' assert fas_industry_two.full_path == '/industries/bar/' assert fas_industry_article.full_path == '/industry-articles/article/' domestic_homepage = HomePageFactory(parent=root_page) domestic_page_one = TopicLandingPageFactory( parent=domestic_homepage, slug='topic') domestic_page_two = ArticleListingPageFactory( parent=domestic_page_one, slug='list') domestic_page_three = ArticlePageFactory( parent=domestic_page_two, slug='article') assert domestic_page_two.full_path == '/topic/list/' assert domestic_page_three.full_path == '/topic/list/article/' domestice_site_policy = SitePolicyPagesFactory(parent=domestic_homepage) domestic_cookies_one = PrivacyAndCookiesPageFactory( slug='privacy', parent=domestice_site_policy) domestic_cookies_two = PrivacyAndCookiesPageFactory( slug='cookies', parent=domestic_cookies_one) assert domestic_cookies_one.full_path == '/privacy/' assert domestic_cookies_two.full_path == '/privacy/cookies/' international_homepage = InternationalHomePageFactory(parent=root_page) international_page_one = InternationalTopicLandingPageFactory( parent=international_homepage, slug='topic') international_page_two = InternationalArticleListingPageFactory( parent=international_page_one, slug='list') international_page_three = InternationalArticlePageFactory( parent=international_page_two, slug='article') assert international_page_two.full_path == '/topic/list/' assert international_page_three.full_path == '/topic/list/article/'
def test_delete_same_slug_different_services(root_page): """ Deleting a page results in ancestor pages being re-saved. Thus ancestor page (root_page) has to have title & title_en_gb. """ root_page.title = 'ancestor page has to have a title' root_page.title_en_gb = 'ancestor page has to have a title' root_page.save() page_one = IndustryPageFactory(slug='foo', parent=root_page) page_two = SectorPageFactory(slug='foo', parent=root_page) assert page_one.slug == 'foo' assert page_two.slug == 'foo' page_one.delete() assert Page.objects.filter(pk=page_one.pk).exists() is False
def test_get_site_creates_routing_settings_if_none_exist( root_page, django_assert_num_queries ): page = IndustryPageFactory(parent=root_page, slug='industry') site = Site.objects.create(hostname='example.gov', root_page=page) # running this first so that the query doesn't count toward # the total query count (the value is usually cached) page._get_site_root_paths() with django_assert_num_queries(2): # 1 query to get the site, 1 to create routing settings result_site = page.get_site() # Check the correct site was returned assert result_site == site # This attribute is set to reference the newly created object, # so this shouldn't result in another query result_site.routingsettings
def untranslated_page(root_page): return IndustryPageFactory( parent=root_page, title_en_gb='ENGLISH', breadcrumbs_label_en_gb='label', introduction_text_en_gb='lede', search_description_en_gb='description', hero_text_en_gb='hero text', introduction_column_one_text_en_gb='lede column one', introduction_column_two_text_en_gb='lede column two', introduction_column_three_text_en_gb='lede column three', company_list_text_en_gb='companies', company_list_call_to_action_text_en_gb='view all', )
def test_meta_field(rf, root_page): fas_industry_page = IndustryPageFactory( parent=root_page, slug='test-slug', ) serializer = IndustryPageSerializer(instance=fas_industry_page, context={'request': rf.get('/')}) assert serializer.data['meta'] == { 'draft_token': None, 'languages': [('en-gb', 'English')], 'url': 'http://supplier.trade.great:8005/test-slug/', 'localised_urls': [('en-gb', 'http://supplier.trade.great:8005/test-slug/')], 'slug': 'test-slug', 'pk': fas_industry_page.pk }
def test_breadcrumbs_field(page, rf): IndustryLandingPageFactory(breadcrumbs_label_en_gb='label-one') IndustryPageFactory(breadcrumbs_label_en_gb='label-two') LandingPageFactory(breadcrumbs_label_en_gb='label-three') IndustryContactPageFactory(breadcrumbs_label_en_gb='label-four') serializer = IndustryPageSerializer(instance=page, context={'request': rf.get('/')}) assert serializer.data['breadcrumbs'] == { 'industrylandingpage': { 'slug': 'industries-landing-page', 'label': 'label-one' }, 'industrycontactpage': { 'slug': 'industry-contact', 'label': 'label-four' }, 'landingpage': { 'slug': 'landing-page', 'label': 'label-three' } }
def page(root_page): return IndustryPageFactory(parent=root_page, slug='the-slug')
def test_slugs_are_not_unique_across_services(root_page): page_one = IndustryPageFactory(slug='foo', parent=root_page) page_two = SectorPageFactory(slug='foo', parent=root_page) assert page_one.slug == 'foo' assert page_two.slug == 'foo'
def test_slugs_are_unique_in_the_same_service(): IndustryPageFactory(slug='foo') with pytest.raises(ValidationError) as excinfo: IndustryPageFactory(slug='foo') assert 'This slug is already in use' in str(excinfo.value)