mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Disabled the template_history endpoint
- Updated tests and added a new mock_get_monthly_template_usage - Deleted get_monthly_template_statistics_for_service - Added new test to test the redirection of the old endpoint
This commit is contained in:
@@ -81,7 +81,7 @@ def template_history(service_id):
|
|||||||
|
|
||||||
@main.route("/services/<service_id>/template-usage")
|
@main.route("/services/<service_id>/template-usage")
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions(admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def template_usage(service_id):
|
def template_usage(service_id):
|
||||||
|
|
||||||
year, current_financial_year = requested_and_current_financial_year(request)
|
year, current_financial_year = requested_and_current_financial_year(request)
|
||||||
|
|||||||
@@ -20,12 +20,6 @@ class TemplateStatisticsApiClient(NotifyAdminAPIClient):
|
|||||||
params=params
|
params=params
|
||||||
)['data']
|
)['data']
|
||||||
|
|
||||||
def get_monthly_template_statistics_for_service(self, service_id, year):
|
|
||||||
|
|
||||||
return self.get(
|
|
||||||
url='/service/{}/notifications/templates/monthly?year={}'.format(service_id, year)
|
|
||||||
)['data']
|
|
||||||
|
|
||||||
def get_monthly_template_usage_for_service(self, service_id, year):
|
def get_monthly_template_usage_for_service(self, service_id, year):
|
||||||
|
|
||||||
return self.get(
|
return self.get(
|
||||||
|
|||||||
@@ -359,17 +359,33 @@ def test_should_show_recent_templates_on_dashboard(
|
|||||||
partial(url_for),
|
partial(url_for),
|
||||||
partial(url_for, year='2016'),
|
partial(url_for, year='2016'),
|
||||||
])
|
])
|
||||||
def test_should_show_monthly_breakdown_of_template_usage(
|
def test_should_show_redirect_from_template_history(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
mock_get_monthly_template_statistics,
|
partial_url,
|
||||||
partial_url,
|
|
||||||
):
|
):
|
||||||
response = logged_in_client.get(
|
response = logged_in_client.get(
|
||||||
partial_url('main.template_history', service_id=SERVICE_ONE_ID, _external=True)
|
partial_url('main.template_history', service_id=SERVICE_ONE_ID, _external=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 301
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-07-01 12:00") # 4 months into 2016 financial year
|
||||||
|
@pytest.mark.parametrize('partial_url', [
|
||||||
|
partial(url_for),
|
||||||
|
partial(url_for, year='2016'),
|
||||||
|
])
|
||||||
|
def test_should_show_monthly_breakdown_of_template_usage(
|
||||||
|
logged_in_client,
|
||||||
|
mock_get_monthly_template_usage,
|
||||||
|
partial_url,
|
||||||
|
):
|
||||||
|
response = logged_in_client.get(
|
||||||
|
partial_url('main.template_usage', service_id=SERVICE_ONE_ID, _external=True)
|
||||||
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
mock_get_monthly_template_statistics.assert_called_once_with(SERVICE_ONE_ID, 2016)
|
mock_get_monthly_template_usage.assert_called_once_with(SERVICE_ONE_ID, 2016)
|
||||||
|
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
table_rows = page.select('tbody tr')
|
table_rows = page.select('tbody tr')
|
||||||
|
|||||||
+10
-14
@@ -2001,22 +2001,18 @@ def mock_get_template_statistics(mocker, service_one, fake_uuid):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_monthly_template_statistics(mocker, service_one, fake_uuid):
|
def mock_get_monthly_template_usage(mocker, service_one, fake_uuid):
|
||||||
def _stats(service_id, year):
|
def _stats(service_id, year):
|
||||||
return {
|
return [{
|
||||||
datetime.utcnow().strftime('%Y-%m'): {
|
"template_id": fake_uuid,
|
||||||
fake_uuid: {
|
"month": 4,
|
||||||
"counts": {
|
"year": year,
|
||||||
"sending": 1,
|
"count": 2,
|
||||||
"delivered": 1,
|
"name": 'My first template',
|
||||||
},
|
"type": 'sms'
|
||||||
"name": 'My first template',
|
}]
|
||||||
"type": 'sms',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
'app.template_statistics_client.get_monthly_template_statistics_for_service',
|
'app.template_statistics_client.get_monthly_template_usage_for_service',
|
||||||
side_effect=_stats
|
side_effect=_stats
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user