コード例 #1
0
def test_planned_tests_page_with_current_operator_test(
    mocker,
    client_get,
    extra_json_fields,
):
    mocker.patch('app.models.alerts.PlannedTests.from_yaml', return_value=[])
    mocker.patch('app.models.alerts.Alerts.load',
                 return_value=Alerts([
                     create_alert_dict(
                         channel='operator',
                         starts_at=dt_parse('2021-04-21T09:00:00Z'),
                         **extra_json_fields)
                 ]))
    html = client_get("alerts/planned-tests")
    assert [normalize_spaces(h2.text)
            for h2 in html.select('main h2')] == ['Wednesday 21 April 2021']
    assert not html.select('main h3')
    assert [normalize_spaces(p.text) for p in html.select('main p')] == [
        'Some mobile phone networks in the UK will test emergency alerts.',
        'Most phones and tablets will not get a test alert.',
        'Find out more about mobile network operator tests.',
        'The alert will say:',
        ('This is a mobile network operator test of the Emergency Alerts '
         'service. You do not need to take any action. To find out more, '
         'search for gov.uk/alerts'),
    ]
コード例 #2
0
def test_landing_page_404s_if_no_key_in_query_string(client):
    response = client.get(
        url_for('main.landing', service_id=uuid4(), document_id=uuid4()))
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert response.status_code == 404
    assert normalize_spaces(page.title.text) == 'Page not found – GOV.UK'
    assert normalize_spaces(page.h1.text) == 'Page not found'
コード例 #3
0
def test_404_if_no_key_in_query_string(service_id, document_id, view, client):
    response = client.get(
        url_for(
            view,
            service_id=service_id,
            document_id=document_id,
        ))
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert response.status_code == 404
    assert normalize_spaces(page.title.text) == 'Page not found – GOV.UK'
    assert normalize_spaces(page.h1.text) == 'Page not found'
コード例 #4
0
def test_planned_tests_page_with_upcoming_test(
    mocker,
    client_get,
    data_from_yaml,
    expected_h2s,
    expected_h3s,
    expected_paragraphs,
):
    mocker.patch('app.models.alerts.PlannedTests.from_yaml',
                 return_value=data_from_yaml)
    html = client_get("alerts/planned-tests")
    assert [normalize_spaces(h2.text)
            for h2 in html.select('main h2')] == expected_h2s
    assert [normalize_spaces(h3.text)
            for h3 in html.select('main h3')] == expected_h3s
    assert [normalize_spaces(p.text)
            for p in html.select('main p')] == expected_paragraphs
コード例 #5
0
def test_download_document_creates_link_to_actual_doc_from_api(
        service_id, document_id, key, document_has_metadata, client, mocker,
        sample_service):
    mocker.patch('app.service_api_client.get_service',
                 return_value={'data': sample_service})

    response = client.get(
        url_for('main.download_document',
                service_id=service_id,
                document_id=document_id,
                key=key))

    assert response.status_code == 200
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert normalize_spaces(page.title.text) == 'Download your file – GOV.UK'
    assert normalize_spaces(page.h1.text) == 'Download your file'
    assert page.select('main a')[0]['href'] == 'url'
コード例 #6
0
def test_landing_page_when_document_is_unavailable(client, mocker,
                                                   sample_service):
    mocker.patch('app.service_api_client.get_service',
                 return_value={'data': sample_service})
    mocker.patch('app.main.views.index.is_file_available', return_value=False)
    response = client.get(
        url_for('main.landing',
                service_id=uuid4(),
                document_id=uuid4(),
                key='1234'))

    assert response.status_code == 200
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert normalize_spaces(page.h1.text) == 'No longer available'

    contact_link = page.select('main a')[0]
    assert normalize_spaces(contact_link.text) == 'contact Sample Service'
    assert contact_link['href'] == 'https://sample-service.gov.uk'
コード例 #7
0
def test_planned_tests_page(mocker, client_get):
    mocker.patch('app.models.alerts.PlannedTests.from_yaml', return_value=[])
    html = client_get("alerts/planned-tests")
    assert html.select_one('h1').text.strip() == "Planned tests"
    assert [normalize_spaces(p.text) for p in html.select('main p')] == [
        'There are currently no planned tests of emergency alerts.',
        'You can see previous tests on the past alerts page.',
    ]
    assert html.select_one('main p a').text == 'past alerts page'
    assert html.select_one('main p a')['href'] == '/alerts/past-alerts'
コード例 #8
0
def test_landing_page_creates_link_for_document(client, mocker,
                                                sample_service):
    mocker.patch('app.service_api_client.get_service',
                 return_value={'data': sample_service})
    service_id = uuid4()
    document_id = uuid4()
    mocker.patch('app.main.views.index.is_file_available', return_value=True)
    response = client.get(
        url_for('main.landing',
                service_id=service_id,
                document_id=document_id,
                key='1234'))

    assert response.status_code == 200
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert normalize_spaces(
        page.title.text) == 'You have a file to download – GOV.UK'
    assert normalize_spaces(page.h1.text) == 'You have a file to download'
    assert page.find('a', string=re.compile("Continue"))['href'] == url_for(
        'main.download_document',
        service_id=service_id,
        document_id=document_id,
        key='1234')
コード例 #9
0
def test_planned_tests_page_with_previous_days_operator_test(
    mocker,
    client_get,
):
    mocker.patch('app.models.alerts.PlannedTests.from_yaml', return_value=[])
    mocker.patch('app.models.alerts.Alerts.load',
                 return_value=Alerts([
                     create_alert_dict(
                         channel='operator',
                         starts_at=dt_parse('2021-04-20T09:00:00Z'),
                     )
                 ]))
    html = client_get("alerts/planned-tests")
    assert normalize_spaces(html.select_one('main p').text) == (
        'There are currently no planned tests of emergency alerts.')
コード例 #10
0
def test_index_page_shows_planned_tests(
    client_get,
    mocker,
    current_and_planned_test_alerts,
    expected_banner,
):
    mocker.patch('app.models.alerts.Alerts.current_and_public', [])
    mocker.patch(
        'app.models.alerts.Alerts.current_and_planned_test_alerts',
        current_and_planned_test_alerts,
    )

    html = client_get("alerts")
    assert normalize_spaces(
        html.select_one('.alerts-notification-banner').text) == (
            expected_banner)

    assert html.select_one('.alerts-notification-banner a')['href'] == (
        '/alerts/planned-tests')