def test_should_show_page_for_one_job(
    client_request,
    active_user_with_permissions,
    mock_get_service_template,
    mock_get_job,
    mocker,
    mock_get_notifications,
    mock_get_service_data_retention,
    fake_uuid,
    status_argument,
    expected_api_call,
    user,
):

    page = client_request.get(
        'main.view_job',
        service_id=SERVICE_ONE_ID,
        job_id=fake_uuid,
        status=status_argument
    )

    assert page.h1.text.strip() == 'thisisatest.csv'
    assert ' '.join(page.find('tbody').find('tr').text.split()) == (
        '07123456789 template content Delivered 1 January at 11:10am'
    )
    assert page.find('div', {'data-key': 'notifications'})['data-resource'] == url_for(
        'main.view_job_updates',
        service_id=SERVICE_ONE_ID,
        job_id=fake_uuid,
        status=status_argument,
    )
    csv_link = page.select_one('a[download]')
    assert csv_link['href'] == url_for(
        'main.view_job_csv',
        service_id=SERVICE_ONE_ID,
        job_id=fake_uuid,
        status=status_argument
    )
    assert csv_link.text == 'Download this report'
    assert page.find('span', {'id': 'time-left'}).text == 'Data available for 7 days'

    assert normalize_spaces(page.select_one('tbody tr').text) == normalize_spaces(
        '07123456789 '
        'template content '
        'Delivered 1 January at 11:10am'
    )
    assert page.select_one('tbody tr a')['href'] == url_for(
        'main.view_notification',
        service_id=SERVICE_ONE_ID,
        notification_id=sample_uuid(),
        from_job=fake_uuid,
    )

    mock_get_notifications.assert_called_with(
        SERVICE_ONE_ID,
        fake_uuid,
        status=expected_api_call
    )
Esempio n. 2
0
def test_should_show_page_for_one_job(
    logged_in_client,
    service_one,
    active_user_with_permissions,
    mock_get_service_template,
    mock_get_job,
    mocker,
    mock_get_notifications,
    fake_uuid,
    status_argument,
    expected_api_call,
):

    response = logged_in_client.get(url_for(
        'main.view_job',
        service_id=service_one['id'],
        job_id=fake_uuid,
        status=status_argument
    ))

    assert response.status_code == 200
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    assert page.h1.text.strip() == 'thisisatest.csv'
    assert ' '.join(page.find('tbody').find('tr').text.split()) == (
        '07123456789 template content Delivered 1 January at 11:10am'
    )
    assert page.find('div', {'data-key': 'notifications'})['data-resource'] == url_for(
        'main.view_job_updates',
        service_id=service_one['id'],
        job_id=fake_uuid,
        status=status_argument,
    )
    csv_link = page.select_one('a[download]')
    assert csv_link['href'] == url_for(
        'main.view_job_csv',
        service_id=service_one['id'],
        job_id=fake_uuid,
        status=status_argument
    )
    assert csv_link.text == 'Download this report'
    assert page.find('span', {'id': 'time-left'}).text == 'Data available for 7 days'
    mock_get_notifications.assert_called_with(
        service_one['id'],
        fake_uuid,
        status=expected_api_call
    )
def test_can_show_notifications(
    client_request,
    logged_in_client,
    service_one,
    mock_get_notifications,
    mock_get_service_statistics,
    mock_has_no_jobs,
    user,
    extra_args,
    expected_update_endpoint,
    page_title,
    status_argument,
    expected_api_call,
    page_argument,
    expected_page_argument,
    to_argument,
    expected_to_argument,
    mocker,
    fake_uuid,
):
    client_request.login(user(fake_uuid))
    if expected_to_argument:
        page = client_request.post('main.view_notifications',
                                   service_id=service_one['id'],
                                   status=status_argument,
                                   page=page_argument,
                                   _data={'to': to_argument},
                                   _expected_status=200,
                                   **extra_args)
    else:
        page = client_request.get('main.view_notifications',
                                  service_id=service_one['id'],
                                  status=status_argument,
                                  page=page_argument,
                                  **extra_args)
    text_of_first_row = page.select('tbody tr')[0].text
    assert '07123456789' in text_of_first_row
    assert ('template content' in text_of_first_row
            or 'template subject' in text_of_first_row)
    assert 'Delivered' in text_of_first_row
    assert page_title in page.h1.text.strip()

    path_to_json = page.find("div",
                             {'data-key': 'notifications'})['data-resource']

    url = urlparse(path_to_json)
    assert url.path == '/services/{}/notifications{}'.format(
        service_one['id'],
        expected_update_endpoint,
    )
    query_dict = parse_qs(url.query)
    if status_argument:
        assert query_dict['status'] == [status_argument]
    if expected_page_argument:
        assert query_dict['page'] == [str(expected_page_argument)]
    assert 'to' not in query_dict

    mock_get_notifications.assert_called_with(
        limit_days=7,
        page=expected_page_argument,
        service_id=service_one['id'],
        status=expected_api_call,
        template_type=list(extra_args.values()),
        to=expected_to_argument,
    )

    json_response = logged_in_client.get(
        url_for('main.get_notifications_as_json',
                service_id=service_one['id'],
                status=status_argument,
                **extra_args))
    json_content = json.loads(json_response.get_data(as_text=True))
    assert json_content.keys() == {'counts', 'notifications'}
