Muestra las diferencias entre dos versiones de la página.
| Próxima revisión | Revisión previa | ||
|
wiki2:python:flask:testing [2015/08/09 17:03] alfred creado |
wiki2:python:flask:testing [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 33: | Línea 33: | ||
| self.assert_template_used('mytemplate.html') | self.assert_template_used('mytemplate.html') | ||
| + | </code> | ||
| + | |||
| + | ==== Testing SQL Alchemy ==== | ||
| + | <code python> | ||
| + | from flask.ext.testing import TestCase | ||
| + | |||
| + | from myapp import create_app, db | ||
| + | |||
| + | class MyTest(TestCase): | ||
| + | |||
| + | SQLALCHEMY_DATABASE_URI = "sqlite://" | ||
| + | TESTING = True | ||
| + | |||
| + | def create_app(self): | ||
| + | |||
| + | # pass in test configuration | ||
| + | return create_app(self) | ||
| + | |||
| + | def setUp(self): | ||
| + | |||
| + | db.create_all() | ||
| + | |||
| + | def tearDown(self): | ||
| + | |||
| + | db.session.remove() | ||
| + | db.drop_all() | ||
| </code> | </code> | ||