Ejemplo n.º 1
0
def test_cms_guidance_descriptive_page_title_is_rendered(rf):
    context = urls_processor(None)

    context['request'] = rf.get('/')
    page = {
        'title': 'Descriptive text',
    }

    context['page'] = page
    context.update(urls_processor(None))
    html = render_to_string('contact/guidance.html', context)

    assert page['title'] + ' - great.gov.uk' in html
Ejemplo n.º 2
0
def test_marketing_article_detail_content_button_not_rendered_without_link(rf):
    context = urls_processor(None)
    page = {
        "title": "Test article admin title",
        "article_title": "Test article",
        "article_teaser": "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text": "<p>Lorem ipsum</p>",
        "cta_title": 'CTA title',
        "cta_teaser": 'CTA teaser text',
        "cta_link_label": "CTA link label",
        "cta_link": "",
        "last_published_at": "2018-10-09T16:25:13.142357Z",
        "meta": {
            "slug": "bar",
        },
        "page_type": "MarketingArticlePage",
    }

    context['request'] = rf.get('/')
    context['page'] = page

    html = render_to_string('content/marketing_article_detail.html', context)

    assert 'class="button button-arrow-small"' not in html
Ejemplo n.º 3
0
def test_404_links(settings):
    """Test 404 page has links to home and contact-us."""
    context = context_processors.urls_processor(None)
    html = render_to_string('404.html', context)

    assert urls.domestic.HOME in html
    assert urls.domestic.CONTACT_US in html
Ejemplo n.º 4
0
def test_article_detail_page_related_content(rf):
    context = urls_processor(None)
    context['request'] = rf.get('/')
    page = {
        "title":
        "Test article admin title",
        "article_title":
        "Test article",
        "article_teaser":
        "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text":
        "<p>Lorem ipsum</p>",
        "cta_title":
        'CTA title',
        "cta_teaser":
        'CTA teaser text',
        "cta_link_label":
        "CTA link label",
        "cta_link":
        "http://www.great.gov.uk",
        "last_published_at":
        "2018-10-09T16:25:13.142357Z",
        "meta": {
            "slug": "bar",
        },
        "related_pages": [
            {
                "article_title": "Related article 1",
                "full_path": "/markets/test/test-one",
                "meta": {
                    "slug": "test-one",
                }
            },
            {
                "article_title": "Related article 2",
                "full_path": "/markets/test/test-two",
                "meta": {
                    "slug": "test-two",
                }
            },
        ],
        "page_type":
        "ArticlePage",
    }
    context['page'] = page
    html = render_to_string('content/article_detail.html', context)
    soup = BeautifulSoup(html, 'html.parser')

    assert 'Related content' in html
    assert soup.find(id='related-content').select(
        'li a')[0].attrs['href'] == '/markets/test/test-one'
    assert soup.find(
        id='related-content').select('li a')[0].text == 'Related article 1'
    assert soup.find(id='related-content').select(
        'li a')[1].attrs['href'] == '/markets/test/test-two'
    assert soup.find(
        id='related-content').select('li a')[1].text == 'Related article 2'
Ejemplo n.º 5
0
def test_marketing_article_detail_page_related_content_not_rendered(rf):
    context = urls_processor(None)
    page = {
        "title": "Test article admin title",
        "article_title": "Test article",
        "article_teaser": "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text": "<p>Lorem ipsum</p>",
        "cta_title": '',
        "cta_teaser": '',
        "cta_link_label": "",
        "cta_link": "",
        "last_published_at": "2018-10-09T16:25:13.142357Z",
        "meta": {
            "slug": "bar",
        },
        "page_type": "MarketingArticlePage",
    }

    context['request'] = rf.get('/')
    context['page'] = page

    html = render_to_string('content/marketing_article_detail.html', context)

    assert '<section id="contact-us-section"' not in html
