Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocking doesn't drain iterator #19

Open
jamielennox opened this issue Feb 27, 2018 · 2 comments
Open

mocking doesn't drain iterator #19

jamielennox opened this issue Feb 27, 2018 · 2 comments
Labels

Comments

@jamielennox
Copy link
Owner

If you pass a generator to data in requests it will iterate over the generator and include that info into the request. This has the result of draining the provided iterator. Currently we don't do this, nor do we read provided files.

It's rare this would be something that an application is testing the result of. The provided case is that swiftclient updates the md5sum as the iterator is read which is currently not happening.

The downside of this is that the body available in last_request is now expended. Again this probably doesn't matter but it's a change in behaviour.

Using itertools.tee we can both drain the generator and maintain the request history - but i'm not sure it's worth it.

Launchpad Details: #LP1616751 Jamie Lennox - 2016-08-25 06:19:58 +0000

@jamielennox
Copy link
Owner Author

Fix proposed to branch: master
Review: https://review.openstack.org/360300

Launchpad Details: #LPC OpenStack Infra - 2016-08-25 07:42:07 +0000

@OrangeDog
Copy link

Another consequence of this is that last_request.text returns the generator instead of the resulting text, which is a much more common thing people would want to check.

That can be worked around with e.g. bytes(itertools.chain(*mock.last_request.text)).decode('utf8')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants