diff options
| author | jvoisin | 2018-12-16 21:33:18 +0100 |
|---|---|---|
| committer | jvoisin | 2018-12-16 21:33:18 +0100 |
| commit | a71a39014519b1c1538fa173bb17f1de814246bf (patch) | |
| tree | b1fd6e73aaf24962085a1ed298826b3f2220bb36 /tests.py | |
| parent | 0997c47d7ef90705559499a7b1f7b957aac28502 (diff) | |
Add even more tests
Diffstat (limited to 'tests.py')
| -rw-r--r-- | tests.py | 28 |
1 files changed, 28 insertions, 0 deletions
| @@ -1,4 +1,7 @@ | |||
| 1 | import unittest | 1 | import unittest |
| 2 | import tempfile | ||
| 3 | import shutil | ||
| 4 | import io | ||
| 2 | 5 | ||
| 3 | import main | 6 | import main |
| 4 | 7 | ||
| @@ -6,8 +9,12 @@ import main | |||
| 6 | class FlaskrTestCase(unittest.TestCase): | 9 | class FlaskrTestCase(unittest.TestCase): |
| 7 | def setUp(self): | 10 | def setUp(self): |
| 8 | main.app.testing = True | 11 | main.app.testing = True |
| 12 | main.app.config['UPLOAD_FOLDER'] = tempfile.mkdtemp() | ||
| 9 | self.app = main.app.test_client() | 13 | self.app = main.app.test_client() |
| 10 | 14 | ||
| 15 | def tearDown(self): | ||
| 16 | shutil.rmtree(main.app.config['UPLOAD_FOLDER']) | ||
| 17 | |||
| 11 | def test_get_root(self): | 18 | def test_get_root(self): |
| 12 | rv = self.app.get('/') | 19 | rv = self.app.get('/') |
| 13 | self.assertIn(b'mat2-web', rv.data) | 20 | self.assertIn(b'mat2-web', rv.data) |
| @@ -20,6 +27,27 @@ class FlaskrTestCase(unittest.TestCase): | |||
| 20 | rv = self.app.get('/download/non_existant') | 27 | rv = self.app.get('/download/non_existant') |
| 21 | self.assertEqual(rv.status_code, 302) | 28 | self.assertEqual(rv.status_code, 302) |
| 22 | 29 | ||
| 30 | def test_get_upload_without_file(self): | ||
| 31 | rv = self.app.post('/') | ||
| 32 | self.assertEqual(rv.status_code, 302) | ||
| 33 | |||
| 34 | def test_get_upload_empty_file(self): | ||
| 35 | rv = self.app.post('/', | ||
| 36 | data=dict( | ||
| 37 | file=(io.BytesIO(b""), 'test.pdf'), | ||
| 38 | ), follow_redirects=False) | ||
| 39 | self.assertEqual(rv.status_code, 302) | ||
| 40 | |||
| 41 | def test_get_upload_empty_file_redir(self): | ||
| 42 | rv = self.app.post('/', | ||
| 43 | data=dict( | ||
| 44 | file=(io.BytesIO(b""), 'test.pdf'), | ||
| 45 | ), follow_redirects=True) | ||
| 46 | self.assertIn(b'The type application/pdf is not supported', | ||
| 47 | rv.data) | ||
| 48 | self.assertEqual(rv.status_code, 200) | ||
| 49 | |||
| 50 | |||
| 23 | if __name__ == '__main__': | 51 | if __name__ == '__main__': |
| 24 | unittest.main() | 52 | unittest.main() |
| 25 | 53 | ||
