Fix get started banner on dashboard

This banner was always being shown because the template was never
getting sent the service’s templates from the API.

This commit fixes this to only show the banner when a service has no
templates, and adds some tests to make sure it doesn’t happen again.
This commit is contained in:
Chris Hill-Scott
2016-07-04 13:04:25 +01:00
parent eb32393551
commit cddfd6c517
4 changed files with 69 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ def service_dashboard(service_id):
return render_template(
'views/dashboard/dashboard.html',
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
templates=service_api_client.get_service_templates(service_id)['data'],
partials=get_dashboard_partials(service_id)
)

View File

@@ -15,7 +15,6 @@
<div class="dashboard">
<h1 class="visuallyhidden">Dashboard</h1>
{% if current_user.has_permissions(['manage_templates'], admin_override=True) %}
{% if not templates %}
{% include 'views/dashboard/write-first-messages.html' %}

View File

@@ -56,6 +56,63 @@ stub_template_stats = [
]
def test_get_started(
app_,
mocker,
api_user_active,
mock_get_service,
mock_get_service_templates_when_no_templates_exist,
mock_get_service_statistics,
mock_get_aggregate_service_statistics,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_get_jobs,
mock_has_permissions,
mock_get_usage
):
mock_template_stats = mocker.patch('app.template_statistics_client.get_template_statistics_for_service',
return_value=copy.deepcopy(stub_template_stats))
with app_.test_request_context(), app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
# mock_get_service_templates_when_no_templates_exist.assert_called_once_with(SERVICE_ONE_ID)
print(response.get_data(as_text=True))
assert response.status_code == 200
assert 'Get started' in response.get_data(as_text=True)
def test_get_started_is_hidden_once_templates_exist(
app_,
mocker,
api_user_active,
mock_get_service,
mock_get_service_templates,
mock_get_service_statistics,
mock_get_aggregate_service_statistics,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_get_jobs,
mock_has_permissions,
mock_get_usage
):
mock_template_stats = mocker.patch('app.template_statistics_client.get_template_statistics_for_service',
return_value=copy.deepcopy(stub_template_stats))
with app_.test_request_context(), app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
# mock_get_service_templates.assert_called_once_with(SERVICE_ONE_ID)
assert response.status_code == 200
assert 'Get started' not in response.get_data(as_text=True)
def test_should_show_recent_templates_on_dashboard(app_,
mocker,
api_user_active,

View File

@@ -424,6 +424,17 @@ def mock_get_service_templates(mocker):
side_effect=_create)
@pytest.fixture(scope='function')
def mock_get_service_templates_when_no_templates_exist(mocker):
def _create(service_id):
return {'data': []}
return mocker.patch(
'app.service_api_client.get_service_templates',
side_effect=_create)
@pytest.fixture(scope='function')
def mock_delete_service_template(mocker):
def _delete(service_id, template_id):