I have a small app in Flask which I want to accompany with tests. I have used Django tests before, and I'm just getting to grips with the lower level functionality in Flask.
My tests currently look like this:
import unittest
from config import app
from mongoengine import connect
from 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='[email protected]')
u.save()
I know that this is wrong, because the test passes but I have added an entry into the database. How should I test the creation of a User without polluting the database? I had assumed that app.config['TESTING']
had some significance here.