From 71b00c20981eccf92ab7af0dc311543f077e327f Mon Sep 17 00:00:00 2001 From: jfriedli Date: Mon, 24 Jan 2022 19:43:12 +0000 Subject: Bugfix catch attribute errors and updated dependencies --- test/test.py | 8 ++++++++ test/test_api.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'test') diff --git a/test/test.py b/test/test.py index d9d0fbf..4d2907f 100644 --- a/test/test.py +++ b/test/test.py @@ -58,6 +58,14 @@ class Mat2WebTestCase(TestCase): ), follow_redirects=False) self.assertEqual(rv.status_code, 302) + def test_get_upload_bad_file_type(self): + rv = self.client.post('/', + data=dict( + file=(io.BytesIO(b"1,2,3 \n 4,5,6"), 'test.csv'), + ), follow_redirects=False) + self.assertEqual(rv.status_code, 200) + self.assertIn(b'The type text/csv could not be cleaned', rv.data) + def test_get_upload_empty_file_redir(self): rv = self.client.post('/', data=dict( diff --git a/test/test_api.py b/test/test_api.py index 91ea043..181fe4b 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -88,6 +88,18 @@ class Mat2APITestCase(unittest.TestCase): error = request.get_json()['message'] self.assertEqual(error, 'The filetype is not supported') + def test_api_not_supported_extension(self): + request = self.app.post('/api/upload', + data='{"file_name": "test_name.csv", ' + '"file": "MSwyLDMKNCw1LDY="}', + headers={'content-type': 'application/json'} + ) + self.assertEqual(request.headers['Content-Type'], 'application/json') + self.assertEqual(request.status_code, 415) + + error = request.get_json()['message'] + self.assertEqual(error, 'The filetype is not supported') + def test_api_supported_extensions(self): rv = self.app.get('/api/extension') self.assertEqual(rv.status_code, 200) @@ -478,6 +490,20 @@ class Mat2APITestCase(unittest.TestCase): self.assertEqual(r.headers['Content-Type'], 'text/plain; charset=utf-8') self.assertEqual(r.data, b'') + def test_remove_metadata_not_supported_extension(self): + r = self.app.post( + '/api/remove_metadata', + data=dict( + file=(io.BytesIO(b"1,2,3 \n 4,5,6"), 'test.csv'), + ), + follow_redirects=False + ) + self.assertEqual( + r.get_json()['message'], + 'The filetype is not supported' + ) + self.assertEqual(r.status_code, 415) + def test_remove_metdata_validation(self): r = self.app.post( '/api/remove_metadata', -- cgit v1.3