Skip to content

Commit

Permalink
Merge pull request #261 from mangin/use_session_in_tests
Browse files Browse the repository at this point in the history
Stop making HTTP requests in tests
  • Loading branch information
pquentin authored Oct 31, 2022
2 parents a9bef59 + 358f988 commit 1aff2e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recorded_with": "betamax/0.4.1", "http_interactions": [{"request": {"uri": "https://api.github.com/repos/sigmavirus24/github3.py/releases/assets/37944", "method": "GET", "headers": {"Accept": ["application/octet-stream"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "User-Agent": ["python-requests/2.5.3 CPython/2.7.9 Darwin/14.1.0"]}, "body": {"base64_string": "", "encoding": "utf-8"}}, "response": {"status": {"code": 302, "message": "Found"}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/releases/assets/37944", "headers": {"access-control-allow-credentials": ["true"], "x-xss-protection": ["1; mode=block"], "vary": ["Accept-Encoding"], "location": ["https://s3.amazonaws.com/github-cloud/releases/3710711/365425c2-4e46-11e3-86fb-bb0d50a886e7.whl?response-content-disposition=attachment%3B%20filename%3Dgithub3.py-0.7.1-py2.py3-none-any.whl&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1426166613&Signature=78anFgNgXLm3TIbo%2FbTEEk7m%2F34%3D"], "x-content-type-options": ["nosniff"], "content-security-policy": ["default-src 'none'"], "x-ratelimit-limit": ["60"], "status": ["302 Found"], "x-frame-options": ["deny"], "x-served-by": ["8dd185e423974a7e13abbbe6e060031e"], "server": ["GitHub.com"], "access-control-allow-origin": ["*"], "strict-transport-security": ["max-age=31536000; includeSubdomains; preload"], "x-github-request-id": ["48A0C951:54E7:48B5311:55019319"], "date": ["Thu, 12 Mar 2015 13:22:33 GMT"], "access-control-expose-headers": ["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"], "x-ratelimit-remaining": ["58"], "content-type": ["text/html;charset=utf-8"], "x-ratelimit-reset": ["1426170017"]}, "body": {"base64_string": "", "encoding": "utf-8"}}, "recorded_at": "2015-03-12T13:22:33"}, {"request": {"uri": "https://s3.amazonaws.com/github-cloud/releases/3710711/365425c2-4e46-11e3-86fb-bb0d50a886e7.whl?response-content-disposition=attachment%3B%20filename%3Dgithub3.py-0.7.1-py2.py3-none-any.whl&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1426166613&Signature=78anFgNgXLm3TIbo%2FbTEEk7m%2F34%3D", "method": "GET", "headers": {"Accept": ["application/octet-stream"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "User-Agent": ["python-requests/2.5.3 CPython/2.7.9 Darwin/14.1.0"]}, "body": {"base64_string": "", "encoding": "utf-8"}}, "response": {"status": {"code": 200, "message": "OK"}, "url": "https://s3.amazonaws.com/github-cloud/releases/3710711/365425c2-4e46-11e3-86fb-bb0d50a886e7.whl?response-content-disposition=attachment%3B%20filename%3Dgithub3.py-0.7.1-py2.py3-none-any.whl&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1426166613&Signature=78anFgNgXLm3TIbo%2FbTEEk7m%2F34%3D", "headers": {"accept-ranges": ["bytes"], "content-disposition": ["attachment; filename=github3.py-0.7.1-py2.py3-none-any.whl"], "x-amz-id-2": ["9+TuHhbd7y2BUJaEV+mFpaDgjl1g9uSAPiZxwc6b2cYydhlhZSyKSuB7PQyiPBPD"], "x-amz-meta-surrogate-key": ["repository-3710711 user-240830"], "x-amz-request-id": ["4B4BFE6BF5135B8D"], "last-modified": ["Fri, 15 Nov 2013 22:35:23 GMT"], "x-amz-meta-surrogate-control": ["max-age=31557600"], "etag": ["\"6550854f02f7bf10b944070b84f38313\""], "date": ["Thu, 12 Mar 2015 13:22:35 GMT"], "cache-control": ["max-age=31557600"], "content-type": ["application/octet-stream"], "server": ["AmazonS3"]}, "body": {"base64_string": "", "encoding": null}}, "recorded_at": "2015-03-12T13:22:34"}]}
15 changes: 6 additions & 9 deletions tests/test_multipart_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ def test_accepts_encoded_strings_with_unicode(self):

class TestFileFromURLWrapper(unittest.TestCase):
def setUp(self):
s = requests.Session()
self.recorder = get_betamax(s)
self.session = requests.Session()
self.recorder = get_betamax(self.session)

@pytest.mark.xfail
def test_read_file(self):
url = ('https://stxnext.com/static/img/logo.830ebe551641.svg')
with self.recorder.use_cassette(
'file_for_download', **preserve_bytes):
self.instance = FileFromURLWrapper(url)
self.instance = FileFromURLWrapper(url, session=self.session)
assert self.instance.len == 5177
chunk = self.instance.read(20)
assert chunk == b'<svg xmlns="http://w'
Expand All @@ -112,16 +111,15 @@ def test_read_file(self):
assert chunk == b'ww.w3.org/'
assert self.instance.len == 5147

@pytest.mark.xfail(strict=False)
def test_no_content_length_header(self):
url = (
'https://api.github.com/repos/sigmavirus24/github3.py/releases/'
'assets/37944'
)
with self.recorder.use_cassette(
'stream_response_to_file', **preserve_bytes):
'stream_response_without_content_length_to_file', **preserve_bytes):
with self.assertRaises(FileNotSupportedError) as context:
FileFromURLWrapper(url)
FileFromURLWrapper(url, session=self.session)
assert context.exception.__str__() == (
'Data from provided URL https://api.github.com/repos/s'
'igmavirus24/github3.py/releases/assets/37944 is not '
Expand Down Expand Up @@ -194,15 +192,14 @@ def test_reads_open_file_objects(self):
m = MultipartEncoder([('field', 'foo'), ('file', fd)])
assert m.read() is not None

@pytest.mark.xfail
def test_reads_file_from_url_wrapper(self):
s = requests.Session()
recorder = get_betamax(s)
url = ('https://stxnext.com/static/img/logo.830ebe551641.svg')
with recorder.use_cassette(
'file_for_download'):
m = MultipartEncoder(
[('field', 'foo'), ('file', FileFromURLWrapper(url))])
[('field', 'foo'), ('file', FileFromURLWrapper(url, session=s))])
assert m.read() is not None

def test_reads_open_file_objects_with_a_specified_filename(self):
Expand Down

0 comments on commit 1aff2e6

Please sign in to comment.