python - Test Suite in Flask with MongoEngine -
i have small app in flask want accompany tests. have used django tests before, , i'm getting grips lower level functionality in flask.
my tests this:
import unittest config import app mongoengine import connect my_app.models import user class testcase(unittest.testcase): def setup(self): app.config['testing'] = true app.config["mongodb_db"] = 'xxx' connect( 'xxx', username='heroku', password='xxx', host='xxx', port=xxx ) self.app = app.test_client() def teardown(self): pass def test_create_user(self): u = user(username='john', email='john@example.com') u.save()
i know wrong, because test passes have added entry database. how should test creation of user without polluting database? had assumed app.config['testing']
had significance here.
any appreciated.
there 2 approaches know of:
1. separate test database
this django automatically unittesting. uses separate database testing clears before , after every test run. implement manually.
2. use mocking avoid using database
this more preferred method situations. use mocking simulate various functions tests don't create/edit/delete information in real database. better multiple reasons, notably performance/speed of unit tests.
Comments
Post a Comment