diff options
Diffstat (limited to 'tests.py')
| -rw-r--r-- | tests.py | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/tests.py b/tests.py deleted file mode 100644 index 4c85a74..0000000 --- a/tests.py +++ /dev/null | |||
| @@ -1,86 +0,0 @@ | |||
| 1 | import unittest | ||
| 2 | import tempfile | ||
| 3 | import shutil | ||
| 4 | import io | ||
| 5 | |||
| 6 | import main | ||
| 7 | |||
| 8 | |||
| 9 | class FlaskrTestCase(unittest.TestCase): | ||
| 10 | def setUp(self): | ||
| 11 | main.app.testing = True | ||
| 12 | main.app.config['UPLOAD_FOLDER'] = tempfile.mkdtemp() | ||
| 13 | self.app = main.app.test_client() | ||
| 14 | |||
| 15 | def tearDown(self): | ||
| 16 | shutil.rmtree(main.app.config['UPLOAD_FOLDER']) | ||
| 17 | |||
| 18 | def test_get_root(self): | ||
| 19 | rv = self.app.get('/') | ||
| 20 | self.assertIn(b'mat2-web', rv.data) | ||
| 21 | |||
| 22 | def test_check_mimetypes(self): | ||
| 23 | rv = self.app.get('/') | ||
| 24 | self.assertIn(b'.torrent', rv.data) | ||
| 25 | self.assertIn(b'.ods', rv.data) | ||
| 26 | |||
| 27 | def test_get_download_dangerous_file(self): | ||
| 28 | rv = self.app.get('/download/1337/\..\filename') | ||
| 29 | self.assertEqual(rv.status_code, 302) | ||
| 30 | |||
| 31 | def test_get_download_without_key_file(self): | ||
| 32 | rv = self.app.get('/download/non_existant') | ||
| 33 | self.assertEqual(rv.status_code, 404) | ||
| 34 | |||
| 35 | def test_get_download_nonexistant_file(self): | ||
| 36 | rv = self.app.get('/download/1337/non_existant') | ||
| 37 | self.assertEqual(rv.status_code, 302) | ||
| 38 | |||
| 39 | |||
| 40 | def test_get_upload_without_file(self): | ||
| 41 | rv = self.app.post('/') | ||
| 42 | self.assertEqual(rv.status_code, 302) | ||
| 43 | |||
| 44 | def test_get_upload_empty_file(self): | ||
| 45 | rv = self.app.post('/', | ||
| 46 | data=dict( | ||
| 47 | file=(io.BytesIO(b""), 'test.pdf'), | ||
| 48 | ), follow_redirects=False) | ||
| 49 | self.assertEqual(rv.status_code, 302) | ||
| 50 | |||
| 51 | def test_get_upload_empty_file_redir(self): | ||
| 52 | rv = self.app.post('/', | ||
| 53 | data=dict( | ||
| 54 | file=(io.BytesIO(b""), 'test.pdf'), | ||
| 55 | ), follow_redirects=True) | ||
| 56 | self.assertIn(b'The type application/pdf is not supported', | ||
| 57 | rv.data) | ||
| 58 | self.assertEqual(rv.status_code, 200) | ||
| 59 | |||
| 60 | def test_get_upload_no_file_name(self): | ||
| 61 | rv = self.app.post('/', | ||
| 62 | data=dict( | ||
| 63 | file=(io.BytesIO(b"aaa"), ''), | ||
| 64 | ), follow_redirects=True) | ||
| 65 | self.assertIn(b'No file part', rv.data) | ||
| 66 | self.assertEqual(rv.status_code, 200) | ||
| 67 | |||
| 68 | |||
| 69 | def test_get_upload_harmless_file(self): | ||
| 70 | rv = self.app.post('/', | ||
| 71 | data=dict( | ||
| 72 | file=(io.BytesIO(b"Some text"), 'test.txt'), | ||
| 73 | ), follow_redirects=True) | ||
| 74 | self.assertIn(b'/download/4c2e9e6da31a64c70623619c449a040968cdbea85945bf384fa30ed2d5d24fa3/test.cleaned.txt', rv.data) | ||
| 75 | self.assertEqual(rv.status_code, 200) | ||
| 76 | |||
| 77 | rv = self.app.get('/download/4c2e9e6da31a64c70623619c449a040968cdbea85945bf384fa30ed2d5d24fa3/test.cleaned.txt') | ||
| 78 | self.assertEqual(rv.status_code, 200) | ||
| 79 | |||
| 80 | rv = self.app.get('/download/4c2e9e6da31a64c70623619c449a040968cdbea85945bf384fa30ed2d5d24fa3/test.cleaned.txt') | ||
| 81 | self.assertEqual(rv.status_code, 302) | ||
| 82 | |||
| 83 | |||
| 84 | if __name__ == '__main__': | ||
| 85 | unittest.main() | ||
| 86 | |||
