mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 01:56:03 -04:00
Normalise whitespace and use client fixtures
Using the client fixture means that fewer nested indentation is needed. Which, along with consistent indenting, makes the code easier to read.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
@@ -17,9 +18,7 @@ from app.dao.templates_dao import dao_update_template
|
|||||||
from app.models import NOTIFICATION_STATUS_TYPES, JOB_STATUS_TYPES, JOB_STATUS_PENDING
|
from app.models import NOTIFICATION_STATUS_TYPES, JOB_STATUS_TYPES, JOB_STATUS_PENDING
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_with_invalid_service_id_returns404(notify_api, sample_service):
|
def test_get_job_with_invalid_service_id_returns404(client, sample_service):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job'.format(sample_service.id)
|
path = '/service/{}/job'.format(sample_service.id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -28,10 +27,8 @@ def test_get_job_with_invalid_service_id_returns404(notify_api, sample_service):
|
|||||||
assert len(resp_json['data']) == 0
|
assert len(resp_json['data']) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_with_invalid_job_id_returns404(notify_api, sample_template):
|
def test_get_job_with_invalid_job_id_returns404(client, sample_template):
|
||||||
service_id = sample_template.service.id
|
service_id = sample_template.service.id
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job/{}'.format(service_id, "bad-id")
|
path = '/service/{}/job/{}'.format(service_id, "bad-id")
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -41,10 +38,8 @@ def test_get_job_with_invalid_job_id_returns404(notify_api, sample_template):
|
|||||||
assert resp_json['message'] == 'No result found'
|
assert resp_json['message'] == 'No result found'
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_with_unknown_id_returns404(notify_api, sample_template, fake_uuid):
|
def test_get_job_with_unknown_id_returns404(client, sample_template, fake_uuid):
|
||||||
service_id = sample_template.service.id
|
service_id = sample_template.service.id
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job/{}'.format(service_id, fake_uuid)
|
path = '/service/{}/job/{}'.format(service_id, fake_uuid)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -56,10 +51,9 @@ def test_get_job_with_unknown_id_returns404(notify_api, sample_template, fake_uu
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_cancel_job(notify_api, sample_scheduled_job):
|
def test_cancel_job(client, sample_scheduled_job):
|
||||||
job_id = str(sample_scheduled_job.id)
|
job_id = str(sample_scheduled_job.id)
|
||||||
service_id = sample_scheduled_job.service.id
|
service_id = sample_scheduled_job.service.id
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job/{}/cancel'.format(service_id, job_id)
|
path = '/service/{}/job/{}/cancel'.format(service_id, job_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.post(path, headers=[auth_header])
|
response = client.post(path, headers=[auth_header])
|
||||||
@@ -69,10 +63,9 @@ def test_cancel_job(notify_api, sample_scheduled_job):
|
|||||||
assert resp_json['data']['job_status'] == 'cancelled'
|
assert resp_json['data']['job_status'] == 'cancelled'
|
||||||
|
|
||||||
|
|
||||||
def test_cant_cancel_normal_job(notify_api, sample_job, mocker):
|
def test_cant_cancel_normal_job(client, sample_job, mocker):
|
||||||
job_id = str(sample_job.id)
|
job_id = str(sample_job.id)
|
||||||
service_id = sample_job.service.id
|
service_id = sample_job.service.id
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
|
||||||
mock_update = mocker.patch('app.dao.jobs_dao.dao_update_job')
|
mock_update = mocker.patch('app.dao.jobs_dao.dao_update_job')
|
||||||
path = '/service/{}/job/{}/cancel'.format(service_id, job_id)
|
path = '/service/{}/job/{}/cancel'.format(service_id, job_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
@@ -81,9 +74,7 @@ def test_cant_cancel_normal_job(notify_api, sample_job, mocker):
|
|||||||
assert mock_update.call_count == 0
|
assert mock_update.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def test_create_unscheduled_job(notify_api, sample_template, mocker, fake_uuid):
|
def test_create_unscheduled_job(client, sample_template, mocker, fake_uuid):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'id': fake_uuid,
|
'id': fake_uuid,
|
||||||
@@ -119,10 +110,8 @@ def test_create_unscheduled_job(notify_api, sample_template, mocker, fake_uuid):
|
|||||||
assert resp_json['data']['original_file_name'] == 'thisisatest.csv'
|
assert resp_json['data']['original_file_name'] == 'thisisatest.csv'
|
||||||
|
|
||||||
|
|
||||||
def test_create_scheduled_job(notify_api, sample_template, mocker, fake_uuid):
|
@freeze_time("2016-01-01 12:00:00.000000")
|
||||||
with notify_api.test_request_context():
|
def test_create_scheduled_job(client, sample_template, mocker, fake_uuid):
|
||||||
with notify_api.test_client() as client:
|
|
||||||
with freeze_time("2016-01-01 12:00:00.000000"):
|
|
||||||
scheduled_date = (datetime.utcnow() + timedelta(hours=95, minutes=59)).isoformat()
|
scheduled_date = (datetime.utcnow() + timedelta(hours=95, minutes=59)).isoformat()
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
@@ -172,7 +161,8 @@ def test_create_job_returns_403_if_service_is_not_active(client, fake_uuid, samp
|
|||||||
|
|
||||||
|
|
||||||
def test_create_job_returns_403_if_letter_template_type_and_service_in_trial(
|
def test_create_job_returns_403_if_letter_template_type_and_service_in_trial(
|
||||||
client, fake_uuid, sample_trial_letter_template, mocker):
|
client, fake_uuid, sample_trial_letter_template, mocker
|
||||||
|
):
|
||||||
data = {
|
data = {
|
||||||
'id': fake_uuid,
|
'id': fake_uuid,
|
||||||
'service': str(sample_trial_letter_template.service.id),
|
'service': str(sample_trial_letter_template.service.id),
|
||||||
@@ -194,12 +184,9 @@ def test_create_job_returns_403_if_letter_template_type_and_service_in_trial(
|
|||||||
mock_job_dao.assert_not_called()
|
mock_job_dao.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_create_scheduled_job_more_then_24_hours_hence(notify_api, sample_template, mocker, fake_uuid):
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
with notify_api.test_request_context():
|
def test_should_not_create_scheduled_job_more_then_24_hours_hence(client, sample_template, mocker, fake_uuid):
|
||||||
with notify_api.test_client() as client:
|
|
||||||
with freeze_time("2016-01-01 11:09:00.061258"):
|
|
||||||
scheduled_date = (datetime.utcnow() + timedelta(hours=96, minutes=1)).isoformat()
|
scheduled_date = (datetime.utcnow() + timedelta(hours=96, minutes=1)).isoformat()
|
||||||
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'id': fake_uuid,
|
'id': fake_uuid,
|
||||||
@@ -228,12 +215,9 @@ def test_should_not_create_scheduled_job_more_then_24_hours_hence(notify_api, sa
|
|||||||
assert resp_json['message']['scheduled_for'] == ['Date cannot be more than 96hrs in the future']
|
assert resp_json['message']['scheduled_for'] == ['Date cannot be more than 96hrs in the future']
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_create_scheduled_job_in_the_past(notify_api, sample_template, mocker, fake_uuid):
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
with notify_api.test_request_context():
|
def test_should_not_create_scheduled_job_in_the_past(client, sample_template, mocker, fake_uuid):
|
||||||
with notify_api.test_client() as client:
|
|
||||||
with freeze_time("2016-01-01 11:09:00.061258"):
|
|
||||||
scheduled_date = (datetime.utcnow() - timedelta(minutes=1)).isoformat()
|
scheduled_date = (datetime.utcnow() - timedelta(minutes=1)).isoformat()
|
||||||
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'id': fake_uuid,
|
'id': fake_uuid,
|
||||||
@@ -262,9 +246,7 @@ def test_should_not_create_scheduled_job_in_the_past(notify_api, sample_template
|
|||||||
assert resp_json['message']['scheduled_for'] == ['Date cannot be in the past']
|
assert resp_json['message']['scheduled_for'] == ['Date cannot be in the past']
|
||||||
|
|
||||||
|
|
||||||
def test_create_job_returns_400_if_missing_data(notify_api, sample_template, mocker):
|
def test_create_job_returns_400_if_missing_data(client, sample_template, mocker):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'template': str(sample_template.id)
|
'template': str(sample_template.id)
|
||||||
@@ -286,9 +268,7 @@ def test_create_job_returns_400_if_missing_data(notify_api, sample_template, moc
|
|||||||
assert 'Missing data for required field.' in resp_json['message']['notification_count']
|
assert 'Missing data for required field.' in resp_json['message']['notification_count']
|
||||||
|
|
||||||
|
|
||||||
def test_create_job_returns_404_if_template_does_not_exist(notify_api, sample_service, mocker):
|
def test_create_job_returns_404_if_template_does_not_exist(client, sample_service, mocker):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'template': str(sample_service.id)
|
'template': str(sample_service.id)
|
||||||
@@ -309,9 +289,7 @@ def test_create_job_returns_404_if_template_does_not_exist(notify_api, sample_se
|
|||||||
assert resp_json['message'] == 'No result found'
|
assert resp_json['message'] == 'No result found'
|
||||||
|
|
||||||
|
|
||||||
def test_create_job_returns_404_if_missing_service(notify_api, sample_template, mocker):
|
def test_create_job_returns_404_if_missing_service(client, sample_template, mocker):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
random_id = str(uuid.uuid4())
|
random_id = str(uuid.uuid4())
|
||||||
data = {'template': str(sample_template.id)}
|
data = {'template': str(sample_template.id)}
|
||||||
@@ -331,9 +309,7 @@ def test_create_job_returns_404_if_missing_service(notify_api, sample_template,
|
|||||||
assert resp_json['message'] == 'No result found'
|
assert resp_json['message'] == 'No result found'
|
||||||
|
|
||||||
|
|
||||||
def test_create_job_returns_400_if_archived_template(notify_api, sample_template, mocker):
|
def test_create_job_returns_400_if_archived_template(client, sample_template, mocker):
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||||
sample_template.archived = True
|
sample_template.archived = True
|
||||||
dao_update_template(sample_template)
|
dao_update_template(sample_template)
|
||||||
@@ -365,11 +341,9 @@ def _setup_jobs(notify_db, notify_db_session, template, number_of_jobs=5):
|
|||||||
template=template)
|
template=template)
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_notifications_for_job_in_order_of_job_number(notify_api,
|
def test_get_all_notifications_for_job_in_order_of_job_number(
|
||||||
notify_db,
|
client, notify_db, notify_db_session, sample_service
|
||||||
notify_db_session,
|
):
|
||||||
sample_service):
|
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
|
||||||
main_job = create_job(notify_db, notify_db_session, service=sample_service)
|
main_job = create_job(notify_db, notify_db_session, service=sample_service)
|
||||||
another_job = create_job(notify_db, notify_db_session, service=sample_service)
|
another_job = create_job(notify_db, notify_db_session, service=sample_service)
|
||||||
|
|
||||||
@@ -426,14 +400,13 @@ def test_get_all_notifications_for_job_in_order_of_job_number(notify_api,
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_get_all_notifications_for_job_filtered_by_status(
|
def test_get_all_notifications_for_job_filtered_by_status(
|
||||||
notify_api,
|
client,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
sample_service,
|
sample_service,
|
||||||
expected_notification_count,
|
expected_notification_count,
|
||||||
status_args
|
status_args
|
||||||
):
|
):
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
|
||||||
job = create_job(notify_db, notify_db_session, service=sample_service)
|
job = create_job(notify_db, notify_db_session, service=sample_service)
|
||||||
|
|
||||||
create_notification(
|
create_notification(
|
||||||
@@ -487,21 +460,21 @@ def test_get_job_by_id(notify_api, sample_job):
|
|||||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_by_id_should_return_statistics(notify_db, notify_db_session, notify_api, sample_job):
|
def test_get_job_by_id_should_return_statistics(client, notify_db, notify_db_session, notify_api, sample_job):
|
||||||
job_id = str(sample_job.id)
|
job_id = str(sample_job.id)
|
||||||
service_id = sample_job.service.id
|
service_id = sample_job.service.id
|
||||||
|
partial_notification = partial(
|
||||||
|
create_notification, notify_db, notify_db_session, service=sample_job.service, job=sample_job
|
||||||
|
)
|
||||||
|
partial_notification(status='created')
|
||||||
|
partial_notification(status='sending')
|
||||||
|
partial_notification(status='delivered')
|
||||||
|
partial_notification(status='pending')
|
||||||
|
partial_notification(status='failed')
|
||||||
|
partial_notification(status='technical-failure') # noqa
|
||||||
|
partial_notification(status='temporary-failure') # noqa
|
||||||
|
partial_notification(status='permanent-failure') # noqa
|
||||||
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='created')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='sending')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='delivered')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='pending')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='failed')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='technical-failure') # noqa
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='temporary-failure') # noqa
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='permanent-failure') # noqa
|
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job/{}'.format(service_id, job_id)
|
path = '/service/{}/job/{}'.format(service_id, job_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -519,23 +492,23 @@ def test_get_job_by_id_should_return_statistics(notify_db, notify_db_session, no
|
|||||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||||
|
|
||||||
|
|
||||||
def test_get_job_by_id_should_return_summed_statistics(notify_db, notify_db_session, notify_api, sample_job):
|
def test_get_job_by_id_should_return_summed_statistics(client, notify_db, notify_db_session, notify_api, sample_job):
|
||||||
job_id = str(sample_job.id)
|
job_id = str(sample_job.id)
|
||||||
service_id = sample_job.service.id
|
service_id = sample_job.service.id
|
||||||
|
partial_notification = partial(
|
||||||
|
create_notification, notify_db, notify_db_session, service=sample_job.service, job=sample_job
|
||||||
|
)
|
||||||
|
partial_notification(status='created')
|
||||||
|
partial_notification(status='created')
|
||||||
|
partial_notification(status='created')
|
||||||
|
partial_notification(status='sending')
|
||||||
|
partial_notification(status='failed')
|
||||||
|
partial_notification(status='failed')
|
||||||
|
partial_notification(status='failed')
|
||||||
|
partial_notification(status='technical-failure')
|
||||||
|
partial_notification(status='temporary-failure')
|
||||||
|
partial_notification(status='temporary-failure')
|
||||||
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='created')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='created')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='created')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='sending')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='failed')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='failed')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='failed')
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='technical-failure') # noqa
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='temporary-failure') # noqa
|
|
||||||
create_notification(notify_db, notify_db_session, service=sample_job.service, job=sample_job, status='temporary-failure') # noqa
|
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job/{}'.format(service_id, job_id)
|
path = '/service/{}/job/{}'.format(service_id, job_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -550,13 +523,11 @@ def test_get_job_by_id_should_return_summed_statistics(notify_db, notify_db_sess
|
|||||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||||
|
|
||||||
|
|
||||||
def test_get_jobs(notify_api, notify_db, notify_db_session, sample_template):
|
def test_get_jobs(client, notify_db, notify_db_session, sample_template):
|
||||||
_setup_jobs(notify_db, notify_db_session, sample_template)
|
_setup_jobs(notify_db, notify_db_session, sample_template)
|
||||||
|
|
||||||
service_id = sample_template.service.id
|
service_id = sample_template.service.id
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job'.format(service_id)
|
path = '/service/{}/job'.format(service_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
@@ -565,7 +536,7 @@ def test_get_jobs(notify_api, notify_db, notify_db_session, sample_template):
|
|||||||
assert len(resp_json['data']) == 5
|
assert len(resp_json['data']) == 5
|
||||||
|
|
||||||
|
|
||||||
def test_get_jobs_with_limit_days(notify_api, notify_db, notify_db_session, sample_template):
|
def test_get_jobs_with_limit_days(client, notify_db, notify_db_session, sample_template):
|
||||||
create_job(
|
create_job(
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
@@ -581,8 +552,6 @@ def test_get_jobs_with_limit_days(notify_api, notify_db, notify_db_session, samp
|
|||||||
|
|
||||||
service_id = sample_template.service.id
|
service_id = sample_template.service.id
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job'.format(service_id)
|
path = '/service/{}/job'.format(service_id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header], query_string={'limit_days': 5})
|
response = client.get(path, headers=[auth_header], query_string={'limit_days': 5})
|
||||||
@@ -591,18 +560,18 @@ def test_get_jobs_with_limit_days(notify_api, notify_db, notify_db_session, samp
|
|||||||
assert len(resp_json['data']) == 1
|
assert len(resp_json['data']) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_jobs_should_return_statistics(notify_db, notify_db_session, notify_api, sample_service):
|
def test_get_jobs_should_return_statistics(client, notify_db, notify_db_session, notify_api, sample_service):
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
earlier = datetime.utcnow() - timedelta(days=1)
|
earlier = datetime.utcnow() - timedelta(days=1)
|
||||||
job_1 = create_job(notify_db, notify_db_session, service=sample_service, created_at=earlier)
|
job_1 = create_job(notify_db, notify_db_session, service=sample_service, created_at=earlier)
|
||||||
job_2 = create_job(notify_db, notify_db_session, service=sample_service, created_at=now)
|
job_2 = create_job(notify_db, notify_db_session, service=sample_service, created_at=now)
|
||||||
|
partial_notification = partial(create_notification, notify_db, notify_db_session, service=sample_service)
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_1, status='created')
|
partial_notification(job=job_1, status='created')
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_1, status='created')
|
partial_notification(job=job_1, status='created')
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_1, status='created')
|
partial_notification(job=job_1, status='created')
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_2, status='sending')
|
partial_notification(job=job_2, status='sending')
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_2, status='sending')
|
partial_notification(job=job_2, status='sending')
|
||||||
create_notification(notify_db, notify_db_session, service=sample_service, job=job_2, status='sending')
|
partial_notification(job=job_2, status='sending')
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
@@ -619,18 +588,18 @@ def test_get_jobs_should_return_statistics(notify_db, notify_db_session, notify_
|
|||||||
|
|
||||||
|
|
||||||
def test_get_jobs_should_return_no_stats_if_no_rows_in_notifications(
|
def test_get_jobs_should_return_no_stats_if_no_rows_in_notifications(
|
||||||
|
client,
|
||||||
notify_db,
|
notify_db,
|
||||||
notify_db_session,
|
notify_db_session,
|
||||||
notify_api,
|
notify_api,
|
||||||
sample_service):
|
sample_service,
|
||||||
|
):
|
||||||
|
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
earlier = datetime.utcnow() - timedelta(days=1)
|
earlier = datetime.utcnow() - timedelta(days=1)
|
||||||
job_1 = create_job(notify_db, notify_db_session, service=sample_service, created_at=earlier)
|
job_1 = create_job(notify_db, notify_db_session, service=sample_service, created_at=earlier)
|
||||||
job_2 = create_job(notify_db, notify_db_session, service=sample_service, created_at=now)
|
job_2 = create_job(notify_db, notify_db_session, service=sample_service, created_at=now)
|
||||||
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
path = '/service/{}/job'.format(sample_service.id)
|
path = '/service/{}/job'.format(sample_service.id)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
response = client.get(path, headers=[auth_header])
|
response = client.get(path, headers=[auth_header])
|
||||||
|
|||||||
Reference in New Issue
Block a user