mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-02-24 00:59:59 -05:00
Add even more tests
This commit is contained in:
parent
0997c47d7e
commit
a71a390145
28
tests.py
28
tests.py
@ -1,4 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import io
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
|
||||||
@ -6,8 +9,12 @@ import main
|
|||||||
class FlaskrTestCase(unittest.TestCase):
|
class FlaskrTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
main.app.testing = True
|
main.app.testing = True
|
||||||
|
main.app.config['UPLOAD_FOLDER'] = tempfile.mkdtemp()
|
||||||
self.app = main.app.test_client()
|
self.app = main.app.test_client()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(main.app.config['UPLOAD_FOLDER'])
|
||||||
|
|
||||||
def test_get_root(self):
|
def test_get_root(self):
|
||||||
rv = self.app.get('/')
|
rv = self.app.get('/')
|
||||||
self.assertIn(b'mat2-web', rv.data)
|
self.assertIn(b'mat2-web', rv.data)
|
||||||
@ -20,6 +27,27 @@ class FlaskrTestCase(unittest.TestCase):
|
|||||||
rv = self.app.get('/download/non_existant')
|
rv = self.app.get('/download/non_existant')
|
||||||
self.assertEqual(rv.status_code, 302)
|
self.assertEqual(rv.status_code, 302)
|
||||||
|
|
||||||
|
def test_get_upload_without_file(self):
|
||||||
|
rv = self.app.post('/')
|
||||||
|
self.assertEqual(rv.status_code, 302)
|
||||||
|
|
||||||
|
def test_get_upload_empty_file(self):
|
||||||
|
rv = self.app.post('/',
|
||||||
|
data=dict(
|
||||||
|
file=(io.BytesIO(b""), 'test.pdf'),
|
||||||
|
), follow_redirects=False)
|
||||||
|
self.assertEqual(rv.status_code, 302)
|
||||||
|
|
||||||
|
def test_get_upload_empty_file_redir(self):
|
||||||
|
rv = self.app.post('/',
|
||||||
|
data=dict(
|
||||||
|
file=(io.BytesIO(b""), 'test.pdf'),
|
||||||
|
), follow_redirects=True)
|
||||||
|
self.assertIn(b'The type application/pdf is not supported',
|
||||||
|
rv.data)
|
||||||
|
self.assertEqual(rv.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user