def test_showing_accordions_null_case_for_region_page(mock_cms_response, rf):

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type': 'CapitalInvestRegionPage',
        'economics_stats': [],
        'location_stats': [],
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/midlands/')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/midlands/')

    assert response.context_data['show_accordions'] is False
def test_when_no_opportunity_list_in_page_for_opportunity_search(
        mock_cms_response, rf):

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ],
            'slug':
            'opportunities'
        },
        'page_type': 'CapitalInvestOpportunityListingPage',
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/opportunities/')  # NOQA
    request.LANGUAGE_CODE = 'en-gb'
    response = OpportunitySearchView.as_view()(
        request, path='/international/content/opportunities/')  # NOQA

    assert response.context_data['num_of_opportunities'] == 0
Esempio n. 3
0
def test_get_cms_page_kwargs_slug(mock_cms_response, rf):
    class TestView(GetSlugFromKwargsMixin, CMSPageMixin, TemplateView):
        template_name = 'core/base.html'
        active_view_name = ''

    page = {
        'title': 'the page',
        'meta': {
            'languages': [('en-gb', 'English'), ('de', 'German')],
            'slug': 'aerospace'
        },
        'page_type': ''
    }

    mock_cms_response.return_value = helpers.create_response(
            status_code=200,
            json_payload=page
        )

    translation.activate('en-gb')
    request = rf.get('/')
    view = TestView.as_view()
    response = view(request, slug='aerospace')

    assert response.context_data['page'] == page
Esempio n. 4
0
def test_landing_page_cms_component(mock_get_page, mock_get_component, client,
                                    settings):
    settings.FEATURE_FLAGS = {
        **settings.FEATURE_FLAGS,
        'EU_EXIT_BANNER_ON': True,
    }
    mock_get_page.return_value = {
        'title': 'the page',
        'sectors': [],
        'guides': [],
        'high_potential_opportunities': [],
        'featured_cards': [],
        'meta': {
            'languages': [('en-gb', 'English')]
        },
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200,
        json_payload={
            'banner_label': 'EU Exit updates',
            'banner_content': '<p>Lorem ipsum.</p>',
            'meta': {
                'languages': [('en-gb', 'English')]
            },
        })

    url = reverse('index')
    response = client.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')

    assert soup.select('.banner-container')[0].get('dir') == 'ltr'
    assert response.template_name == ['core/landing_page.html']
    assert 'EU Exit updates' in str(response.content)
    assert '<p class="body-text">Lorem ipsum.</p>' in str(response.content)
Esempio n. 5
0
def test_get_sector_page_attaches_array_lengths_to_view(mock_cms_response, rf):

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type': 'InternationalSectorPage',
        'statistics': [
            {'number': '1'},
            {'number': '2', 'heading': 'heading'},
            {'number': None, 'heading': 'no-number-stat'}
        ],
        'section_three_subsections': [
            {'heading': 'heading'},
            {'heading': 'heading-with-teaser', 'teaser': 'teaser'},
            {'heading': None, 'teaser': 'teaser-without-heading'}
        ]
    }

    mock_cms_response.return_value = helpers.create_response(
        status_code=200,
        json_payload=page
    )

    request = rf.get('/')
    response = SectorPageCMSView.as_view()(request)

    view = response.context_data['view']
    assert view.num_of_statistics == 2
    assert view.section_three_num_of_subsections == 2
Esempio n. 6
0
def test_localised_urls(mock_get_page, mock_get_component, client):
    mock_get_page.return_value = {
        'title': 'test',
        'sectors': [],
        'guides': [],
        'high_potential_opportunities': [],
        'featured_cards': [],
        'meta': {
            'languages': [
                ('en-gb', 'English'),
                ('fr', 'Français'),
                ('de', 'Deutsch'),
                ['ja', '日本語'],
            ]
        }
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200,
        json_payload={
            'banner_label': 'EU Exit updates',
            'banner_content': '<p>Lorem ipsum.</p>',
            'meta': {
                'languages': [('en-gb', 'English')]
            }
        })

    translation.activate('de')
    url = reverse('index')
    response = client.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')

    assert not soup.select('link[hreflang="de"]')
    assert soup.select('link[hreflang="fr"]')
    assert soup.select('link[hreflang="ja"]')
    assert soup.select('link[hreflang="en-gb"]')
