How to set different responses for the GET requests in Python's unit tests

278 Views Asked by At

I need to return different desponses depending on the GET parameters via HTTPretty:

@httpretty.activate
def test_multiple_requests():
    httpretty.register_uri(httpretty.GET, 'https://example.com/data.xml?n=0',
                           body='0')

    httpretty.register_uri(httpretty.GET, 'https://example.com/data.xml?n=1',
                           body='1')

    r = requests.get('https://example.com/data.xml?n=0')
    print(r.text)

    r = requests.get('https://example.com/data.xml?n=1')
    print(r.text)

This code prints the following:

1
0

Why? I thought that it should be

0
1

instead.

0

There are 0 best solutions below