From d53b4bd7cd1d1bdd6acbbcf1ad837680901de7b6 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Mon, 6 Jun 2016 16:38:55 +0100 Subject: [PATCH] Bug fixed when sending yourself a test the back button links to the correct url. Remove traceback. --- app/main/views/send.py | 4 +- tests/app/main/views/test_send.py | 63 +++++++++++++++++++++++++++++++ tests/conftest.py | 14 +++++++ 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index a850c6ac1..0070ec048 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -205,7 +205,6 @@ def send_from_api(service_id, template_id): @login_required @user_has_permissions('send_texts', 'send_emails', 'send_letters') def check_messages(service_id, template_type, upload_id): - if not session.get('upload_data'): return redirect(url_for('main.choose_template', service_id=service_id, template_type=template_type)) @@ -239,8 +238,9 @@ def check_messages(service_id, template_type, upload_id): ) if request.args.get('from_test') and len(template.placeholders): + extra_args = {'help': 1} if request.args.get('help') else {} back_link = url_for( - '.send_test', service_id=service_id, template_id=template.id, help=1 if request.args.get('help') else 0 + '.send_test', service_id=service_id, template_id=template.id, **extra_args ) else: back_link = url_for('.send_messages', service_id=service_id, template_id=template.id) diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index c4bedf428..fdee927f4 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -591,3 +591,66 @@ def test_route_choose_template_manage_api_keys_permissions(mocker, service_id=service_one['id'], template_id=template_id))) assert len(links) == 1 + + +def test_check_messages_back_link_with_help(app_, + api_user_active, + mock_login, + mock_get_user_by_email, + mock_get_users_by_service, + mock_get_service, + mock_get_service_template_with_placeholders, + mock_has_permissions, + mock_get_service_statistics, + mock_s3_download, + fake_uuid): + 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': 'valid.csv', + 'template_id': fake_uuid, + 'notification_count': 1, + 'valid': True} + response = client.get(url_for( + 'main.check_messages', + service_id=fake_uuid, + upload_id=fake_uuid, + template_type='sms', + from_test=True, + help=2) + ) + assert response.status_code == 200 + content = response.get_data(as_text=True) + assert url_for('.send_test', service_id=fake_uuid, template_id=fake_uuid, help=1) in content + + +def test_check_messages_back_link_without_help(app_, + api_user_active, + mock_login, + mock_get_user_by_email, + mock_get_users_by_service, + mock_get_service, + mock_get_service_template_with_placeholders, + mock_has_permissions, + mock_get_service_statistics, + mock_s3_download, + fake_uuid): + 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': 'valid.csv', + 'template_id': fake_uuid, + 'notification_count': 1, + 'valid': True} + response = client.get(url_for( + 'main.check_messages', + service_id=fake_uuid, + upload_id=fake_uuid, + template_type='sms', + from_test=True) + ) + assert response.status_code == 200 + content = response.get_data(as_text=True) + assert url_for('.send_test', service_id=fake_uuid, template_id=fake_uuid) in content diff --git a/tests/conftest.py b/tests/conftest.py index caa401010..e7e35c729 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -891,6 +891,20 @@ def mock_s3_upload(mocker): return mocker.patch('app.main.views.send.s3upload', side_effect=_upload) +@pytest.fixture(scope='function') +def mock_s3_download(mocker, content=None): + if not content: + content = """ + phone number,name + +447700900986,John + +447700900986,Smith + """ + + def _download(service_id, upload_id): + return content + return mocker.patch('app.main.views.send.s3download', side_effect=_download) + + @pytest.fixture(scope='function') def sample_invite(mocker, service_one, status='pending'): id_ = str(generate_uuid())