Fixed tests

This commit is contained in:
venusbb
2017-09-22 23:09:44 +01:00
parent 0895717680
commit b0e267f677
3 changed files with 63 additions and 38 deletions

View File

@@ -216,9 +216,6 @@ def get_dashboard_partials(service_id):
] ]
service = service_api_client.get_detailed_service(service_id) service = service_api_client.get_detailed_service(service_id)
# import pdb
# pdb.set_trace()
return { return {
'upcoming': render_template( 'upcoming': render_template(
'views/dashboard/_upcoming.html', 'views/dashboard/_upcoming.html',

View File

@@ -21,7 +21,8 @@ def platform_admin():
form = DateFilterForm(request.args) form = DateFilterForm(request.args)
api_args = {'detailed': True, api_args = {'detailed': True,
'only_active': False, # specifically DO get inactive services 'only_active': False, # specifically DO get inactive services
'include_from_test_key': form.include_from_test_key.data 'include_from_test_key': form.include_from_test_key.data,
'trial_mode_services': None
} }
if form.start_date.data: if form.start_date.data:
@@ -106,8 +107,7 @@ def create_global_stats(services):
'requested': 0 'requested': 0
} }
} }
# import pdb
# pdb.set_trace()
for service in services: for service in services:
for msg_type, status in itertools.product(('sms', 'email'), ('delivered', 'failed', 'requested')): for msg_type, status in itertools.product(('sms', 'email'), ('delivered', 'failed', 'requested')):
stats[msg_type][status] += service['statistics'][msg_type][status] stats[msg_type][status] += service['statistics'][msg_type][status]

View File

