1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Use pytest-httpbin

This will help the test flakiness and speed up test runs.
This commit is contained in:
Kevin McCarthy
2015-04-11 13:07:17 -10:00
parent cfc483a08d
commit 4e36997e1a
20 changed files with 380 additions and 369 deletions

View File

@@ -24,14 +24,14 @@ def test_domain_redirect():
assert len(cass) == 2
def test_flickr_multipart_upload():
def test_flickr_multipart_upload(httpbin, tmpdir):
"""
The python-flickr-api project does a multipart
upload that confuses vcrpy
"""
def _pretend_to_be_flickr_library():
content_type, body = "text/plain", "HELLO WORLD"
h = httplib.HTTPConnection("httpbin.org")
h = httplib.HTTPConnection(httpbin.host, httpbin.port)
headers = {
"Content-Type": content_type,
"content-length": str(len(body))
@@ -44,11 +44,12 @@ def test_flickr_multipart_upload():
return data
with vcr.use_cassette('fixtures/vcr_cassettes/flickr.yaml') as cass:
testfile = str(tmpdir.join('flickr.yml'))
with vcr.use_cassette(testfile) as cass:
_pretend_to_be_flickr_library()
assert len(cass) == 1
with vcr.use_cassette('fixtures/vcr_cassettes/flickr.yaml') as cass:
with vcr.use_cassette(testfile) as cass:
assert len(cass) == 1
_pretend_to_be_flickr_library()
assert cass.play_count == 1
@@ -61,13 +62,13 @@ def test_flickr_should_respond_with_200(tmpdir):
assert r.status_code == 200
def test_cookies(tmpdir):
def test_cookies(tmpdir, httpbin):
testfile = str(tmpdir.join('cookies.yml'))
with vcr.use_cassette(testfile):
s = requests.Session()
s.get("http://httpbin.org/cookies/set?k1=v1&k2=v2")
s.get(httpbin.url + "/cookies/set?k1=v1&k2=v2")
r2 = s.get("http://httpbin.org/cookies")
r2 = s.get(httpbin.url + "/cookies")
assert len(r2.json()['cookies']) == 2