mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Updated to retrieve csv upload from new bucket.
Fix test errors.
This commit is contained in:
@@ -76,8 +76,10 @@ def test_should_process_sms_job(sample_job, mocker, mock_celery_remove_job):
|
||||
mocker.patch('app.celery.tasks.create_uuid', return_value="uuid")
|
||||
|
||||
process_job(sample_job.id)
|
||||
|
||||
s3.get_job_from_s3.assert_called_once_with(sample_job.bucket_name, sample_job.id)
|
||||
s3.get_job_from_s3.assert_called_once_with(
|
||||
str(sample_job.service.id),
|
||||
str(sample_job.id)
|
||||
)
|
||||
assert encryption.encrypt.call_args[0][0]['to'] == '+441234123123'
|
||||
assert encryption.encrypt.call_args[0][0]['personalisation'] == {}
|
||||
tasks.send_sms.apply_async.assert_called_once_with(
|
||||
@@ -191,7 +193,10 @@ def test_should_process_sms_job_if_exactly_on_send_limits(notify_db,
|
||||
|
||||
process_job(job.id)
|
||||
|
||||
s3.get_job_from_s3.assert_called_once_with(job.bucket_name, job.id)
|
||||
s3.get_job_from_s3.assert_called_once_with(
|
||||
str(job.service.id),
|
||||
str(job.id)
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(job.id)
|
||||
assert job.status == 'finished'
|
||||
tasks.send_email.apply_async.assert_called_with(
|
||||
@@ -212,7 +217,10 @@ def test_should_not_create_send_task_for_empty_file(sample_job, mocker, mock_cel
|
||||
|
||||
process_job(sample_job.id)
|
||||
|
||||
s3.get_job_from_s3.assert_called_once_with(sample_job.bucket_name, sample_job.id)
|
||||
s3.get_job_from_s3.assert_called_once_with(
|
||||
str(sample_job.service.id),
|
||||
str(sample_job.id)
|
||||
)
|
||||
job = jobs_dao.dao_get_job_by_id(sample_job.id)
|
||||
assert job.status == 'finished'
|
||||
tasks.send_sms.apply_async.assert_not_called
|
||||
@@ -227,7 +235,10 @@ def test_should_process_email_job(sample_email_job, mocker, mock_celery_remove_j
|
||||
|
||||
process_job(sample_email_job.id)
|
||||
|
||||
s3.get_job_from_s3.assert_called_once_with(sample_email_job.bucket_name, sample_email_job.id)
|
||||
s3.get_job_from_s3.assert_called_once_with(
|
||||
str(sample_email_job.service.id),
|
||||
str(sample_email_job.id)
|
||||
)
|
||||
assert encryption.encrypt.call_args[0][0]['to'] == 'test@test.com'
|
||||
assert encryption.encrypt.call_args[0][0]['personalisation'] == {}
|
||||
tasks.send_email.apply_async.assert_called_once_with(
|
||||
@@ -256,8 +267,8 @@ def test_should_process_all_sms_job(sample_job,
|
||||
process_job(sample_job_with_placeholdered_template.id)
|
||||
|
||||
s3.get_job_from_s3.assert_called_once_with(
|
||||
sample_job_with_placeholdered_template.bucket_name,
|
||||
sample_job_with_placeholdered_template.id
|
||||
str(sample_job_with_placeholdered_template.service.id),
|
||||
str(sample_job_with_placeholdered_template.id)
|
||||
)
|
||||
assert encryption.encrypt.call_args[0][0]['to'] == '+441234123120'
|
||||
assert encryption.encrypt.call_args[0][0]['personalisation'] == {'name': 'chris'}
|
||||
|
||||
@@ -44,17 +44,21 @@ def sample_user(notify_db,
|
||||
notify_db_session,
|
||||
mobile_numnber="+447700900986",
|
||||
email="notify@digital.cabinet-office.gov.uk"):
|
||||
data = {
|
||||
'name': 'Test User',
|
||||
'email_address': email,
|
||||
'password': 'password',
|
||||
'mobile_number': mobile_numnber,
|
||||
'state': 'active'
|
||||
}
|
||||
usr = User.query.filter_by(email_address=email).first()
|
||||
if not usr:
|
||||
usr = User(**data)
|
||||
save_model_user(usr)
|
||||
try:
|
||||
data = {
|
||||
'name': 'Test User',
|
||||
'email_address': email,
|
||||
'password': 'password',
|
||||
'mobile_number': mobile_numnber,
|
||||
'state': 'active'
|
||||
}
|
||||
usr = User.query.filter_by(email_address=email).first()
|
||||
if not usr:
|
||||
usr = User(**data)
|
||||
save_model_user(usr)
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return usr
|
||||
|
||||
|
||||
@@ -211,14 +215,11 @@ def sample_job(notify_db,
|
||||
template = sample_template(notify_db, notify_db_session,
|
||||
service=service)
|
||||
job_id = uuid.uuid4()
|
||||
bucket_name = 'service-{}-notify'.format(service.id)
|
||||
file_name = '{}.csv'.format(job_id)
|
||||
data = {
|
||||
'id': uuid.uuid4(),
|
||||
'service_id': service.id,
|
||||
'service': service,
|
||||
'template_id': template.id,
|
||||
'bucket_name': bucket_name,
|
||||
'file_name': file_name,
|
||||
'original_file_name': 'some.csv',
|
||||
'notification_count': notification_count,
|
||||
'created_at': created_at
|
||||
@@ -255,14 +256,11 @@ def sample_email_job(notify_db,
|
||||
notify_db_session,
|
||||
service=service)
|
||||
job_id = uuid.uuid4()
|
||||
bucket_name = 'service-{}-notify'.format(service.id)
|
||||
file_name = '{}.csv'.format(job_id)
|
||||
data = {
|
||||
'id': uuid.uuid4(),
|
||||
'service_id': service.id,
|
||||
'service': service,
|
||||
'template_id': template.id,
|
||||
'bucket_name': bucket_name,
|
||||
'file_name': file_name,
|
||||
'original_file_name': 'some.csv',
|
||||
'notification_count': 1
|
||||
}
|
||||
|
||||
@@ -15,14 +15,10 @@ def test_create_job(sample_template):
|
||||
assert Job.query.count() == 0
|
||||
|
||||
job_id = uuid.uuid4()
|
||||
bucket_name = 'service-{}-notify'.format(sample_template.service.id)
|
||||
file_name = '{}.csv'.format(job_id)
|
||||
data = {
|
||||
'id': job_id,
|
||||
'service_id': sample_template.service.id,
|
||||
'template_id': sample_template.id,
|
||||
'bucket_name': bucket_name,
|
||||
'file_name': file_name,
|
||||
'original_file_name': 'some.csv',
|
||||
'notification_count': 1
|
||||
}
|
||||
|
||||
@@ -99,8 +99,6 @@ def test_create_job(notify_api, sample_template, mocker):
|
||||
'service': str(sample_template.service.id),
|
||||
'template': sample_template.id,
|
||||
'original_file_name': 'thisisatest.csv',
|
||||
'bucket_name': 'service-{}-notify'.format(sample_template.service.id),
|
||||
'file_name': '{}.csv'.format(job_id),
|
||||
'notification_count': 1
|
||||
}
|
||||
path = '/service/{}/job'.format(sample_template.service.id)
|
||||
@@ -153,10 +151,8 @@ def test_create_job_returns_400_if_missing_data(notify_api, sample_template, moc
|
||||
app.celery.tasks.process_job.apply_async.assert_not_called()
|
||||
assert resp_json['result'] == 'error'
|
||||
assert 'Missing data for required field.' in resp_json['message']['original_file_name']
|
||||
assert 'Missing data for required field.' in resp_json['message']['file_name']
|
||||
assert 'Missing data for required field.' in resp_json['message']['notification_count']
|
||||
assert 'Missing data for required field.' in resp_json['message']['id']
|
||||
assert 'Missing data for required field.' in resp_json['message']['bucket_name']
|
||||
|
||||
|
||||
def test_create_job_returns_404_if_missing_service(notify_api, sample_template, mocker):
|
||||
|
||||
Reference in New Issue
Block a user