python mock Requests and the response

  • Thread starter usmani.kashif9957
  • Start date

U

usmani.kashif9957

I am a beginner to using mock in python and trying to use http://www.voidspace.org.uk/python/mock.

Please tell me the basic calls to get me working in below scenario. I am using python's Requests module (http://docs.python-requests.org/en/latest/) .

In my views.py, I have a function that makes variety of requests.get() calls with different response each time

def myview(request):
res1 = requests.get('aurl')
res2 = request.get('burl')
res3 = request.get('curl')

In my test class I want to do something like this but cannot figure out exact method calls

Step 1:

//Mock the requests module
//when mockedRequests.get('aurl') is called then return 'a response'
//when mockedRequests.get('burl') is called then return 'b response'
//when mockedRequests.get('curl') is called then return 'C response'

Step 2:

Call my view

Step 3:

verify response contains 'a response', 'b response' , 'c response'

Please help me to complete Step 1.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top