summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorjvoisin2018-12-16 21:33:18 +0100
committerjvoisin2018-12-16 21:33:18 +0100
commita71a39014519b1c1538fa173bb17f1de814246bf (patch)
treeb1fd6e73aaf24962085a1ed298826b3f2220bb36 /tests.py
parent0997c47d7ef90705559499a7b1f7b957aac28502 (diff)
Add even more tests
Diffstat (limited to 'tests.py')
-rw-r--r--tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests.py b/tests.py
index 7447554..5972474 100644
--- a/tests.py
+++ b/tests.py
@@ -1,4 +1,7 @@
1import unittest 1import unittest
2import tempfile
3import shutil
4import io
2 5
3import main 6import main
4 7
@@ -6,8 +9,12 @@ import main
6class FlaskrTestCase(unittest.TestCase): 9class 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
23if __name__ == '__main__': 51if __name__ == '__main__':
24 unittest.main() 52 unittest.main()
25 53