Esempio n. 7
0
def test_show_featured_cards_section_doesnt_show_when_not_all_there(
        mock_get_page, mock_get_component, client):
    mock_get_page.return_value = {
        'title':
        'the page',
        'featured_cards': [
            {
                'title': '',
                'image': {},
                'summary': 'A summary',
            },
            {
                'title': 'Get started in the UK',
                'image': {},
                'summary': 'A summary',
                'cta_link': 'www.google.com'
            },
            {
                'title': 'Get started in the UK',
                'image': {},
                'summary': '',
            },
        ],
        'high_potential_opportunities': [],
        'meta': {
            'languages': [('en-gb', 'English')]
        },
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    url = reverse('index')
    response = client.get(url)

    assert response.context_data['show_featured_cards'] is False
def test_get_random_three_opportunities_for_sub_sector_page_null_case(
        mock_cms_response, rf):

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
            ],
            'slug': 'sector'
        },
        'page_type': 'InternationalSubSectorPage',
        'statistics': [],
        'section_three_subsections': []
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/industries/sector/sub_sector')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/industries/sector/sub_sector')

    assert len(response.context_data['random_opportunities']) == 0
def test_google_campaign_middleware(mock_lookup_by_path, client):
    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type': 'InternationalHomePage'
    }

    mock_lookup_by_path.return_value = helpers.create_response(
        status_code=200, json_payload=page)
    url = reverse('index')
    client.get(
        url, {
            'utm_source': 'test_source',
            'utm_medium': 'test_medium',
            'utm_campaign': 'test_campaign',
            'utm_term': 'test_term',
            'utm_content': 'test_content'
        })

    correct_utm = {
        'utm_source': 'test_source',
        'utm_medium': 'test_medium',
        'utm_campaign': 'test_campaign',
        'utm_term': 'test_term',
        'utm_content': 'test_content'
    }

    assert 'utm' in client.session
    assert client.session['utm'] == correct_utm
Esempio n. 10
0
def test_show_hpo_section(mock_get_page, mock_get_component, client):
    mock_get_page.return_value = {
        'title':
        'the page',
        'high_potential_opportunities': [
            {
                'title': 'Rail Infrastructure',
                'meta': {
                    'slug': 'invest-aerospace',
                    'languages': [
                        ['fr', 'Français'],
                    ],
                },
            },
        ],
        'featured_cards': [],
        'meta': {
            'languages': [('en-gb', 'English')]
        },
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    url = reverse('index')
    response = client.get(url)

    assert response.context_data['show_hpo_section'] is False
def test_capital_invest_sub_sector_page_returns_200_when_feature_flag_on(
        mock_cms_response, rf, settings):
    settings.FEATURE_FLAGS['CAPITAL_INVEST_SUB_SECTOR_PAGE_ON'] = True

    page = {
        'title': 'Housing',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
            ],
            'slug': 'housing'
        },
        'page_type': 'InternationalSubSectorPage',
        'statistics': [],
        'section_three_subsections': [],
        'related_opportunities': []
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/industries/energy/housing')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/industries/energy/housing')

    assert response.status_code == 200
Esempio n. 12
0
def test_landing_page_cms_component_bidi(mock_get_page, mock_get_component,
                                         client, settings):
    settings.FEATURE_FLAGS = {
        **settings.FEATURE_FLAGS,
        'EU_EXIT_BANNER_ON': True,
    }
    mock_get_page.return_value = {
        'title': 'the page',
        'sectors': [],
        'guides': [],
        'high_potential_opportunities': [],
        'featured_cards': [],
        'meta': {
            'languages': [('ar', 'العربيّة')]
        },
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200,
        json_payload={
            'banner_label': 'EU Exit updates',
            'banner_content': '<p>Lorem ipsum.</p>',
            'meta': {
                'languages': [('ar', 'العربيّة')]
            },
        })

    translation.activate('ar')
    url = reverse('index')
    response = client.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')

    assert soup.select('.banner-container')[0].get('dir') == 'rtl'
def test_get_capital_invest_opportunity_page_url_constants(
        mock_cms_response, rf):

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type': 'CapitalInvestOpportunityPage'
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/opportunities/ashton')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/opportunities/ashton')

    assert response.context_data['invest_cta_link'] == urls.SERVICES_INVEST
    assert response.context_data['buy_cta_link'] == urls.SERVICES_FAS
Esempio n. 14
0
def test_cms_language_switcher_one_language(mock_cms_response, rf):
    class MyView(CMSPageView):

        template_name = 'core/base.html'
        slug = 'test'
        active_view_name = ''

    page = {
        'title': 'test',
        'meta': {
            'languages': [
                ['de', 'Deutsch'],
            ]
        }
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/')
    with translation.override('de'):
        response = MyView.as_view()(request)

    assert response.status_code == 200
    assert response.context_data['language_switcher']['show'] is False
def test_get_why_choose_the_uk_page_attaches_array_lengths_to_view(
        mock_cms_response, rf):

    page = {
        'title':
        'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type':
        'AboutUkWhyChooseTheUkPage',
        'statistics': [{
            'number': '1'
        }, {
            'number': '2',
            'heading': 'heading'
        }, {
            'number': None,
            'heading': 'no-number-stat'
        }]
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/about-uk/why-choose-uk/')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/about-uk/why-choose-uk/')

    assert response.context_data['num_of_statistics'] == 2
Esempio n. 16
0
def test_industries_landing_page_cms_view(mock_get_page, client):
    mock_get_page.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    url = reverse('industries')
    response = client.get(url)

    assert response.status_code == 200
def test_perfect_fit_main_view_get(mock_get_options, client):
    mock_get_options.return_value = helpers.create_response(
        status_code=200,
        json_payload=OPTIONS_DATA
    )
    url = reverse('perfect_fit_prospectus:main')
    response = client.get(url)
    assert response.status_code == 200
Esempio n. 18
0
def test_uk_region_page_cms_view(mock_get_page, client):
    mock_get_page.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    url = reverse('uk-region', kwargs={'slug': 'region-name'})
    response = client.get(url)

    assert response.status_code == 200
def test_get_sorting_filters_chosen_for_opportunity_search(
        mock_cms_response, rf):

    page = {
        'title':
        'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ],
            'slug':
            'opportunities'
        },
        'page_type':
        'CapitalInvestOpportunityListingPage',
        'opportunity_list': [
            {
                'id':
                6,
                'title':
                'Some Opp 1',
                'sub_sectors': ['energy', 'housing-led'],
                'scale_value':
                '1000.00',
                'related_region': {
                    'title': 'South of England'
                },
                'related_sectors': [
                    {
                        'related_sector': {
                            'heading': 'Aerospace'
                        }
                    },
                ],
            },
        ]
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get(
        '/international/content/opportunities/?sort_by=Scale%3A+Low+to+High&region=Midlands'
    )  # NOQA
    request.LANGUAGE_CODE = 'en-gb'
    response = OpportunitySearchView.as_view(
    )(request,
      path=
      '/international/content/opportunities/?sort_by=Scale%3A+Low+to+High&regionMidlands'
      )  # NOQA

    assert response.context_data['sorting_chosen'] == 'Scale: Low to High'
def test_get_sector_page_attaches_array_lengths_to_view(mock_cms_response, rf):

    page = {
        'title':
        'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type':
        'InternationalSectorPage',
        'related_opportunities': [
            {
                'title': 'Sector',
                'hero_image': {
                    'url': 'article_list.png'
                },
                'sub_sectors': ['energy', 'housing-led'],
                'scale': 'scale',
            },
        ],
        'statistics': [{
            'number': '1'
        }, {
            'number': '2',
            'heading': 'heading'
        }, {
            'number': None,
            'heading': 'no-number-stat'
        }],
        'section_three_subsections': [{
            'heading': 'heading'
        }, {
            'heading': 'heading-with-teaser',
            'teaser': 'teaser'
        }, {
            'heading': None,
            'teaser': 'teaser-without-heading'
        }]
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/industries/sector-page/')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/industries/sector-page/')

    assert response.context_data['num_of_statistics'] == 2
    assert response.context_data['section_three_num_of_subsections'] == 2
Esempio n. 21
0
def test_industry_page_does_not_exist_in_international(mock_get_page,
                                                       mock_page_exists,
                                                       client):
    mock_page_exists.return_value = None
    mock_get_page.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)
    url = reverse('industry', kwargs={'slug': 'foo'})
    response = client.get(url)
    assert mock_get_page.call_args == call(draft_token=None,
                                           language_code='en-gb',
                                           slug='foo')
    assert response.status_code == 200
Esempio n. 22
0
def test_get_cms_page(mock_cms_response, rf):
    class TestView(CMSPageView):
        template_name = 'core/base.html'
        slug = 'invest-home-page'
        active_view_name = ''

    mock_cms_response.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    request = rf.get('/')
    response = TestView.as_view()(request)

    assert response.context_data['page'] == dummy_page
def test_active_view_name(mock_cms_response, rf):
    class TestView(CMSPageMixin, TemplateView):
        active_view_name = 'test'
        template_name = 'core/base.html'
        slug = 'test'

    mock_cms_response.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    request = rf.get('/')
    response = TestView.as_view()(request)

    assert response.status_code == 200
    assert response.context_data['active_view_name'] == 'test'
def test_goes_to_page_one_if_page_num_too_big_for_opportunity_search(
        mock_cms_response, rf):

    page = {
        'title':
        'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ],
            'slug':
            'opportunities'
        },
        'page_type':
        'CapitalInvestOpportunityListingPage',
        'opportunity_list': [
            {
                'id':
                6,
                'title':
                'Some Opp 1',
                'sub_sectors': ['energy', 'housing-led'],
                'scale_value':
                '',
                'related_region': {
                    'title': 'South of England'
                },
                'related_sectors': [
                    {
                        'related_sector': {
                            'heading': 'Aerospace'
                        }
                    },
                ],
            },
        ]
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/opportunities/?page=10')
    request.LANGUAGE_CODE = 'en-gb'
    response = OpportunitySearchView.as_view()(
        request, path='/international/content/opportunities/'
        '?page=10')

    assert response.url == '/international/content/opportunities/?&page=1'
