mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-20 13:12:27 -04:00
Only check on csv is the file extension.
Update validator logic Update message for the validator.
This commit is contained in:
@@ -20,8 +20,8 @@ class CsvFileValidator(object):
|
||||
self.message = message
|
||||
|
||||
def __call__(self, form, field):
|
||||
if not form.file.data.mimetype == 'text/csv':
|
||||
raise ValidationError(self.message)
|
||||
if not field.data.filename.lower().endswith('.csv'):
|
||||
raise ValidationError("{} is not a CSV file".format(field.data.filename))
|
||||
|
||||
|
||||
class ValidEmailDomainRegex(object):
|
||||
|
||||
@@ -51,6 +51,32 @@ def test_upload_csvfile_with_errors_shows_check_page_with_errors(
|
||||
assert 'Re-upload your file' in content
|
||||
|
||||
|
||||
def test_upload_csv_invalid_extension(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_service_template,
|
||||
mock_s3_upload,
|
||||
mock_has_permissions,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
fake_uuid):
|
||||
contents = u'phone number,name\n+44 123,test1\n+44 456,test2'
|
||||
with app_.test_request_context():
|
||||
filename = 'invalid.txt'
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
resp = client.post(
|
||||
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
||||
data={'file': (BytesIO(contents.encode('utf-8')), filename)},
|
||||
content_type='multipart/form-data',
|
||||
follow_redirects=True
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert "{} is not a CSV file".format(filename) in resp.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_send_test_sms_message_to_self(
|
||||
app_,
|
||||
mocker,
|
||||
|
||||
@@ -635,7 +635,7 @@ def mock_get_no_api_keys(mocker):
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_login(mocker, mock_get_user, mock_update_user):
|
||||
def mock_login(mocker, mock_get_user, mock_update_user, mock_events):
|
||||
def _verify_code(user_id, code, code_type):
|
||||
return True, ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user