I did tried to do the unit testing in flask. And I did, I'm testing a function that saves documents in database. I want to after finishing those testing function to apply tearDown function to delete all the data that were added in database while testing.
How can I do this, I couldn't find help.
from app import create_app, mongo
...
class ApiTestCases(TestCase):
def create_app(self):
app = create_app()
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_saving_dummy_json(self):
json_obj = {"test": "test", "post_type": "test"}
response = self.client.post(
url_for('api.save'),
data=json.dumps(json_obj),
content_type='application/json'
)
self.assert200(response)
Can somebody help me please? Is any way to do it?
I tried like this by importing mongo
def tearDown(self):
mongo.session.remove()
mongo.drop_all()
But this is not working
Aucun commentaire:
Enregistrer un commentaire