1

I have a function that makes a call :

GET www.thirdpartydomain.com/objectlist/

and fetches a JSON list in the following way: [ { id: 1, name: 'abc', }, { id: 2, name: 'def', } ]

and then the function loops through the objects in the array fetched and makes further calls

GET www.thirdpartydomain.com/object/<id> --- where id is in the fetched json array

For testing, I dont want to call the thirdpartydomain API and instead fake it with known responses for LISt and DETAILS API

How can I do this in Django?

dowjones123
  • 3,695
  • 5
  • 40
  • 83
  • I'd say it mostly depends on how you are sending the request to the third party website. If you are using the module [`requests`](http://docs.python-requests.org/en/latest/) you can use the module [`responses`](https://github.com/getsentry/responses) to "fake" the HTTP request and get the results you want for testing. – El Bert Mar 13 '15 at 10:58
  • +1 for `responses` ... there's also https://pypi.python.org/pypi/httpretty they are both good but different, have used them both – Anentropic Mar 13 '15 at 11:42

1 Answers1

0

Have you looked at Betamax? To quote from the documentation:

Betamax intercepts every request you make and attempts to find a matching request that has already been intercepted and recorded

You'd decorate your tests appropriate, the the first time you run them it would mock them from what it recorded previously.

kevinharvey
  • 858
  • 6
  • 16