Fix re-uploading of CSV files

The problem
---

1. Upload a CSV with problems
2. See the validation errors on the page
3. Try to re-upload the file
4. Get this error:

> Method Not Allowed
> The method is not allowed for the requested URL.

https://www.pivotaltracker.com/story/show/116882241

The cause
---
The POST route for the check page (where you see errors in your files)
was removed here:
f3fd5f6b15 (diff-1dd8b3bf53dfd9382c7721051f3d930dR280)

The fix
---
This commit adds:
- a simple route which re-calls the initial ‘I have uploaded a file’ route
- a test to make sure that both of these routes are POSTed to
This commit is contained in:
Chris Hill-Scott
2016-04-05 08:55:43 +01:00
parent 6992041027
commit c95123914a
2 changed files with 26 additions and 8 deletions

View File

@@ -25,19 +25,26 @@ def test_upload_csvfile_with_errors_shows_check_page_with_errors(
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.post(
initial_upload = client.post(
url_for('main.send_messages', service_id=12345, template_id=54321),
data={'file': (BytesIO(contents.encode('utf-8')), 'invalid.csv')},
content_type='multipart/form-data',
follow_redirects=True
)
assert response.status_code == 200
content = response.get_data(as_text=True)
assert 'There was a problem with invalid.csv' in content
assert '+44 123' in content
assert '+44 456' in content
assert 'Not a UK mobile number' in content
assert 'Re-upload your file' in content
reupload = client.post(
url_for('main.check_messages', service_id=12345, template_type='sms', upload_id='abc123'),
data={'file': (BytesIO(contents.encode('utf-8')), 'invalid.csv')},
content_type='multipart/form-data',
follow_redirects=True
)
for response in [initial_upload, reupload]:
assert response.status_code == 200
content = response.get_data(as_text=True)
assert 'There was a problem with invalid.csv' in content
assert '+44 123' in content
assert '+44 456' in content
assert 'Not a UK mobile number' in content
assert 'Re-upload your file' in content
def test_send_test_sms_message_to_self(