Ejemplo n.º 6
0
def test_market_landing_pagination_page_next_not_in_html(rf):
    context = urls_processor(None)
    page_size = 18
    child_page = {'title': 'Title', 'sub_heading': 'Markets subheading'}
    page = {
        'title':
        'test',
        'page_type':
        'TopicLandingPage',
        'tree_based_breadcrumbs': [
            {
                'url': '/markets/',
                'title': 'Markets'
            },
            {
                'url': '/markets/japan/',
                'title': 'Japan'
            },
        ],
        'child_pages': [
            child_page, child_page, child_page, child_page, child_page,
            child_page, child_page, child_page, child_page, child_page
        ]
    }

    paginator = Paginator(page['child_pages'], page_size)
    pagination_page = paginator.page(1)
    context['request'] = rf.get('/')
    context['pagination_page'] = pagination_page

    html = render_to_string('content/markets_landing_page.html', context)

    assert 'pagination-next' not in html
Ejemplo n.º 7
0
def test_404_links(settings):
    """Test 404 page has links to home and contact-us."""
    context = urls_processor(None)
    html = render_to_string('404.html', context)

    assert urls.SERVICES_GREAT_DOMESTIC in html
    assert urls.CONTACT_US in html
Ejemplo n.º 8
0
def test_country_guide_complete_intro_ctas(dummy_cms_page, rf):
    context = urls_processor(None)
    context['page'] = dummy_cms_page
    context['request'] = rf.get('/')

    intro_ctas = [
        {
            'title': 'title 1',
            'link': 'link 1',
        },
        {
            'title': 'title 2',
            'link': 'link 2',
        },
        {
            'title': 'title 3',
            'link': 'link 3',
        },
    ]

    context['page']['heading_teaser'] = 'Teaser'
    context['page']['intro_ctas'] = intro_ctas

    html = render_to_string('content/country_guide.html', context)
    soup = BeautifulSoup(html, 'html.parser')
    ctas = soup.select('#country-guide-teaser-section .intro-cta-link')

    assert len(ctas) == 3
Ejemplo n.º 9
0
 def get_context_data(self):
     return {
         **self.cleaned_data,
         **urls_processor(None),
         **header_footer_processor(None),
         'recipient_name': self.recipient_name,
     }
Ejemplo n.º 10
0
def test_marketing_article_detail_page_related_content(rf):
    context = urls_processor(None)
    page = {
        "title": "Test article admin title",
        "article_title": "Test article",
        "article_teaser": "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text": "<p>Lorem ipsum</p>",
        "cta_title": 'CTA title',
        "cta_teaser": 'CTA teaser text',
        "cta_link_label": "CTA link label",
        "cta_link": "http://www.great.gov.uk",
        "last_published_at": "2018-10-09T16:25:13.142357Z",
        "meta": {
            "slug": "bar",
        },
        "page_type": "MarketingArticlePage",
    }
    context['request'] = rf.get('/')
    context['page'] = page
    html = render_to_string('content/marketing_article_detail.html', context)

    soup = BeautifulSoup(html, 'html.parser')
    assert soup.find(
        id='contact-us-section').select('h2')[0].text == 'CTA title'
    assert soup.find(
        id='contact-us-section').select('p')[0].text == 'CTA teaser text'
    assert soup.find(id='contact-us-section').select(
        'a.button')[0].attrs['href'] == 'http://www.great.gov.uk'
Ejemplo n.º 11
0
def test_case_study_soo_link(settings):
    context = urls_processor(None)
    context['casestudy'] = casestudies.HELLO_BABY
    html = render_to_string('casestudy/hello-baby.html', context)
    soup = BeautifulSoup(html, 'html.parser')
    soo_link = soup.find(string='Selling online overseas service').parent

    assert soo_link.attrs['href'] == urls.domestic.SELLING_OVERSEAS
Ejemplo n.º 12
0
def test_get_finance_template():
    context = urls_processor(None)
    html = render_to_string('finance/trade_finance.html', context)

    expected = reverse('uk-export-finance-lead-generation-form',
                       kwargs={'step': 'contact'})

    assert expected in html
def test_urls_exist_in_domestic_footer(url, settings):
    context = {
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None),
        **context_processors.feature_flags(None),
    }
    template_name = ('directory_components/header_footer/domestic_footer.html')
    assert url in render_to_string(template_name, context)
Ejemplo n.º 14
0
def test_article_list_page():
    context = urls_processor(None)
    context['page'] = test_list_page

    html = render_to_string('content/article_list.html', context)

    assert test_list_page['title'] in html

    assert '01 October' in html
    assert '02 October' in html
