Update to 1.3.0
This commit is contained in:
parent
6f3b862965
commit
5d192ad785
4 changed files with 43 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
/httmock-1.2.6.tar.gz
|
||||
/httmock-1.3.0.tar.gz
|
||||
/tests.py
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
%global pypi_name httmock
|
||||
|
||||
Name: python-%{pypi_name}
|
||||
Version: 1.2.6
|
||||
Release: 9%{?dist}
|
||||
Version: 1.3.0
|
||||
Release: 1%{?dist}
|
||||
Summary: A mocking library for requests
|
||||
|
||||
License: ASL 2.0
|
||||
|
|
@ -53,6 +53,9 @@ cp %{SOURCE1} .
|
|||
%{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info
|
||||
|
||||
%changelog
|
||||
* Wed Nov 13 2019 Steve Traylen <steve.traylen@cern.ch> - 1.3.0-1
|
||||
- Update to 1.3.0
|
||||
|
||||
* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 1.2.6-9
|
||||
- Rebuilt for Python 3.8.0rc1 (#1748018)
|
||||
|
||||
|
|
|
|||
3
sources
3
sources
|
|
@ -1 +1,2 @@
|
|||
SHA512 (httmock-1.2.6.tar.gz) = a31b4a28383c052bb15ca5c2f07f96c8654f44d15df05fa7972e410b9c1a40f70c6ed48256dd7cf3a0486f8555142ba59330edd9c8beb003785ecdb535ddfb69
|
||||
SHA512 (tests.py) = f869c9923bdd68c8758c1937eb61a7b8e2aae1ef32dce9ca850460dfdfd8daae7c20e1e5b9c298c1ce600900cbe2c34ba9660bd0ded0dbd34e817e39a18eee72
|
||||
SHA512 (httmock-1.3.0.tar.gz) = f713ddf45675738582a3611e01a55babce2951231b34fb9ca6b1b64fcf60a3862994ff7ad4cd7a224a116c6acb1caa267978a7cb6fedd02676fa2a01f90e93aa
|
||||
|
|
|
|||
34
tests.py
34
tests.py
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import requests
|
||||
import unittest
|
||||
|
||||
|
|
@ -41,6 +42,22 @@ def facebook_mock(url, request):
|
|||
def facebook_mock_count(url, request):
|
||||
return 'Hello from Facebook'
|
||||
|
||||
@urlmatch(netloc=r'(.*\.)?google\.com$', path=r'^/$', method='POST')
|
||||
@remember_called
|
||||
def google_mock_store_requests(url, request):
|
||||
return 'Posting at Google'
|
||||
|
||||
|
||||
@all_requests
|
||||
def charset_utf8(url, request):
|
||||
return {
|
||||
'content': u'Motörhead'.encode('utf-8'),
|
||||
'status_code': 200,
|
||||
'headers': {
|
||||
'Content-Type': 'text/plain; charset=utf-8'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def any_mock(url, request):
|
||||
return 'Hello from %s' % (url.netloc,)
|
||||
|
|
@ -112,6 +129,13 @@ class MockTest(unittest.TestCase):
|
|||
with HTTMock(response_content):
|
||||
self.assertRaises(TypeError, requests.get, 'http://example.com/')
|
||||
|
||||
def test_encoding_from_contenttype(self):
|
||||
with HTTMock(charset_utf8):
|
||||
r = requests.get('http://example.com/')
|
||||
self.assertEqual(r.encoding, 'utf-8')
|
||||
self.assertEqual(r.text, u'Motörhead')
|
||||
self.assertEqual(r.content, r.text.encode('utf-8'))
|
||||
|
||||
|
||||
class DecoratorTest(unittest.TestCase):
|
||||
|
||||
|
|
@ -334,3 +358,13 @@ class RememberCalledTest(unittest.TestCase):
|
|||
|
||||
self.several_calls(1, requests.get, 'http://facebook.com/')
|
||||
self.assertEquals(facebook_mock_count.call['count'], 4)
|
||||
|
||||
def test_store_several_requests(self):
|
||||
with HTTMock(google_mock_store_requests):
|
||||
payload = {"query": "foo"}
|
||||
requests.post('http://google.com', data=payload)
|
||||
|
||||
self.assertTrue(google_mock_store_requests.call['called'])
|
||||
self.assertEqual(google_mock_store_requests.call['count'], 1)
|
||||
request = google_mock_store_requests.call['requests'][0]
|
||||
self.assertEqual(request.body, 'query=foo')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue