mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Add test.
Remove else since it is not needed.
This commit is contained in:
+15
-15
@@ -200,22 +200,22 @@ def check_messages(service_id, upload_id):
|
|||||||
if request.files:
|
if request.files:
|
||||||
# The csv was invalid, validate the csv again
|
# The csv was invalid, validate the csv again
|
||||||
return send_messages(service_id, template_id)
|
return send_messages(service_id, template_id)
|
||||||
else:
|
|
||||||
original_file_name = upload_data.get('original_file_name')
|
|
||||||
notification_count = upload_data.get('notification_count')
|
|
||||||
session.pop('upload_data')
|
|
||||||
try:
|
|
||||||
job_api_client.create_job(upload_id, service_id, template_id, original_file_name, notification_count)
|
|
||||||
except HTTPError as e:
|
|
||||||
if e.status_code == 404:
|
|
||||||
abort(404)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
flash('We’ve started sending your messages', 'default_with_tick')
|
original_file_name = upload_data.get('original_file_name')
|
||||||
return redirect(
|
notification_count = upload_data.get('notification_count')
|
||||||
url_for('main.view_job', service_id=service_id, job_id=upload_id)
|
session.pop('upload_data')
|
||||||
)
|
try:
|
||||||
|
job_api_client.create_job(upload_id, service_id, template_id, original_file_name, notification_count)
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.status_code == 404:
|
||||||
|
abort(404)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
flash('We’ve started sending your messages', 'default_with_tick')
|
||||||
|
return redirect(
|
||||||
|
url_for('main.view_job', service_id=service_id, job_id=upload_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_filedata(file):
|
def _get_filedata(file):
|
||||||
|
|||||||
@@ -257,3 +257,35 @@ def test_create_job_should_call_api(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert 'We’ve started sending your messages' in response.get_data(as_text=True)
|
assert 'We’ve started sending your messages' in response.get_data(as_text=True)
|
||||||
mock_create_job.assert_called_with(job_id, service_id, template_id, original_file_name, notification_count)
|
mock_create_job.assert_called_with(job_id, service_id, template_id, original_file_name, notification_count)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_messages_should_revalidate_file_when_uploading_file(
|
||||||
|
app_,
|
||||||
|
service_one,
|
||||||
|
api_user_active,
|
||||||
|
mock_login,
|
||||||
|
mock_get_service,
|
||||||
|
job_data,
|
||||||
|
mock_create_job,
|
||||||
|
mock_get_service_template,
|
||||||
|
mock_s3_upload,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
|
||||||
|
service_id = service_one['id']
|
||||||
|
contents = 'phone number,name,,,\n++44 7700 900981,test1,,,\n+44 7700 900981,test2,,,\n ,,, \n ,,, \t \t \n'
|
||||||
|
file_data = (BytesIO(contents.encode('utf-8')), 'invalid.csv')
|
||||||
|
upload_data = {'file': file_data}
|
||||||
|
|
||||||
|
mocker.patch('app.main.views.send.s3download', return_value=contents)
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(api_user_active)
|
||||||
|
with client.session_transaction() as session:
|
||||||
|
session['upload_data'] = {'original_file_name': 'invalid.csv',
|
||||||
|
'template_id': job_data['template'],
|
||||||
|
'notification_count': job_data['notification_count']}
|
||||||
|
url = url_for('main.check_messages', service_id=service_id, upload_id=job_data['id'])
|
||||||
|
response = client.post(url, data=upload_data, follow_redirects=True)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert 'Your CSV file contained missing or invalid data' in response.get_data(as_text=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user