def test_urls_exist_in_domestic_header(url, settings):
    context = {
        'features': {
            'NEWS_SECTION_ON': True
        },
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None)
    }
    template_name = ('directory_components/header_footer/domestic_header.html')
    assert url in render_to_string(template_name, context)
Ejemplo n.º 16
0
def test_news_list_page_feature_flag_on():
    context = urls_processor(None)
    context['features'] = {'NEWS_SECTION_ON': True}
    context['page'] = test_news_list_page

    html = render_to_string('content/domestic_news_list.html', context)

    assert test_news_list_page['title'] in html
    assert 'Lorem ipsum' in html
    assert 'Dolor sit amet' in html
def test_header_international_news_section_off(settings):
    context = {
        'features': {
            'NEWS_SECTION_ON': False
        },
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None)
    }
    template_name = 'directory_components/header_footer/domestic_header.html'
    html = render_to_string(template_name, context)
    assert urls.GREAT_INTERNATIONAL_NEWS not in html
Ejemplo n.º 18
0
def test_landing_page_header_footer(rf):
    context = urls_processor(None)
    context['request'] = rf.get('/')

    html = render_to_string('core/landing_page.html', context)

    assert '/static/js/home' in html

    soup = BeautifulSoup(html, 'html.parser')

    assert soup.find(id="great-global-header-logo")
def test_urls_exist_in_international_header(url, settings):
    context = {
        'features': {
            'NEWS_SECTION_ON': True,
            'HOW_TO_DO_BUSINESS_ON': True,
        },
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None)
    }
    template_name = (
        'directory_components/header_footer/international_header.html')
    assert url in render_to_string(template_name, context)
Ejemplo n.º 20
0
def test_country_guide_no_intro_ctas(dummy_cms_page, rf):
    context = urls_processor(None)
    context['page'] = dummy_cms_page
    context['request'] = rf.get('/')

    context['page']['heading_teaser'] = 'Teaser'

    html = render_to_string('content/country_guide.html', context)
    soup = BeautifulSoup(html, 'html.parser')
    ctas = soup.select('#country-guide-teaser-section .intro-cta-link')

    assert len(ctas) == 0
Ejemplo n.º 21
0
def test_country_guide_no_industries(dummy_cms_page, rf):
    context = urls_processor(None)
    context['page'] = dummy_cms_page
    context['request'] = rf.get('/')

    context['page']['accordions'] = []
    context['page']['section_two_heading'] = 'Heading'

    html = render_to_string('content/country_guide.html', context)
    soup = BeautifulSoup(html, 'html.parser')

    assert soup.find(id='country-guide-section-two')
    assert not soup.find(id='country-guide-accordions')
Ejemplo n.º 22
0
def test_tag_list_page():
    context = urls_processor(None)
    page = {
        'name': 'New to exporting',
        'articles': test_articles,
    }
    context['page'] = page
    html = render_to_string('content/tag_list.html', context)

    assert '01 October' in html
    assert '02 October' in html
    assert 'Article 1 title' in html
    assert 'Article 2 title' in html
    assert 'Articles with tag: New to exporting' in html
Ejemplo n.º 23
0
def test_article_detail_page_media_rendered(rf):
    context = urls_processor(None)
    context['request'] = rf.get('/')
    page = {"article_video": {"url": "test.mp4", "file_extension": "mp4"}}

    context['page'] = page

    html = render_to_string('content/article_detail.html', context)

    soup = BeautifulSoup(html, 'html.parser')
    src = soup.find(id='article-video').select('source')[0]

    assert '<div class="video-container">' in html
    assert src.attrs['src'] == 'test.mp4'
    assert src.attrs['type'] == 'video/mp4'
def test_domestic_footer_ids_match_urls_and_text(title, element_id, url,
                                                 settings):
    context = {
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None),
        **context_processors.feature_flags(None),
    }
    html = render_to_string(
        'directory_components/header_footer/domestic_footer.html', context)
    soup = BeautifulSoup(html, 'html.parser')

    element = soup.find(id=element_id)
    assert element.attrs['href'] == url
    if title:
        assert element.string == title
