Skip to content

Strange behavior with multiple responses #158

@ykharko

Description

@ykharko

Describe the bug
I wanted to test specific logic of my application when retry logic is used. I wanted to emulate couple of fail responses and then successful one. I tried to use Entry.register method as it looks like its interface allows to pass multiple responses.
Almost everything works fine (difference responses are returned back) except for one thing: odd responses are missed.

To Reproduce
Probably the easiest way to reproduce it is not to use retries but just specify multiple responses with different status codes:

from mocket import mocketize
from mocket.mockhttp import Entry, Response
import requests


TARGET_URL = 'http://merchant.store/webhook'


@mocketize
def main():
    Entry.register(
        Entry.POST,
        TARGET_URL,
        Response(body='{}', status=200),
        Response(body='{}', status=201),
        Response(body='{}', status=202)
    )

    response = requests.post(TARGET_URL, json={'test': 1})

    print(response.status_code)


if __name__ == '__main__':
    main()

Expected behavior
In the given example I expect 200 status code is returned back, but actually 201 status code is returned.

Additional context
OS: Ubuntu
Python version: 3.8.10
Requests version: 2.25.1
Mocket version: 3.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions