betamaxpy / betamax

A VCR imitation designed only for python-requests.
https://betamax.readthedocs.io/en/latest/
Other
566 stars 62 forks source link

`requests.Response` is reused when `stream=True` #95

Closed arhoyling closed 8 years ago

arhoyling commented 8 years ago

When you make the same streaming requests multiple times, you do not get any data after the first request.

import betamax
import requests

session = requests.Session()
recorder = betamax.Betamax(session)

def stream(n):
    for k in range(1, n):
        response = session.get('http://httpbin.org/stream/3', stream=True)
        assert response.raw.read(), "Stream should not be empty. Attempt: %d" % k

with recorder.use_cassette('stream', record='once'):
    stream(10)

Betamax loads the cassette in the use_cassette() decorator and creates a unique Interaction with the associated recorded requests.Response. This requests.Response is reused each time interaction.as_response() is called but the stream is fully consumed after the first request.

Considering that Betamax is used for testing, would it be such an overhead to dynamically deserialize the recorded response every time an Interaction is used?

sigmavirus24 commented 8 years ago

This makes sense. Would you like to tackle this @arhoyling?

arhoyling commented 8 years ago

Just made a pull request with the changes.

sigmavirus24 commented 8 years ago

@arhoyling where did you make the pull request? There are none here.

arhoyling commented 8 years ago

@sigmavirus24 you are right. Sorry about that. I should have read the docs before trying a pull request.

Here

sigmavirus24 commented 8 years ago

This has been fixed.