Make a few more test files Pytest 5 compliant

This commit is contained in:
Katie Smith
2019-12-19 11:19:28 +00:00
parent c6779e6f92
commit b62018a8e4
3 changed files with 69 additions and 64 deletions

View File

@@ -5,13 +5,7 @@ import pytest
from bs4 import BeautifulSoup
from flask import url_for
from tests.conftest import (
SERVICE_ONE_ID,
SERVICE_TWO_ID,
normalize_spaces,
service_one,
service_two,
)
from tests.conftest import SERVICE_ONE_ID, SERVICE_TWO_ID, normalize_spaces
OS1, OS2, OS3, S1, S2, S3 = repeat(uuid.uuid4(), 6)
@@ -237,43 +231,58 @@ def test_choose_account_should_not_show_back_to_service_link_if_service_archived
assert page.select_one('.navigation-service a') is None
@pytest.mark.parametrize('service, expected_status, page_text', (
(service_one, 200, (
'Test Service Switch service '
''
'Dashboard '
'Templates '
'Team members'
)),
(service_two, 403, (
def test_should_not_show_back_to_service_if_user_doesnt_belong_to_service(
client_request,
fake_uuid,
mock_get_service,
service_two,
):
mock_get_service.return_value = service_two
expected_page_text = (
# Page has no back to link
'Youre not allowed to see this page '
'To check your permissions, speak to a member of your team who can manage settings, team and usage.'
)),
))
def test_should_not_show_back_to_service_if_user_doesnt_belong_to_service(
client_request,
api_user_active,
fake_uuid,
mock_get_service,
mock_get_service_template,
mock_get_template_folders,
service,
expected_status,
page_text,
):
mock_get_service.return_value = service(api_user_active)
)
page = client_request.get(
'main.view_template',
service_id=mock_get_service.return_value['id'],
template_id=fake_uuid,
_expected_status=expected_status,
_expected_status=403,
_test_page_title=False,
)
assert normalize_spaces(
page.select_one('header + .govuk-width-container').text
).startswith(
normalize_spaces(page_text)
normalize_spaces(expected_page_text)
)
def test_should_show_back_to_service_if_user_belongs_to_service(
client_request,
fake_uuid,
mock_get_service,
mock_get_service_template,
service_one,
):
mock_get_service.return_value = service_one
expected_page_text = (
'Test Service Switch service '
''
'Dashboard '
'Templates '
'Team members'
)
page = client_request.get(
'main.view_template',
service_id=mock_get_service.return_value['id'],
template_id=fake_uuid,
_test_page_title=False,
)
assert normalize_spaces(
page.select_one('header + .govuk-width-container').text
).startswith(
normalize_spaces(expected_page_text)
)

View File

@@ -11,10 +11,8 @@ from tests.conftest import (
USER_ONE_ID,
active_caseworking_user,
active_user_with_permissions,
normalize_spaces,
)
from tests.conftest import mock_check_invite_token as mock_check_token_invite
from tests.conftest import normalize_spaces
from tests.conftest import sample_invite as create_sample_invite
def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(
@@ -296,13 +294,12 @@ def test_new_user_accept_invite_calls_api_and_views_registration_page(
def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation(
client,
service_one,
mocker,
mock_get_user,
mock_get_service,
sample_invite,
mock_check_invite_token,
):
cancelled_invitation = create_sample_invite(mocker, service_one, status='cancelled')
mock_check_token_invite(mocker, cancelled_invitation)
sample_invite['status'] = 'cancelled'
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'))
app.invite_api_client.check_token.assert_called_with('thisisnotarealtoken')