2016-04-06 15:48:04 +01:00
|
|
|
import copy
|
2016-03-17 10:46:47 +00:00
|
|
|
from flask import url_for
|
2016-04-05 11:40:13 +01:00
|
|
|
|
2016-04-06 15:06:02 +01:00
|
|
|
from bs4 import BeautifulSoup
|
2016-06-19 09:04:21 +01:00
|
|
|
from freezegun import freeze_time
|
2016-04-06 15:06:02 +01:00
|
|
|
|
2016-03-23 12:15:57 +00:00
|
|
|
from tests import validate_route_permission
|
2016-04-05 11:40:13 +01:00
|
|
|
from tests.conftest import SERVICE_ONE_ID
|
2015-12-18 10:26:56 +00:00
|
|
|
|
2016-01-06 16:51:35 +00:00
|
|
|
|
2016-04-06 15:48:04 +01:00
|
|
|
stub_template_stats = [
|
|
|
|
|
{
|
|
|
|
|
'template': {
|
|
|
|
|
'name': 'Brine Shrimp',
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
'id': 1
|
|
|
|
|
},
|
|
|
|
|
'id': '6005e192-4738-4962-beec-ebd982d0b03f',
|
|
|
|
|
'day': '2016-04-06',
|
|
|
|
|
'usage_count': 6,
|
|
|
|
|
'service': '1491b86f-c950-48f5-bed1-2a55df027ecb'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'template': {
|
|
|
|
|
'name': 'Pickle feet',
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
'id': 2
|
|
|
|
|
},
|
|
|
|
|
'id': '0bd529cd-a0fd-43e5-80ee-b95ef6b0d51f',
|
|
|
|
|
'day': '2016-04-06',
|
|
|
|
|
'usage_count': 6,
|
|
|
|
|
'service': '1491b86f-c950-48f5-bed1-2a55df027ecb'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'template': {
|
|
|
|
|
'name': 'Brine Shrimp',
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
'id': 1
|
|
|
|
|
},
|
|
|
|
|
'id': '24531628-ffff-4082-a443-9f6db5af83d9',
|
|
|
|
|
'day': '2016-04-05',
|
|
|
|
|
'usage_count': 7,
|
|
|
|
|
'service': '1491b86f-c950-48f5-bed1-2a55df027ecb'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'template': {
|
|
|
|
|
'name': 'Pickle feet',
|
|
|
|
|
'template_type': 'sms',
|
|
|
|
|
'id': 2
|
|
|
|
|
},
|
|
|
|
|
'id': '0bd529cd-a0fd-43e5-80ee-b95ef6b0d51f',
|
|
|
|
|
'day': '2016-03-06',
|
|
|
|
|
'usage_count': 200,
|
|
|
|
|
'service': '1491b86f-c950-48f5-bed1-2a55df027ecb'
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 13:04:25 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2016-04-06 15:06:02 +01:00
|
|
|
def test_should_show_recent_templates_on_dashboard(app_,
|
2016-04-06 15:48:04 +01:00
|
|
|
mocker,
|
2016-04-06 15:06:02 +01:00
|
|
|
api_user_active,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_service_statistics,
|
2016-05-03 13:25:22 +01:00
|
|
|
mock_get_aggregate_service_statistics,
|
2016-04-06 15:06:02 +01:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_jobs,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_has_permissions,
|
|
|
|
|
mock_get_usage):
|
2016-04-06 15:48:04 +01:00
|
|
|
|
|
|
|
|
mock_template_stats = mocker.patch('app.template_statistics_client.get_template_statistics_for_service',
|
|
|
|
|
return_value=copy.deepcopy(stub_template_stats))
|
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-04-05 11:40:13 +01:00
|
|
|
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
|
2016-01-06 16:51:35 +00:00
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2016-04-06 15:48:04 +01:00
|
|
|
response.get_data(as_text=True)
|
2016-04-19 17:02:49 +01:00
|
|
|
mock_get_service_statistics.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
|
2016-04-20 13:59:24 +01:00
|
|
|
mock_template_stats.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
2016-04-06 15:06:02 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
2016-05-03 13:25:22 +01:00
|
|
|
headers = [header.text.strip() for header in page.find_all('h2') + page.find_all('h1')]
|
2016-04-06 15:06:02 +01:00
|
|
|
assert 'Test Service' in headers
|
2016-04-19 12:57:55 +01:00
|
|
|
assert 'In the last 7 days' in headers
|
2016-05-11 15:05:40 +01:00
|
|
|
|
2016-06-17 15:03:34 +01:00
|
|
|
table_rows = page.find_all('tbody')[0].find_all('tr')
|
2016-04-06 15:48:04 +01:00
|
|
|
|
|
|
|
|
assert len(table_rows) == 2
|
2016-04-20 14:09:38 +01:00
|
|
|
|
2016-06-17 15:03:34 +01:00
|
|
|
assert 'Pickle feet' in table_rows[0].find_all('th')[0].text
|
|
|
|
|
assert 'Text message template' in table_rows[0].find_all('th')[0].text
|
|
|
|
|
assert '206' in table_rows[0].find_all('td')[0].text
|
2016-05-11 15:05:40 +01:00
|
|
|
|
2016-06-17 15:03:34 +01:00
|
|
|
assert 'Brine Shrimp' in table_rows[1].find_all('th')[0].text
|
|
|
|
|
assert 'Text message template' in table_rows[1].find_all('th')[0].text
|
|
|
|
|
assert '13' in table_rows[1].find_all('td')[0].text
|
2016-04-20 14:09:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_all_templates_on_template_statistics_page(
|
|
|
|
|
app_,
|
|
|
|
|
mocker,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
mock_has_permissions
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
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():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for('main.template_history', service_id=SERVICE_ONE_ID))
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
response.get_data(as_text=True)
|
|
|
|
|
mock_template_stats.assert_called_once_with(SERVICE_ONE_ID)
|
|
|
|
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
2016-06-17 15:03:34 +01:00
|
|
|
table_rows = page.find_all('tbody')[0].find_all('tr')
|
2016-04-20 14:09:38 +01:00
|
|
|
|
|
|
|
|
assert len(table_rows) == 2
|
|
|
|
|
|
2016-06-17 15:03:34 +01:00
|
|
|
assert 'Pickle feet' in table_rows[0].find_all('th')[0].text
|
|
|
|
|
assert 'Text message template' in table_rows[0].find_all('th')[0].text
|
|
|
|
|
assert '206' in table_rows[0].find_all('td')[0].text
|
2016-04-06 15:48:04 +01:00
|
|
|
|
2016-06-17 15:03:34 +01:00
|
|
|
assert 'Brine Shrimp' in table_rows[1].find_all('th')[0].text
|
|
|
|
|
assert 'Text message template' in table_rows[1].find_all('th')[0].text
|
|
|
|
|
assert '13' in table_rows[1].find_all('td')[0].text
|
2016-04-06 15:06:02 +01:00
|
|
|
|
2016-03-09 12:10:50 +00:00
|
|
|
|
2016-06-19 09:04:21 +01:00
|
|
|
@freeze_time("2016-01-01 11:09:00.061258")
|
|
|
|
|
def test_should_show_recent_jobs_on_dashboard(
|
|
|
|
|
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_template_statistics,
|
|
|
|
|
mock_get_jobs,
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
mock_get_usage
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
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_jobs.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
table_rows = page.find_all('tbody')[1].find_all('tr')
|
|
|
|
|
|
|
|
|
|
assert "Test message" not in page.text
|
|
|
|
|
assert len(table_rows) == 4
|
|
|
|
|
|
|
|
|
|
for index, filename in enumerate((
|
|
|
|
|
"export 1/1/2016.xls",
|
|
|
|
|
"all email addresses.xlsx",
|
|
|
|
|
"applicants.ods",
|
|
|
|
|
"thisisatest.csv",
|
|
|
|
|
)):
|
2016-06-20 10:07:37 +01:00
|
|
|
assert filename in table_rows[index].find_all('th')[0].text
|
|
|
|
|
assert 'Uploaded 1 January at 11:09' in table_rows[index].find_all('th')[0].text
|
2016-06-19 09:04:21 +01:00
|
|
|
for column_index, count in enumerate((1, 0, 0)):
|
|
|
|
|
assert table_rows[index].find_all('td')[column_index].text.strip() == str(count)
|
|
|
|
|
|
|
|
|
|
|
2016-03-09 12:10:50 +00:00
|
|
|
def _test_dashboard_menu(mocker, app_, usr, service, permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
usr._permissions[str(service['id'])] = permissions
|
2016-03-30 09:31:53 +01:00
|
|
|
mocker.patch('app.user_api_client.check_verify_code', return_value=(True, ''))
|
|
|
|
|
mocker.patch('app.service_api_client.get_services', return_value={'data': [service]})
|
2016-03-09 12:10:50 +00:00
|
|
|
mocker.patch('app.user_api_client.get_user', return_value=usr)
|
|
|
|
|
mocker.patch('app.user_api_client.get_user_by_email', return_value=usr)
|
2016-03-17 10:46:47 +00:00
|
|
|
mocker.patch('app.service_api_client.get_service', return_value={'data': service})
|
2016-03-17 11:45:48 +00:00
|
|
|
mocker.patch('app.statistics_api_client.get_statistics_for_service', return_value={'data': [{}]})
|
2016-03-09 12:10:50 +00:00
|
|
|
client.login(usr)
|
|
|
|
|
return client.get(url_for('main.service_dashboard', service_id=service['id']))
|
|
|
|
|
|
|
|
|
|
|
2016-04-05 11:40:13 +01:00
|
|
|
def test_menu_send_messages(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_jobs,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_get_template_statistics,
|
|
|
|
|
mock_get_usage):
|
2016-04-05 11:40:13 +01:00
|
|
|
|
2016-03-09 12:10:50 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
resp = _test_dashboard_menu(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
2016-03-29 13:23:36 +01:00
|
|
|
['view_activity', 'send_texts', 'send_emails', 'send_letters'])
|
2016-03-09 12:10:50 +00:00
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='email')in page
|
|
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='sms')in page
|
2016-03-21 15:25:19 +00:00
|
|
|
assert url_for('main.manage_users', service_id=service_one['id']) in page
|
2016-03-30 09:31:53 +01:00
|
|
|
assert url_for('main.documentation') in page
|
2016-03-09 12:10:50 +00:00
|
|
|
|
2016-03-30 09:31:53 +01:00
|
|
|
assert url_for('main.service_settings', service_id=service_one['id']) not in page
|
2016-03-09 12:10:50 +00:00
|
|
|
assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
2016-03-21 15:36:47 +00:00
|
|
|
assert url_for('main.show_all_services') not in page
|
2016-05-11 09:43:55 +01:00
|
|
|
assert url_for('main.view_providers') not in page
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
2016-04-05 11:40:13 +01:00
|
|
|
def test_menu_manage_service(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_jobs,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_get_template_statistics,
|
|
|
|
|
mock_get_usage):
|
2016-03-09 12:10:50 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
resp = _test_dashboard_menu(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
2016-03-29 13:23:36 +01:00
|
|
|
['view_activity', 'manage_users', 'manage_templates', 'manage_settings'])
|
2016-03-09 12:10:50 +00:00
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='email') in page
|
|
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='sms') in page
|
|
|
|
|
assert url_for('main.manage_users', service_id=service_one['id']) in page
|
|
|
|
|
assert url_for('main.service_settings', service_id=service_one['id']) in page
|
2016-03-30 09:31:53 +01:00
|
|
|
assert url_for('main.documentation') in page
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
2016-03-21 15:36:47 +00:00
|
|
|
assert url_for('main.show_all_services') not in page
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
2016-04-05 11:40:13 +01:00
|
|
|
def test_menu_manage_api_keys(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_jobs,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_get_template_statistics,
|
|
|
|
|
mock_get_usage):
|
2016-03-09 12:10:50 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
resp = _test_dashboard_menu(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
2016-03-29 17:33:12 +01:00
|
|
|
['view_activity', 'manage_api_keys'])
|
2016-03-09 12:10:50 +00:00
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
2016-03-18 14:43:03 +00:00
|
|
|
template_type='email') in page
|
2016-03-09 12:10:50 +00:00
|
|
|
assert url_for(
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
service_id=service_one['id'],
|
2016-03-18 14:43:03 +00:00
|
|
|
template_type='sms') in page
|
2016-03-21 15:25:19 +00:00
|
|
|
assert url_for('main.manage_users', service_id=service_one['id']) in page
|
2016-03-09 12:10:50 +00:00
|
|
|
assert url_for('main.service_settings', service_id=service_one['id']) not in page
|
2016-03-21 15:36:47 +00:00
|
|
|
assert url_for('main.show_all_services') not in page
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
assert url_for('main.api_keys', service_id=service_one['id']) in page
|
2016-03-17 10:46:47 +00:00
|
|
|
|
|
|
|
|
|
2016-04-05 11:40:13 +01:00
|
|
|
def test_menu_all_services_for_platform_admin_user(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
platform_admin_user,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_jobs,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_get_template_statistics,
|
|
|
|
|
mock_get_usage):
|
2016-03-17 10:46:47 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
resp = _test_dashboard_menu(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
platform_admin_user,
|
|
|
|
|
service_one,
|
|
|
|
|
[])
|
|
|
|
|
page = resp.get_data(as_text=True)
|
2016-03-21 15:36:47 +00:00
|
|
|
assert url_for('main.choose_template', service_id=service_one['id'], template_type='sms') in page
|
|
|
|
|
assert url_for('main.choose_template', service_id=service_one['id'], template_type='email') in page
|
|
|
|
|
assert url_for('main.manage_users', service_id=service_one['id']) in page
|
|
|
|
|
assert url_for('main.service_settings', service_id=service_one['id']) in page
|
2016-06-07 11:17:33 +01:00
|
|
|
assert url_for('main.view_notifications', service_id=service_one['id'], message_type='email') in page
|
|
|
|
|
assert url_for('main.view_notifications', service_id=service_one['id'], message_type='sms') in page
|
2016-03-21 15:36:47 +00:00
|
|
|
assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
2016-04-12 14:19:51 +01:00
|
|
|
|
2016-03-23 12:15:57 +00:00
|
|
|
|
|
|
|
|
def test_route_for_service_permissions(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
mock_get_jobs,
|
2016-04-05 11:40:13 +01:00
|
|
|
mock_get_service_statistics,
|
2016-04-20 15:37:17 +01:00
|
|
|
mock_get_template_statistics,
|
|
|
|
|
mock_get_usage):
|
2016-03-23 12:15:57 +00:00
|
|
|
routes = [
|
|
|
|
|
'main.service_dashboard']
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
# Just test that the user is part of the service
|
|
|
|
|
for route in routes:
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
"GET",
|
|
|
|
|
200,
|
|
|
|
|
url_for(
|
|
|
|
|
route,
|
|
|
|
|
service_id=service_one['id']),
|
2016-03-29 13:23:36 +01:00
|
|
|
['view_activity'],
|
2016-03-23 12:15:57 +00:00
|
|
|
api_user_active,
|
|
|
|
|
service_one)
|
2016-04-06 15:48:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_aggregate_template_stats():
|
|
|
|
|
from app.main.views.dashboard import aggregate_usage
|
|
|
|
|
expected = aggregate_usage(copy.deepcopy(stub_template_stats))
|
|
|
|
|
|
|
|
|
|
assert len(expected) == 2
|
|
|
|
|
for item in expected:
|
2016-04-12 11:42:45 +01:00
|
|
|
if item['template'].id == 1:
|
2016-04-06 15:48:04 +01:00
|
|
|
assert item['usage_count'] == 13
|
2016-04-12 11:42:45 +01:00
|
|
|
elif item['template'].id == 2:
|
2016-04-06 15:48:04 +01:00
|
|
|
assert item['usage_count'] == 206
|
2016-07-19 13:53:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_service_dashboard_updates_gets_detailed_service(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
active_user_with_permissions,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_service_statistics,
|
|
|
|
|
mock_get_usage,
|
|
|
|
|
):
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
client.login(active_user_with_permissions, mocker, service_one)
|
|
|
|
|
response = client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
# mock_get_service_statistics.assert_not_called()
|
|
|
|
|
# mock_get_service.assert_called_once_with(service_one.id, detailed=True)
|