Diferencia entre revisiones de «Usuario:Lmorillas/desarrollo web servidor/flask/testing»
De WikiEducator
(Página creada con '{{MiTitulo| Testing de apps Flask}} == Documentación == * http://flask.pocoo.org/docs/testing/ * http://mkelsey.com/2013/05/15/test-driven-development-of-a-flask-api/ == Ejem…') |
|||
Línea 8: | Línea 8: | ||
* https://github.com/mitsuhiko/flask/blob/master/examples/flaskr/flaskr_tests.py | * https://github.com/mitsuhiko/flask/blob/master/examples/flaskr/flaskr_tests.py | ||
* https://github.com/mitsuhiko/flask/blob/master/examples/minitwit/minitwit_tests.py | * https://github.com/mitsuhiko/flask/blob/master/examples/minitwit/minitwit_tests.py | ||
+ | |||
+ | == Esqueleto == | ||
+ | <source lang="python"> | ||
+ | # -*- coding: utf-8 -*- | ||
+ | import os | ||
+ | import flaskr | ||
+ | import unittest | ||
+ | import tempfile | ||
+ | |||
+ | class FlaskrTestCase(unittest.TestCase): | ||
+ | |||
+ | def setUp(self): | ||
+ | self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() | ||
+ | flaskr.app.config['TESTING'] = True | ||
+ | self.app = flaskr.app.test_client() | ||
+ | flaskr.init_db() | ||
+ | |||
+ | def tearDown(self): | ||
+ | os.close(self.db_fd) | ||
+ | os.unlink(flaskr.app.config['DATABASE']) | ||
+ | |||
+ | if __name__ == '__main__': | ||
+ | unittest.main() | ||
+ | </source> |
Última revisión de 08:05 13 dic 2013
Documentación
- http://flask.pocoo.org/docs/testing/
- http://mkelsey.com/2013/05/15/test-driven-development-of-a-flask-api/
Ejemplos
- https://github.com/mitsuhiko/flask/blob/master/examples/flaskr/flaskr_tests.py
- https://github.com/mitsuhiko/flask/blob/master/examples/minitwit/minitwit_tests.py
Esqueleto
# -*- coding: utf-8 -*- import os import flaskr import unittest import tempfile class FlaskrTestCase(unittest.TestCase): def setUp(self): self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() flaskr.app.config['TESTING'] = True self.app = flaskr.app.test_client() flaskr.init_db() def tearDown(self): os.close(self.db_fd) os.unlink(flaskr.app.config['DATABASE']) if __name__ == '__main__': unittest.main()