Esempio n. 4
0
def test_can_show_notifications(
    logged_in_client,
    service_one,
    mock_get_notifications,
    mock_get_detailed_service,
    message_type,
    page_title,
    status_argument,
    expected_api_call,
    page_argument,
    expected_page_argument,
    to_argument,
    expected_to_argument,
):
    if expected_to_argument:
        response = logged_in_client.post(url_for(
            'main.view_notifications',
            service_id=service_one['id'],
            message_type=message_type,
            status=status_argument,
            page=page_argument,
        ),
                                         data={'to': to_argument})
    else:
        response = logged_in_client.get(
            url_for(
                'main.view_notifications',
                service_id=service_one['id'],
                message_type=message_type,
                status=status_argument,
                page=page_argument,
            ))
    assert response.status_code == 200
    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
    text_of_first_row = page.select('tbody tr')[0].text
    assert '07123456789' in text_of_first_row
    assert ('template content' in text_of_first_row
            or 'template subject' in text_of_first_row)
    assert 'Delivered' in text_of_first_row
    assert page_title in page.h1.text.strip()

    path_to_json = page.find("div",
                             {'data-key': 'notifications'})['data-resource']

    url = urlparse(path_to_json)
    assert url.path == '/services/{}/notifications/{}.json'.format(
        service_one['id'], message_type)
    query_dict = parse_qs(url.query)
    if status_argument:
        assert query_dict['status'] == [status_argument]
    if expected_page_argument:
        assert query_dict['page'] == [str(expected_page_argument)]
    assert 'to' not in query_dict

    mock_get_notifications.assert_called_with(
        limit_days=7,
        page=expected_page_argument,
        service_id=service_one['id'],
        status=expected_api_call,
        template_type=[message_type],
        to=expected_to_argument,
    )

    json_response = logged_in_client.get(
        url_for('main.get_notifications_as_json',
                service_id=service_one['id'],
                message_type=message_type,
                status=status_argument))
    json_content = json.loads(json_response.get_data(as_text=True))
    assert json_content.keys() == {'counts', 'notifications'}
Esempio n. 5
0
def test_can_show_notifications(
    client_request,
    logged_in_client,
    service_one,
    mock_get_notifications,
    mock_get_service_statistics,
    mock_get_service_data_retention,
    mock_has_no_jobs,
    user,
    extra_args,
    expected_update_endpoint,
    expected_limit_days,
    page_title,
    status_argument,
    expected_api_call,
    page_argument,
    expected_page_argument,
    to_argument,
    expected_to_argument,
    mocker,
    fake_uuid,
):
    client_request.login(user(fake_uuid))
    if expected_to_argument:
        page = client_request.post(
            "main.view_notifications",
            service_id=SERVICE_ONE_ID,
            status=status_argument,
            page=page_argument,
            _data={"to": to_argument},
            _expected_status=200,
            **extra_args,
        )
    else:
        page = client_request.get(
            "main.view_notifications",
            service_id=SERVICE_ONE_ID,
            status=status_argument,
            page=page_argument,
            **extra_args,
        )
    text_of_first_row = page.select("tbody tr")[0].text
    assert "6502532222" in text_of_first_row
    assert "template content" in text_of_first_row or "template subject" in text_of_first_row
    assert "Delivered" in text_of_first_row
    assert page_title in page.h1.text.strip()

    path_to_json = page.find("div",
                             {"data-key": "notifications"})["data-resource"]

    url = urlparse(path_to_json)
    assert url.path == "/services/{}/notifications{}".format(
        SERVICE_ONE_ID,
        expected_update_endpoint,
    )
    query_dict = parse_qs(url.query)
    if status_argument:
        assert query_dict["status"] == [status_argument]
    if expected_page_argument:
        assert query_dict["page"] == [str(expected_page_argument)]
    assert "to" not in query_dict

    mock_get_notifications.assert_called_with(
        limit_days=expected_limit_days,
        page=expected_page_argument,
        service_id=SERVICE_ONE_ID,
        status=expected_api_call,
        template_type=list(extra_args.values()),
        to=expected_to_argument,
    )

    json_response = logged_in_client.get(
        url_for(
            "main.get_notifications_as_json",
            service_id=service_one["id"],
            status=status_argument,
            **extra_args,
        ))
    json_content = json.loads(json_response.get_data(as_text=True))
    assert json_content.keys() == {
        "counts",
        "notifications",
        "service_data_retention_days",
    }