I have a login method that I have written a unittest for it and it works great. But login method calls external classes to verify username and password. As I want to make the procedure faster and do the test in isolation I want to mock those classes.
def test_login(self):
with self.app.test_client() as client:
response = client.post('/login',
data=json.dumps(dict({'username': 'username',
'password': 'password'})),
content_type='application/json',
headers={'x-header':'custom headers'})
self.assertEqual(response.status_code, 200, response.data)
Inside of login there is a class that connects to DB. How should I mock the part conneting to DB? Lets say the DB class is called externalService(). Any thoughts?
Aucun commentaire:
Enregistrer un commentaire