Reputation: 45
I am trying to write a mock test for an api that someone else coded, and my duty is to test a module's post method. The module is written to do a job of a handler and it uses BaseHandler as super class.
What do i need is how/what to mock while writing the mock test for a http post method. Should I mimic a post request? Or make a real one? Or what else?
I am not allowed to share any codes, but the code uses tornado to make connection to localhost, mongodb for database read-write and is written using Python 3.6.
Any ideas are welcome. Thanks from now.
Upvotes: 0
Views: 487
Reputation: 628
import mock
class Test(ApiTestCase):
@mock.patch.object(send_sms, 'delay'):
def test_send_sms(self, send_sms_mock):
data = {}
resp = self.client.post(self.url, data, format='json')
assert send_sms_mock.call_count == 1
This is basic example to mock post
Upvotes: 0