2018-04-24 12:48:05 +01:00
|
|
|
import pytest
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
from app.navigation import (
|
|
|
|
|
CaseworkNavigation,
|
|
|
|
|
HeaderNavigation,
|
|
|
|
|
MainNavigation,
|
|
|
|
|
OrgNavigation,
|
|
|
|
|
)
|
|
|
|
|
from tests.conftest import (
|
|
|
|
|
ORGANISATION_ID,
|
|
|
|
|
SERVICE_ONE_ID,
|
|
|
|
|
active_caseworking_user,
|
|
|
|
|
app_,
|
|
|
|
|
normalize_spaces,
|
|
|
|
|
)
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
all_endpoints = [
|
|
|
|
|
rule.endpoint for rule in next(app_(None)).url_map.iter_rules()
|
|
|
|
|
]
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
navigation_instances = (
|
2018-04-25 11:11:37 +01:00
|
|
|
MainNavigation(),
|
|
|
|
|
HeaderNavigation(),
|
2018-04-25 13:17:47 +01:00
|
|
|
OrgNavigation(),
|
2018-06-12 16:17:20 +01:00
|
|
|
CaseworkNavigation(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('navigation_instance', navigation_instances)
|
2018-04-25 11:11:37 +01:00
|
|
|
def test_navigation_items_are_properly_defined(navigation_instance):
|
|
|
|
|
for endpoint in navigation_instance.endpoints_with_navigation:
|
|
|
|
|
assert (
|
|
|
|
|
endpoint in all_endpoints
|
|
|
|
|
), '{} is not a real endpoint (in {}.mapping)'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
endpoint not in navigation_instance.endpoints_without_navigation
|
|
|
|
|
), '{} is listed in {}.mapping and {}.exclude'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__,
|
|
|
|
|
type(navigation_instance).__name__,
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
navigation_instance.endpoints_with_navigation.count(endpoint) == 1
|
|
|
|
|
), '{} found more than once in {}.mapping'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__
|
|
|
|
|
)
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
@pytest.mark.parametrize('navigation_instance', navigation_instances)
|
2018-04-25 11:11:37 +01:00
|
|
|
def test_excluded_navigation_items_are_properly_defined(navigation_instance):
|
|
|
|
|
for endpoint in navigation_instance.endpoints_without_navigation:
|
|
|
|
|
assert (
|
|
|
|
|
endpoint in all_endpoints
|
|
|
|
|
), '{} is not a real endpoint (in {}.exclude)'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
endpoint not in navigation_instance.endpoints_with_navigation
|
|
|
|
|
), '{} is listed in {}.exclude and {}.mapping'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__,
|
|
|
|
|
type(navigation_instance).__name__,
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
navigation_instance.endpoints_without_navigation.count(endpoint) == 1
|
|
|
|
|
), '{} found more than once in {}.exclude'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__
|
|
|
|
|
)
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
@pytest.mark.parametrize('navigation_instance', navigation_instances)
|
2018-04-25 11:11:37 +01:00
|
|
|
def test_all_endpoints_are_covered(navigation_instance):
|
2018-04-24 12:48:05 +01:00
|
|
|
for endpoint in all_endpoints:
|
2018-05-29 15:31:40 +01:00
|
|
|
if not endpoint == 'main.monthly_billing_usage':
|
2018-05-16 13:23:49 +01:00
|
|
|
assert endpoint in (
|
|
|
|
|
navigation_instance.endpoints_with_navigation +
|
|
|
|
|
navigation_instance.endpoints_without_navigation
|
|
|
|
|
), '{} is not listed or excluded in {}'.format(
|
|
|
|
|
endpoint,
|
|
|
|
|
type(navigation_instance).__name__
|
|
|
|
|
)
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
2018-06-12 16:17:20 +01:00
|
|
|
@pytest.mark.parametrize('navigation_instance', navigation_instances)
|
2018-04-24 12:48:05 +01:00
|
|
|
@pytest.mark.xfail(raises=KeyError)
|
2018-04-25 11:11:37 +01:00
|
|
|
def test_raises_on_invalid_navigation_item(
|
|
|
|
|
client_request, navigation_instance
|
|
|
|
|
):
|
|
|
|
|
navigation_instance.is_selected('foo')
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint, selected_nav_item', [
|
|
|
|
|
('main.choose_template', 'Templates'),
|
|
|
|
|
('main.manage_users', 'Team members'),
|
|
|
|
|
])
|
|
|
|
|
def test_a_page_should_nave_selected_navigation_item(
|
|
|
|
|
client_request,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
mock_get_invites_for_service,
|
2018-11-01 17:11:58 +00:00
|
|
|
mock_get_template_folders,
|
2018-04-24 12:48:05 +01:00
|
|
|
endpoint,
|
|
|
|
|
selected_nav_item,
|
|
|
|
|
):
|
|
|
|
|
page = client_request.get(endpoint, service_id=SERVICE_ONE_ID)
|
|
|
|
|
selected_nav_items = page.select('.navigation a.selected')
|
|
|
|
|
assert len(selected_nav_items) == 1
|
|
|
|
|
assert selected_nav_items[0].text.strip() == selected_nav_item
|
2018-04-25 11:11:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint, selected_nav_item', [
|
|
|
|
|
('main.documentation', 'Documentation'),
|
|
|
|
|
('main.support', 'Support'),
|
|
|
|
|
])
|
|
|
|
|
def test_a_page_should_nave_selected_header_navigation_item(
|
|
|
|
|
client_request,
|
|
|
|
|
endpoint,
|
|
|
|
|
selected_nav_item,
|
|
|
|
|
):
|
|
|
|
|
page = client_request.get(endpoint, service_id=SERVICE_ONE_ID)
|
|
|
|
|
selected_nav_items = page.select('#proposition-links a.active')
|
|
|
|
|
assert len(selected_nav_items) == 1
|
|
|
|
|
assert selected_nav_items[0].text.strip() == selected_nav_item
|
2018-04-25 13:17:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('endpoint, selected_nav_item', [
|
2019-06-20 10:59:54 +01:00
|
|
|
('main.organisation_dashboard', 'Usage'),
|
2018-04-25 13:17:47 +01:00
|
|
|
('main.manage_org_users', 'Team members'),
|
|
|
|
|
])
|
|
|
|
|
def test_a_page_should_nave_selected_org_navigation_item(
|
|
|
|
|
client_request,
|
|
|
|
|
mock_get_organisation,
|
|
|
|
|
mock_get_organisation_services,
|
|
|
|
|
mock_get_users_for_organisation,
|
|
|
|
|
mock_get_invited_users_for_organisation,
|
|
|
|
|
endpoint,
|
|
|
|
|
selected_nav_item,
|
|
|
|
|
):
|
|
|
|
|
page = client_request.get(endpoint, org_id=ORGANISATION_ID)
|
|
|
|
|
selected_nav_items = page.select('.navigation a.selected')
|
|
|
|
|
assert len(selected_nav_items) == 1
|
|
|
|
|
assert selected_nav_items[0].text.strip() == selected_nav_item
|
2018-06-12 16:17:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_caseworkers_get_caseworking_navigation(
|
|
|
|
|
client_request,
|
|
|
|
|
mocker,
|
|
|
|
|
fake_uuid,
|
2018-11-01 17:11:58 +00:00
|
|
|
mock_get_template_folders,
|
2018-06-12 16:17:20 +01:00
|
|
|
mock_get_service_templates,
|
2018-07-30 17:40:32 +01:00
|
|
|
mock_has_no_jobs,
|
2018-06-12 16:17:20 +01:00
|
|
|
):
|
|
|
|
|
mocker.patch(
|
|
|
|
|
'app.user_api_client.get_user',
|
|
|
|
|
return_value=active_caseworking_user(fake_uuid)
|
|
|
|
|
)
|
|
|
|
|
page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID)
|
|
|
|
|
assert normalize_spaces(page.select_one('#content nav').text) == (
|
2018-08-06 11:10:37 +01:00
|
|
|
'Templates Sent messages Team members'
|
2018-06-12 16:17:20 +01:00
|
|
|
)
|
2018-07-30 17:40:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_caseworkers_see_jobs_nav_if_jobs_exist(
|
|
|
|
|
client_request,
|
|
|
|
|
mocker,
|
|
|
|
|
fake_uuid,
|
|
|
|
|
mock_get_service_templates,
|
2018-11-01 17:11:58 +00:00
|
|
|
mock_get_template_folders,
|
2018-07-30 17:40:32 +01:00
|
|
|
mock_has_jobs,
|
|
|
|
|
):
|
|
|
|
|
mocker.patch(
|
|
|
|
|
'app.user_api_client.get_user',
|
|
|
|
|
return_value=active_caseworking_user(fake_uuid)
|
|
|
|
|
)
|
|
|
|
|
page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID)
|
|
|
|
|
assert normalize_spaces(page.select_one('#content nav').text) == (
|
2019-10-09 10:52:33 +01:00
|
|
|
'Templates Sent messages Uploads Team members'
|
2018-07-30 17:40:32 +01:00
|
|
|
)
|