Ejemplo n.º 25
0
def test_article_advice_page():
    context = urls_processor(None)
    page = {
        'title':
        'Markets',
        'hero_image': {
            'url': 'markets.jpg'
        },
        'child_pages': [{
            'title': 'Africa market information',
            'full_path': '/markets/africa/',
            'hero_image': {
                'url': 'africa.png'
            },
            'hero_image_thumbnail': {
                'url': 'africa.jpg'
            },
            'articles_count': 0,
        }, {
            'title': 'Asia market information',
            'full_path': '/markets/asia/',
            'hero_image': {
                'url': 'asia.png'
            },
            'hero_image_thumbnail': {
                'url': 'asia.jpg'
            },
            'articles_count': 3,
        }],
        "page_type":
        "TopicLandingPage",
    }

    context['page'] = page

    html = render_to_string('content/topic_list.html', context)

    assert page['title'] in html

    assert 'Asia market information' in html
    assert 'Africa market information' in html
    assert 'markets.jpg' in html
    assert 'asia.jpg' in html
    assert 'africa.jpg' in html
Ejemplo n.º 26
0
def test_country_guide_add_href_target(dummy_cms_page, rf):
    context = urls_processor(None)
    request = rf.get('/')
    request.META['HTTP_HOST'] = 'example.com'

    context['page'] = dummy_cms_page
    context['request'] = request

    context['page'][
        'section_one_body'] = '<a href="http://www.google.co.uk">Here is an external link</a>'

    html = render_to_string('content/country_guide.html', context)
    soup = BeautifulSoup(html, 'html.parser')
    links = soup.select('#country-guide-section-one a')

    assert len(links) == 1
    assert links[0].attrs['title'] == 'Opens in a new window'
    assert links[0].attrs['target'] == '_blank'
    assert links[0].attrs['rel'] == ['noopener', 'noreferrer']
def test_international_header_ids_match_urls_and_text(title, element_id, url,
                                                      settings):
    context = {
        'features': {
            'NEWS_SECTION_ON': True,
            'HOW_TO_DO_BUSINESS_ON': True
        },
        **context_processors.header_footer_processor(None),
        **context_processors.urls_processor(None),
    }

    html = render_to_string(
        'directory_components/header_footer/international_header.html',
        context)
    soup = BeautifulSoup(html, 'html.parser')

    element = soup.find(id=element_id)

    assert element.attrs['href'] == url
    if title:
        assert element.string == title
Ejemplo n.º 28
0
def test_country_guide_fact_sheet_displays_if_given_title(rf):
    context = urls_processor(None)
    context['request'] = rf.get('/')
    page = {
        'title': 'test',
        'page_type': 'CountryGuidePage',
        'heading': 'Heading',
        'statistics': [],
        'accordions': [],
        'fact_sheet': {
            'fact_sheet_title': 'Fact sheet title',
            'columns': []
        }
    }
    context['page'] = page

    html = render_to_string('content/country_guide.html', context)
    soup = BeautifulSoup(html, 'html.parser')

    assert soup.find(id='country-guide-section-three')
    assert 'Fact sheet title' in html
Ejemplo n.º 29
0
def test_article_detail_page_media_not_rendered(rf):
    context = urls_processor(None)
    context['request'] = rf.get('/')
    page = {
        "title": "Test article admin title",
        "article_title": "Test article",
        "article_teaser": "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text": "<p>Lorem ipsum</p>",
        "cta_title": 'CTA title',
        "cta_teaser": 'CTA teaser text',
        "cta_link_label": "CTA link label",
        "cta_link": "http://www.great.gov.uk",
        "last_published_at": "2018-10-09T16:25:13.142357Z",
    }

    context['page'] = page

    html = render_to_string('content/article_detail.html', context)

    assert '<div class="video-container">' not in html
Ejemplo n.º 30
0
def test_article_detail_page_no_related_content(rf):
    context = urls_processor(None)
    page = {
        "title": "Test article admin title",
        "article_title": "Test article",
        "article_teaser": "Test teaser",
        "article_image": {
            "url": "foobar.png"
        },
        "article_body_text": "<p>Lorem ipsum</p>",
        "related_pages": [],
        "full_path": "/advice/manage-legal-and-ethical-compliance/foo/",
        "last_published_at": "2018-10-09T16:25:13.142357Z",
        "meta": {
            "slug": "foo",
        },
        "page_type": "ArticlePage",
    }
    context['request'] = rf.get('/')
    context['page'] = page

    html = render_to_string('content/article_detail.html', context)
    assert 'Related content' not in html