patrys / httmock

A mocking library for requests
Other
468 stars 57 forks source link

Added a request list to remember_called decorator #54

Closed jsenin closed 5 years ago

jsenin commented 6 years ago

I need to assert the payload sent to an external host, so I added the request list in order to ensure my data was properly formed.

The scenario it's a functional tests with no integration servers. I need to test a call to an api, although it's my code I consider it as a blackbox. this blackbox must to do a call to another api so I have not direct way to validate the third call. Using the request history I can validate the call. Something like this:

def test_store_several_requests(self):
    with HTTMock(google_mock_store_requests):
        payload = {"query": "foo"}
        requests.post('http://google.com', data=payload)

    self.assertTrue(google_mock_store_requests.call['called'])
    self.assertEqual(google_mock_store_requests.call['count'], 1)
    request = google_mock_store_requests.call['requests'][0]
    self.assertEqual(request.body, 'query=foo')
jsenin commented 5 years ago

@patrys could you consider my pull request ? thanks

patrys commented 5 years ago

Yes, sorry for the long wait.

jsenin commented 5 years ago

Thank you Patrys !

On Mon, 2019-01-28 at 17:17 +0000, Patryk Zawadzki wrote:

Yes, sorry for the long wait. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.