diff options
Diffstat (limited to 'test/test_api.py')
| -rw-r--r-- | test/test_api.py | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/test/test_api.py b/test/test_api.py index 6961197..6d48a35 100644 --- a/test/test_api.py +++ b/test/test_api.py | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | import unittest | ||
| 2 | import tempfile | ||
| 3 | import json | 1 | import json |
| 4 | import os | 2 | import os |
| 5 | import shutil | 3 | import shutil |
| 4 | import tempfile | ||
| 5 | import unittest | ||
| 6 | import zipfile | 6 | import zipfile |
| 7 | from six import BytesIO | 7 | import io |
| 8 | 8 | ||
| 9 | from unittest.mock import patch | 9 | from unittest.mock import patch |
| 10 | |||
| 10 | from openapi_spec_validator import validate_spec | 11 | from openapi_spec_validator import validate_spec |
| 12 | from six import BytesIO | ||
| 11 | 13 | ||
| 12 | import main | 14 | import main |
| 13 | 15 | ||
| @@ -433,5 +435,60 @@ class Mat2APITestCase(unittest.TestCase): | |||
| 433 | spec = self.app.get('apispec_1.json').get_json() | 435 | spec = self.app.get('apispec_1.json').get_json() |
| 434 | validate_spec(spec) | 436 | validate_spec(spec) |
| 435 | 437 | ||
| 438 | def test_remove_metadata(self): | ||
| 439 | r = self.app.post( | ||
| 440 | '/api/remove_metadata', | ||
| 441 | data=dict( | ||
| 442 | file=(io.BytesIO(b""), 'test.txt'), | ||
| 443 | ), | ||
| 444 | follow_redirects=False | ||
| 445 | ) | ||
| 446 | self.assertEqual(r.status_code, 200) | ||
| 447 | self.assertEqual(r.headers['Content-Disposition'], 'attachment; filename=test.cleaned.txt') | ||
| 448 | self.assertEqual(r.headers['Content-Type'], 'text/plain; charset=utf-8') | ||
| 449 | self.assertEqual(r.data, b'') | ||
| 450 | |||
| 451 | def test_remove_metdata_validation(self): | ||
| 452 | r = self.app.post( | ||
| 453 | '/api/remove_metadata', | ||
| 454 | data=dict( | ||
| 455 | fileNotExisting=(io.BytesIO(b""), 'test.random'), | ||
| 456 | ), | ||
| 457 | follow_redirects=False | ||
| 458 | ) | ||
| 459 | self.assertEqual(r.get_json()['message'], 'No file part') | ||
| 460 | self.assertEqual(r.status_code, 400) | ||
| 461 | |||
| 462 | r = self.app.post( | ||
| 463 | '/api/remove_metadata', | ||
| 464 | data=dict( | ||
| 465 | file=(io.BytesIO(b""), ''), | ||
| 466 | ), | ||
| 467 | follow_redirects=False | ||
| 468 | ) | ||
| 469 | self.assertEqual(r.get_json()['message'], 'No selected `file`') | ||
| 470 | self.assertEqual(r.status_code, 400) | ||
| 471 | |||
| 472 | r = self.app.post( | ||
| 473 | '/api/remove_metadata', | ||
| 474 | data=dict( | ||
| 475 | file=(io.BytesIO(b""), '../../'), | ||
| 476 | ), | ||
| 477 | follow_redirects=False | ||
| 478 | ) | ||
| 479 | self.assertEqual(r.get_json()['message'], 'Invalid Filename') | ||
| 480 | self.assertEqual(r.status_code, 400) | ||
| 481 | |||
| 482 | r = self.app.post( | ||
| 483 | '/api/remove_metadata', | ||
| 484 | data=dict( | ||
| 485 | file=(io.BytesIO(b""), 'test.random'), | ||
| 486 | ), | ||
| 487 | follow_redirects=False | ||
| 488 | ) | ||
| 489 | self.assertEqual(r.get_json()['message'], 'The type None is not supported') | ||
| 490 | self.assertEqual(r.status_code, 415) | ||
| 491 | |||
| 492 | |||
| 436 | if __name__ == '__main__': | 493 | if __name__ == '__main__': |
| 437 | unittest.main() | 494 | unittest.main() |
