betamaxpy / betamax

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

Betamax corrupts some responses #105

Closed DeCarabas closed 8 years ago

DeCarabas commented 8 years ago

Here's a simple test, which fails on betamax 0.60.0:

from betamax import Betamax
import requests

def test_get_url_image():
    http_session = requests.Session()
    url = 'https://www.crummy.com/software/BeautifulSoup/10.1.jpg'
    expected = http_session.get(url)

    with Betamax(http_session).use_cassette('test_get_url_image'):
        actual = http_session.get(url)

    assert expected.content == actual.content

It fails: actual.content is different than expected.content. I haven't looked very closely to see what's wrong, but something is.

sigmavirus24 commented 8 years ago

Is this a regression from 0.5.x?

sigmavirus24 commented 8 years ago

Also that URL isn't working for me. Do you have one that exhibits this behaviour?

sigmavirus24 commented 8 years ago

Betamax stores response data in JSON. Arbitrary bytes sometimes are able to serialize to JSON which gives the false sense of "working". In this case, when they're deserialized, they're corrupted, as you point out. If you look at our documentation we explain this and how to fix it.