Esempio n. 25
0
def test_cms_language_switcher_active_language_available(
        mock_cms_response, rf):
    class MyView(CMSPageView):

        template_name = 'core/base.html'
        slug = 'test'
        active_view_name = ''

    mock_cms_response.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    request = rf.get('/de/')
    with translation.override('de'):
        response = MyView.as_view()(request)

    assert response.status_code == 200
    context = response.context_data['language_switcher']
    assert context['show'] is True
Esempio n. 26
0
def test_get_int_link_on_invest_home_page(mock_get_page, mock_get_component,
                                          client):

    mock_get_page.return_value = {
        'title': 'the page',
        'high_potential_opportunities': [],
        'featured_cards': [],
        'meta': {
            'languages': [('en-gb', 'English')]
        },
    }
    mock_get_component.return_value = helpers.create_response(
        status_code=200, json_payload=dummy_page)

    url = reverse('index')
    response = client.get(url)

    assert response.context_data[
        'international_home_page_link'] == urls.GREAT_INTERNATIONAL
def test_get_capital_invest_region_page_attaches_array_lengths_to_view(
        mock_cms_response, rf):

    page = {
        'title':
        'test',
        'meta': {
            'languages': [
                ['en-gb', 'English'],
                ['fr', 'Français'],
                ['de', 'Deutsch'],
            ]
        },
        'page_type':
        'CapitalInvestRegionPage',
        'economics_stats': [{
            'number': '1'
        }, {
            'number': '2',
            'heading': 'heading'
        }, {
            'number': None,
            'heading': 'no-number-stat'
        }],
        'location_stats': [{
            'number': '1'
        }, {
            'number': None,
            'heading': 'no-number-stat'
        }],
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    request = rf.get('/international/content/midlands/')
    request.LANGUAGE_CODE = 'en-gb'
    response = MultilingualCMSPageFromPathView.as_view()(
        request, path='/international/content/midlands/')

    assert response.context_data['num_of_economics_statistics'] == 2
    assert response.context_data['num_of_location_statistics'] == 1
Esempio n. 28
0
def test_404_when_cms_language_unavailable(mock_cms_response, rf):
    class TestView(GetSlugFromKwargsMixin, CMSPageView):
        template_name = 'core/base.html'

    page = {
        'title': 'the page',
        'meta': {
            'languages': [('en-gb', 'English'), ('de', 'German')],
            'slug': 'aerospace'
        },
    }

    mock_cms_response.return_value = helpers.create_response(status_code=200,
                                                             json_payload=page)

    translation.activate('fr')
    request = rf.get('/fr/')
    view = TestView.as_view()

    with pytest.raises(Http404):
        view(request, slug='aerospace')
def test_perfect_fit_main_view_post_valid_data(
    mock_get_options, mock_create_report, captcha_stub, client
):
    mock_get_options.return_value = helpers.create_response(
        status_code=200,
        json_payload=OPTIONS_DATA
    )

    valid_data = {
        'name': 'Ted',
        'company': 'Corp',
        'email': '*****@*****.**',
        'country': 'AF',
        'sector': 'tech',
        'g-recaptcha-response': captcha_stub,
        'gdpr_optin': 'on'
    }

    url = reverse('perfect_fit_prospectus:main')
    response = client.post(url, data=valid_data)
    assert response.status_code == 302

    success_response = client.post(
        url, data=valid_data, follow=True)
    assert success_response.status_code == 200

    messages = [
        message.message for message in
        list(success_response.context['messages'])]
    assert '*****@*****.**' in messages[0]

    assert mock_create_report.called is True
    assert mock_create_report.call_args == mock.call(
        {
            'name': 'Ted', 'company': 'Corp', 'email': '*****@*****.**',
            'phone_number': '', 'country': 'AF', 'gdpr_optin': True,
            'captcha': 'PASSED', 'sector': 'tech'
        }
    )
def test_perfect_fit_main_view_post_client_error(
    mock_get_options, mock_create_report, client, captcha_stub
):
    mock_get_options.return_value = helpers.create_response(
        status_code=200,
        json_payload=OPTIONS_DATA
    )

    mock_create_report.side_effect = HTTPError

    valid_data = {
        'name': 'Ted',
        'company': 'Corp',
        'email': '*****@*****.**',
        'country': 'AF',
        'sector': 'tech',
        'g-recaptcha-response': captcha_stub,
        'gdpr_optin': 'on'
    }
    url = reverse('perfect_fit_prospectus:main')
    with pytest.raises(HTTPError):
        client.post(url, data=valid_data)