From 3e5deeffdb97f9baf92dc4e35dcd65e0c878e4a6 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 7 Dec 2017 15:42:58 +0000 Subject: [PATCH] Split successful upload test into two MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Easier to test the individual aspects of what’s going on here if they’re two separate tests, one hitting the initial `POST`, and one hitting the page that they’re subsequently redirected to. --- tests/app/main/views/test_send.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index c148d03cb..6cba9b778 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -440,7 +440,21 @@ def test_upload_csv_invalid_extension( assert "invalid.txt isn’t a spreadsheet that Notify can read" in resp.get_data(as_text=True) -def test_upload_valid_csv_shows_file_contents( +def test_upload_valid_csv_redirects_to_check_page( + client_request, + mock_get_service_template_with_placeholders, + mock_s3_upload, + fake_uuid, +): + client_request.post( + 'main.send_messages', service_id=SERVICE_ONE_ID, template_id=fake_uuid, + _data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')}, + _expected_status=302, + expected_redirect='foo' + ) + + +def test_upload_valid_csv_shows_preview_and_table( client_request, mocker, mock_get_service_template_with_placeholders, @@ -450,16 +464,19 @@ def test_upload_valid_csv_shows_file_contents( fake_uuid, ): + with client_request.session_transaction() as session: + session['upload_data'] = {'template_id': fake_uuid} + mocker.patch('app.main.views.send.s3download', return_value=""" phone number,name,thing,thing,thing 07700900986, Jo, foo, foo, foo """) - page = client_request.post( - 'main.send_messages', service_id=SERVICE_ONE_ID, template_id=fake_uuid, - _data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')}, - _follow_redirects=True, - _expected_status=200, + page = client_request.get( + 'main.check_messages', + service_id=SERVICE_ONE_ID, + template_type='sms', + upload_id=fake_uuid, ) assert page.h1.text.strip() == 'Preview of Two week reminder'