2018-04-24 12:48:05 +01:00
|
|
|
import pytest
|
|
|
|
|
from tests.conftest import SERVICE_ONE_ID, app_
|
|
|
|
|
|
2018-04-25 10:24:32 +01:00
|
|
|
from app.navigation import MainNavigation
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
all_endpoints = [
|
|
|
|
|
rule.endpoint for rule in next(app_(None)).url_map.iter_rules()
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_navigation_items_are_properly_defined():
|
2018-04-25 10:24:32 +01:00
|
|
|
for endpoint in MainNavigation().endpoints_with_navigation:
|
2018-04-24 12:48:05 +01:00
|
|
|
assert endpoint in all_endpoints
|
2018-04-25 10:24:32 +01:00
|
|
|
assert endpoint not in MainNavigation().endpoints_without_navigation
|
|
|
|
|
assert MainNavigation().endpoints_with_navigation.count(endpoint) == 1
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_excluded_navigation_items_are_properly_defined():
|
2018-04-25 10:24:32 +01:00
|
|
|
for endpoint in MainNavigation().endpoints_without_navigation:
|
2018-04-24 12:48:05 +01:00
|
|
|
assert endpoint in all_endpoints
|
2018-04-25 10:24:32 +01:00
|
|
|
assert endpoint not in MainNavigation().endpoints_with_navigation
|
|
|
|
|
assert MainNavigation().endpoints_without_navigation.count(endpoint) == 1
|
2018-04-24 12:48:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_all_endpoints_are_covered():
|
|
|
|
|
for endpoint in all_endpoints:
|
|
|
|
|
assert endpoint in (
|
2018-04-25 10:24:32 +01:00
|
|
|
MainNavigation().endpoints_with_navigation +
|
|
|
|
|
MainNavigation().endpoints_without_navigation
|
2018-04-24 12:48:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.xfail(raises=KeyError)
|
|
|
|
|
def test_raises_on_invalid_navigation_item(client_request):
|
2018-04-25 10:24:32 +01:00
|
|
|
MainNavigation().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,
|
|
|
|
|
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
|