Codebase list httmock / 7462c11
Update upstream source from tag 'upstream/1.4.0' Update to upstream version '1.4.0' with Debian dir 3c51dd2293ab48a2f60437efa661e1b6d5399799 Colin Watson 3 years ago
4 changed file(s) with 48 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
0 os: linux
1 arch:
2 - amd64
3 - ppc64le
04 language: python
15 python:
26 - 2.7
48 - 3.4
59 - 3.5
610 - 3.6
11 - 3.7
12 - 3.8
13 jobs:
14 exclude:
15 - arch: ppc64le
16 python: pypy
717 install:
818 - "pip install requests"
919 script: nosetests
0 httmock (1.3.0-6) UNRELEASED; urgency=medium
0 httmock (1.4.0-1) UNRELEASED; urgency=medium
11
22 [ Debian Janitor ]
33 * Bump debhelper from deprecated 9 to 12.
1010 contact address.
1111 * d/control: Update Vcs-* fields with new Debian Python Team Salsa
1212 layout.
13
14 [ Colin Watson ]
15 * New upstream release.
1316
1417 -- Debian Janitor <janitor@jelmer.uk> Fri, 24 Apr 2020 07:29:47 +0000
1518
1313 if sys.version_info >= (3, 0, 0):
1414 from io import BytesIO
1515 else:
16 try:
17 from cStringIO import StringIO as BytesIO
18 except ImportError:
19 from StringIO import StringIO as BytesIO
16 from StringIO import StringIO as BytesIO
2017
2118
2219 binary_type = bytes
3835
3936
4037 def response(status_code=200, content='', headers=None, reason=None, elapsed=0,
41 request=None, stream=False):
38 request=None, stream=False, http_vsn=11):
4239 res = requests.Response()
4340 res.status_code = status_code
4441 if isinstance(content, (dict, list)):
6360 res.raw = BytesIO(content)
6461 else:
6562 res.raw = BytesIO(b'')
63 res.raw.version = http_vsn
6664
6765 # normally this closes the underlying connection,
6866 # but we have nothing to free.
193191 response = history.pop()
194192 response.history = tuple(history)
195193
196 session.cookies = response.cookies
194 session.cookies.update(response.cookies)
197195
198196 return response
199197
230228 res.get('reason'),
231229 res.get('elapsed', 0),
232230 request,
233 stream=kwargs.get('stream', False))
231 stream=kwargs.get('stream', False),
232 http_vsn=res.get('http_vsn', 11))
234233 elif isinstance(res, (text_type, binary_type)):
235234 return response(content=res, stream=kwargs.get('stream', False))
236235 elif res is None:
6565 def dict_any_mock(url, request):
6666 return {
6767 'content': 'Hello from %s' % (url.netloc,),
68 'status_code': 200
68 'status_code': 200,
69 'http_vsn': 10,
6970 }
7071
7172
135136 self.assertEqual(r.text, u'Motörhead')
136137 self.assertEqual(r.content, r.text.encode('utf-8'))
137138
139 def test_has_raw_version(self):
140 with HTTMock(any_mock):
141 r = requests.get('http://example.com')
142 self.assertEqual(r.raw.version, 11)
143 with HTTMock(dict_any_mock):
144 r = requests.get('http://example.com')
145 self.assertEqual(r.raw.version, 10)
138146
139147 class DecoratorTest(unittest.TestCase):
140148
241249 r = response(200, None, {'Content-Type': 'application/json'})
242250 self.assertEqual(r.headers['content-type'], 'application/json')
243251
252 def test_response_raw_version(self):
253 r = response(200, None, {'Content-Type': 'application/json'},
254 http_vsn=10)
255 self.assertEqual(r.raw.version, 10)
256
244257 def test_response_cookies(self):
245258 @all_requests
246259 def response_content(url, request):
267280 self.assertTrue('foo' in session.cookies)
268281 self.assertEqual(session.cookies['foo'], 'bar')
269282
283 def test_session_persistent_cookies(self):
284 session = requests.Session()
285 with HTTMock(lambda u, r: response(200, 'Foo', {'Set-Cookie': 'foo=bar;'}, request=r)):
286 session.get('https://foo_bar')
287 with HTTMock(lambda u, r: response(200, 'Baz', {'Set-Cookie': 'baz=qux;'}, request=r)):
288 session.get('https://baz_qux')
289 self.assertEqual(len(session.cookies), 2)
290 self.assertTrue('foo' in session.cookies)
291 self.assertEqual(session.cookies['foo'], 'bar')
292 self.assertTrue('baz' in session.cookies)
293 self.assertEqual(session.cookies['baz'], 'qux')
294
270295 def test_python_version_encoding_differences(self):
271296 # Previous behavior would result in this test failing in Python3 due
272297 # to how requests checks for utf-8 JSON content in requests.utils with:
340365 results = self.several_calls(
341366 1, requests.get, 'http://facebook.com/')
342367
343 self.assertEquals(facebook_mock_count.call['count'], 1)
368 self.assertEqual(facebook_mock_count.call['count'], 1)
344369
345370 @with_httmock(google_mock_count, facebook_mock_count)
346371 def test_several_call_decorated(self):
356381 self.assertEqual(r.content, b'Hello from Facebook')
357382
358383 self.several_calls(1, requests.get, 'http://facebook.com/')
359 self.assertEquals(facebook_mock_count.call['count'], 4)
384 self.assertEqual(facebook_mock_count.call['count'], 4)
360385
361386 def test_store_several_requests(self):
362387 with HTTMock(google_mock_store_requests):