@@ -9,6 +9,8 @@ from tests import service_json
from app.main.views.platform_admin import format_stats_by_service, create_global_stats, sum_service_usage from app.main.views.platform_admin import format_stats_by_service, create_global_stats, sum_service_usage
from unittest.mock import ANY
@pytest.mark.parametrize('endpoint', [ @pytest.mark.parametrize('endpoint', [
'main.platform_admin', 'main.platform_admin',
@@ -68,7 +70,10 @@ def test_should_show_research_and_restricted_mode(
response = client.get(url_for(endpoint)) response = client.get(url_for(endpoint))
assert response.status_code == 200 assert response.status_code == 200
mock_get_detailed_services.assert_called_once_with({'detailed': True, 'include_from_test_key': True}) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'include_from_test_key': True,
'only_active': False,
'trial_mode_services': ANY})
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
# get first column in second row, which contains flags as text. # get first column in second row, which contains flags as text.
table_body = page.find_all('table')[0].find_all('tbody')[0] table_body = page.find_all('table')[0].find_all('tbody')[0]
@@ -76,9 +81,9 @@ def test_should_show_research_and_restricted_mode(
assert service_mode == displayed assert service_mode == displayed
@pytest.mark.parametrize('endpoint, expected_services_shown', [ @pytest.mark.parametrize('endpoint, expected_services_shown, trial_mode_services', [
('main.live_services', 1), ('main.live_services', 1, False),
('main.trial_services', 1), ('main.trial_services', 1, True),
]) ])
def test_should_render_platform_admin_page( def test_should_render_platform_admin_page(
client, client,
@@ -87,6 +92,7 @@ def test_should_render_platform_admin_page(
mock_get_detailed_services, mock_get_detailed_services,
endpoint, endpoint,
expected_services_shown, expected_services_shown,
trial_mode_services,
): ):
mock_get_user(mocker, user=platform_admin_user) mock_get_user(mocker, user=platform_admin_user)
client.login(platform_admin_user) client.login(platform_admin_user)
@@ -94,46 +100,54 @@ def test_should_render_platform_admin_page(
assert response.status_code == 200 assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert len(page.select('tbody tr')) == expected_services_shown * 2 # one row for SMS, one for email assert len(page.select('tbody tr')) == expected_services_shown * 2 # one row for SMS, one for email
mock_get_detailed_services.assert_called_once_with({'detailed': True, 'include_from_test_key': True}) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'include_from_test_key': True,
'only_active': False,
'trial_mode_services': trial_mode_services})
@pytest.mark.parametrize('endpoint', [ @pytest.mark.parametrize('endpoint, trial_mode_services', [
'main.platform_admin', ('main.platform_admin', None),
'main.live_services', ('main.live_services', False),
'main.trial_services', ('main.trial_services', True),
]) ])
@pytest.mark.parametrize('include_from_test_key, api_args', [ @pytest.mark.parametrize('include_from_test_key, inc', [
("Y", {'detailed': True, 'include_from_test_key': True}), ("Y", True),
("N", {'detailed': True, 'include_from_test_key': False}) ("N", False)
]) ])
def test_platform_admin_toggle_including_from_test_key( def test_platform_admin_toggle_including_from_test_key(
include_from_test_key, include_from_test_key,
api_args,
client, client,
platform_admin_user, platform_admin_user,
mocker, mocker,
mock_get_detailed_services, mock_get_detailed_services,
endpoint, endpoint,
trial_mode_services,
inc
): ):
mock_get_user(mocker, user=platform_admin_user) mock_get_user(mocker, user=platform_admin_user)
client.login(platform_admin_user) client.login(platform_admin_user)
response = client.get(url_for(endpoint, include_from_test_key=include_from_test_key)) response = client.get(url_for(endpoint, include_from_test_key=include_from_test_key))
assert response.status_code == 200 assert response.status_code == 200
mock_get_detailed_services.assert_called_once_with(api_args) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'only_active': False,
'trial_mode_services': trial_mode_services,
'include_from_test_key': inc})
@pytest.mark.parametrize('endpoint', [ @pytest.mark.parametrize('endpoint, trial_mode_services', [
'main.platform_admin', ('main.platform_admin', None),
'main.live_services', ('main.live_services', False),
'main.trial_services', ('main.trial_services', True)
]) ])
def test_platform_admin_with_date_filter( def test_platform_admin_with_date_filter(
client, client,
platform_admin_user, platform_admin_user,
mocker, mocker,
mock_get_detailed_services, mock_get_detailed_services,
endpoint, trial_mode_services,
endpoint
): ):
mock_get_user(mocker, user=platform_admin_user) mock_get_user(mocker, user=platform_admin_user)
client.login(platform_admin_user) client.login(platform_admin_user)
@@ -144,9 +158,11 @@ def test_platform_admin_with_date_filter(
assert 'Platform admin' in resp_data assert 'Platform admin' in resp_data
mock_get_detailed_services.assert_called_once_with({ mock_get_detailed_services.assert_called_once_with({
'include_from_test_key': False, 'include_from_test_key': False,
'start_date': datetime.date(2016, 12, 20),
'end_date': datetime.date(2016, 12, 28), 'end_date': datetime.date(2016, 12, 28),
'start_date': datetime.date(2016, 12, 20),
'detailed': True, 'detailed': True,
'only_active': False,
'trial_mode_services': trial_mode_services,
}) })
@@ -292,14 +308,15 @@ def test_format_stats_by_service_returns_correct_values(fake_uuid):
assert ret[0]['stats']['sms']['failed'] == 11 assert ret[0]['stats']['sms']['failed'] == 11
@pytest.mark.parametrize('endpoint, restricted, research_mode', [ @pytest.mark.parametrize('endpoint, restricted, research_mode, trial_mode_services', [
('main.trial_services', True, False), ('main.trial_services', True, False, True),
('main.live_services', False, False) ('main.live_services', False, False, False)
]) ])
def test_should_show_email_and_sms_stats_for_all_service_types( def test_should_show_email_and_sms_stats_for_all_service_types(
endpoint, endpoint,
restricted, restricted,
research_mode, research_mode,
trial_mode_services,
client, client,
platform_admin_user, platform_admin_user,
mocker, mocker,
@@ -322,7 +339,10 @@ def test_should_show_email_and_sms_stats_for_all_service_types(
response = client.get(url_for(endpoint)) response = client.get(url_for(endpoint))
assert response.status_code == 200 assert response.status_code == 200
mock_get_detailed_services.assert_called_once_with({'detailed': True, 'include_from_test_key': True}) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'include_from_test_key': True,
'trial_mode_services': trial_mode_services,
'only_active': ANY})
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
table_body = page.find_all('table')[0].find_all('tbody')[0] table_body = page.find_all('table')[0].find_all('tbody')[0]
@@ -340,12 +360,13 @@ def test_should_show_email_and_sms_stats_for_all_service_types(
assert sms_failed == 11 assert sms_failed == 11
@pytest.mark.parametrize('endpoint, restricted', [ @pytest.mark.parametrize('endpoint, restricted, trial_mode_services', [
('main.live_services', False), ('main.live_services', False, False),
('main.trial_services', True) ('main.trial_services', True, True)
], ids=['live', 'trial']) ], ids=['live', 'trial'])
def test_should_show_archived_services_last( def test_should_show_archived_services_last(
endpoint, endpoint,
trial_mode_services,
client, client,
platform_admin_user, platform_admin_user,
mocker, mocker,
@@ -367,7 +388,10 @@ def test_should_show_archived_services_last(
response = client.get(url_for(endpoint)) response = client.get(url_for(endpoint))
assert response.status_code == 200 assert response.status_code == 200
mock_get_detailed_services.assert_called_once_with({'detailed': True, 'include_from_test_key': True}) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'include_from_test_key': True,
'only_active': ANY,
'trial_mode_services': trial_mode_services})
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
table_body = page.find_all('table')[0].find_all('tbody')[0] table_body = page.find_all('table')[0].find_all('tbody')[0]
@@ -438,14 +462,15 @@ def test_should_show_correct_sent_totals_for_platform_admin(
assert sms_total == 40 assert sms_total == 40
@pytest.mark.parametrize('endpoint, restricted, research_mode', [ @pytest.mark.parametrize('endpoint, restricted, research_mode, trial_mode_services', [
('main.trial_services', True, False), ('main.trial_services', True, False, True),
('main.live_services', False, False) ('main.live_services', False, False, False)
]) ])
def test_should_order_services_by_usage_with_inactive_last( def test_should_order_services_by_usage_with_inactive_last(
endpoint, endpoint,
restricted, restricted,
research_mode, research_mode,
trial_mode_services,
client, client,
platform_admin_user, platform_admin_user,
mocker, mocker,
@@ -490,7 +515,10 @@ def test_should_order_services_by_usage_with_inactive_last(
response = client.get(url_for(endpoint)) response = client.get(url_for(endpoint))
assert response.status_code == 200 assert response.status_code == 200
mock_get_detailed_services.assert_called_once_with({'detailed': True, 'include_from_test_key': True}) mock_get_detailed_services.assert_called_once_with({'detailed': True,
'include_from_test_key': True,
'only_active': ANY,
'trial_mode_services': trial_mode_services})
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
table_body = page.find_all('table')[0].find_all('tbody')[0] table_body = page.find_all('table')[0].find_all('tbody')[0]