From f759a6beeba36c3da42262761c30965a32e7c4dc Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Wed, 16 May 2018 16:43:03 +0200 Subject: [PATCH 01/11] First release rhbz#1577198 --- .gitignore | 1 + README.md | 3 - python-httmock.spec | 83 +++++++++++ sources | 1 + tests.py | 336 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 .gitignore delete mode 100644 README.md create mode 100644 python-httmock.spec create mode 100644 sources create mode 100644 tests.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adc2300 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/httmock-1.2.6.tar.gz diff --git a/README.md b/README.md deleted file mode 100644 index 255b310..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# python-httmock - -mocking library for requests \ No newline at end of file diff --git a/python-httmock.spec b/python-httmock.spec new file mode 100644 index 0000000..99724d5 --- /dev/null +++ b/python-httmock.spec @@ -0,0 +1,83 @@ +# Created by pyp2rpm-3.3.0 +%global pypi_name httmock + +Name: python-%{pypi_name} +Version: 1.2.6 +Release: 1%{?dist} +Summary: A mocking library for requests + +License: ASL 2.0 +URL: https://github.com/patrys/httmock +Source0: https://files.pythonhosted.org/packages/source/h/httmock/httmock-%{version}.tar.gz +Source1: https://raw.githubusercontent.com/patrys/httmock/%{version}/tests.py +BuildArch: noarch + +BuildRequires: python2-devel +BuildRequires: python2dist(requests) >= 1.0.0 +BuildRequires: python2dist(setuptools) + +BuildRequires: python3-devel +BuildRequires: python3dist(requests) >= 1.0.0 +BuildRequires: python3dist(setuptools) + +%description +A mocking library for requests for Python. +You can use it to mock third-party APIs and test libraries +that use requests internally. + +%package -n python2-%{pypi_name} +Summary: %{summary} +%{?python_provide:%python_provide python2-%{pypi_name}} + +Requires: python2dist(requests) >= 1.0.0 +%description -n python2-%{pypi_name} +A mocking library for requests for Python. +You can use it to mock third-party APIs and test libraries +that use requests internally. + +%package -n python3-%{pypi_name} +Summary: %{summary} +%{?python_provide:%python_provide python3-%{pypi_name}} + +Requires: python3dist(requests) >= 1.0.0 +%description -n python3-%{pypi_name} +A mocking library for requests for Python. +You can use it to mock third-party APIs and test libraries +that use requests internally. + +%prep +%autosetup -n %{pypi_name}-%{version} +# Remove bundled egg-info +rm -rf %{pypi_name}.egg-info +cp %{SOURCE1} . + +%build +%py2_build +%py3_build + +%install +# Must do the default python version install last because +# the scripts in /usr/bin are overwritten with every setup.py install. +%py2_install +%py3_install + +%check +%{__python2} setup.py test +%{__python3} setup.py test + +%files -n python2-%{pypi_name} +%license LICENSE +%doc README.md +%{python2_sitelib}/%{pypi_name}.py* +%{python2_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info + +%files -n python3-%{pypi_name} +%license LICENSE +%doc README.md +%{python3_sitelib}/__pycache__/* +%{python3_sitelib}/%{pypi_name}.py +%{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info + +%changelog +* Fri May 11 2018 Steve Traylen - 1.2.6-1 +- Initial package. diff --git a/sources b/sources new file mode 100644 index 0000000..be3e2e0 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (httmock-1.2.6.tar.gz) = a31b4a28383c052bb15ca5c2f07f96c8654f44d15df05fa7972e410b9c1a40f70c6ed48256dd7cf3a0486f8555142ba59330edd9c8beb003785ecdb535ddfb69 diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..7a13cb3 --- /dev/null +++ b/tests.py @@ -0,0 +1,336 @@ +import requests +import unittest + +from httmock import (all_requests, response, urlmatch, with_httmock, HTTMock, + remember_called, text_type, binary_type) + + +@urlmatch(scheme='swallow') +def unmatched_scheme(url, request): + raise AssertionError('This is outrageous') + + +@urlmatch(path=r'^never$') +def unmatched_path(url, request): + raise AssertionError('This is outrageous') + + +@urlmatch(method='post') +def unmatched_method(url, request): + raise AssertionError('This is outrageous') + + +@urlmatch(netloc=r'(.*\.)?google\.com$', path=r'^/$') +def google_mock(url, request): + return 'Hello from Google' + + +@urlmatch(netloc=r'(.*\.)?google\.com$', path=r'^/$') +@remember_called +def google_mock_count(url, request): + return 'Hello from Google' + + +@urlmatch(scheme='http', netloc=r'(.*\.)?facebook\.com$') +def facebook_mock(url, request): + return 'Hello from Facebook' + + +@urlmatch(scheme='http', netloc=r'(.*\.)?facebook\.com$') +@remember_called +def facebook_mock_count(url, request): + return 'Hello from Facebook' + + +def any_mock(url, request): + return 'Hello from %s' % (url.netloc,) + + +def dict_any_mock(url, request): + return { + 'content': 'Hello from %s' % (url.netloc,), + 'status_code': 200 + } + + +def example_400_response(url, response): + r = requests.Response() + r.status_code = 400 + r._content = b'Bad request.' + return r + + +class MockTest(unittest.TestCase): + + def test_return_type(self): + with HTTMock(any_mock): + r = requests.get('http://domain.com/') + self.assertTrue(isinstance(r, requests.Response)) + self.assertTrue(isinstance(r.content, binary_type)) + self.assertTrue(isinstance(r.text, text_type)) + + def test_scheme_fallback(self): + with HTTMock(unmatched_scheme, any_mock): + r = requests.get('http://example.com/') + self.assertEqual(r.content, b'Hello from example.com') + + def test_path_fallback(self): + with HTTMock(unmatched_path, any_mock): + r = requests.get('http://example.com/') + self.assertEqual(r.content, b'Hello from example.com') + + def test_method_fallback(self): + with HTTMock(unmatched_method, any_mock): + r = requests.get('http://example.com/') + self.assertEqual(r.content, b'Hello from example.com') + + def test_netloc_fallback(self): + with HTTMock(google_mock, facebook_mock): + r = requests.get('http://google.com/') + self.assertEqual(r.content, b'Hello from Google') + with HTTMock(google_mock, facebook_mock): + r = requests.get('http://facebook.com/') + self.assertEqual(r.content, b'Hello from Facebook') + + def test_400_response(self): + with HTTMock(example_400_response): + r = requests.get('http://example.com/') + self.assertEqual(r.status_code, 400) + self.assertEqual(r.content, b'Bad request.') + + def test_real_request_fallback(self): + with HTTMock(any_mock): + with HTTMock(google_mock, facebook_mock): + r = requests.get('http://example.com/') + self.assertEqual(r.status_code, 200) + self.assertEqual(r.content, b'Hello from example.com') + + def test_invalid_intercept_response_raises_value_error(self): + @all_requests + def response_content(url, request): + return -1 + with HTTMock(response_content): + self.assertRaises(TypeError, requests.get, 'http://example.com/') + + +class DecoratorTest(unittest.TestCase): + + @with_httmock(any_mock) + def test_decorator(self): + r = requests.get('http://example.com/') + self.assertEqual(r.content, b'Hello from example.com') + + @with_httmock(any_mock) + def test_iter_lines(self): + r = requests.get('http://example.com/') + self.assertEqual(list(r.iter_lines()), + [b'Hello from example.com']) + + +class AllRequestsDecoratorTest(unittest.TestCase): + + def test_all_requests_response(self): + @all_requests + def response_content(url, request): + return {'status_code': 200, 'content': 'Oh hai'} + with HTTMock(response_content): + r = requests.get('https://example.com/') + self.assertEqual(r.status_code, 200) + self.assertEqual(r.content, b'Oh hai') + + def test_all_str_response(self): + @all_requests + def response_content(url, request): + return 'Hello' + with HTTMock(response_content): + r = requests.get('https://example.com/') + self.assertEqual(r.content, b'Hello') + + +class AllRequestsMethodDecoratorTest(unittest.TestCase): + @all_requests + def response_content(self, url, request): + return {'status_code': 200, 'content': 'Oh hai'} + + def test_all_requests_response(self): + with HTTMock(self.response_content): + r = requests.get('https://example.com/') + self.assertEqual(r.status_code, 200) + self.assertEqual(r.content, b'Oh hai') + + @all_requests + def string_response_content(self, url, request): + return 'Hello' + + def test_all_str_response(self): + with HTTMock(self.string_response_content): + r = requests.get('https://example.com/') + self.assertEqual(r.content, b'Hello') + + +class UrlMatchMethodDecoratorTest(unittest.TestCase): + @urlmatch(netloc=r'(.*\.)?google\.com$', path=r'^/$') + def google_mock(self, url, request): + return 'Hello from Google' + + @urlmatch(scheme='http', netloc=r'(.*\.)?facebook\.com$') + def facebook_mock(self, url, request): + return 'Hello from Facebook' + + @urlmatch(query=r'.*page=test') + def query_page_mock(self, url, request): + return 'Hello from test page' + + def test_netloc_fallback(self): + with HTTMock(self.google_mock, facebook_mock): + r = requests.get('http://google.com/') + self.assertEqual(r.content, b'Hello from Google') + with HTTMock(self.google_mock, facebook_mock): + r = requests.get('http://facebook.com/') + self.assertEqual(r.content, b'Hello from Facebook') + + def test_query(self): + with HTTMock(self.query_page_mock, self.google_mock): + r = requests.get('http://google.com/?page=test') + r2 = requests.get('http://google.com/') + self.assertEqual(r.content, b'Hello from test page') + self.assertEqual(r2.content, b'Hello from Google') + + +class ResponseTest(unittest.TestCase): + + content = {'name': 'foo', 'ipv4addr': '127.0.0.1'} + content_list = list(content.keys()) + + def test_response_auto_json(self): + r = response(0, self.content) + self.assertTrue(isinstance(r.content, binary_type)) + self.assertTrue(isinstance(r.text, text_type)) + self.assertEqual(r.json(), self.content) + r = response(0, self.content_list) + self.assertEqual(r.json(), self.content_list) + + def test_response_status_code(self): + r = response(200) + self.assertEqual(r.status_code, 200) + + def test_response_headers(self): + r = response(200, None, {'Content-Type': 'application/json'}) + self.assertEqual(r.headers['content-type'], 'application/json') + + def test_response_cookies(self): + @all_requests + def response_content(url, request): + return response(200, 'Foo', {'Set-Cookie': 'foo=bar;'}, + request=request) + with HTTMock(response_content): + r = requests.get('https://example.com/') + self.assertEqual(len(r.cookies), 1) + self.assertTrue('foo' in r.cookies) + self.assertEqual(r.cookies['foo'], 'bar') + + def test_response_session_cookies(self): + @all_requests + def response_content(url, request): + return response(200, 'Foo', {'Set-Cookie': 'foo=bar;'}, + request=request) + session = requests.Session() + with HTTMock(response_content): + r = session.get('https://foo_bar') + self.assertEqual(len(r.cookies), 1) + self.assertTrue('foo' in r.cookies) + self.assertEqual(r.cookies['foo'], 'bar') + self.assertEqual(len(session.cookies), 1) + self.assertTrue('foo' in session.cookies) + self.assertEqual(session.cookies['foo'], 'bar') + + def test_python_version_encoding_differences(self): + # Previous behavior would result in this test failing in Python3 due + # to how requests checks for utf-8 JSON content in requests.utils with: + # + # TypeError: Can't convert 'bytes' object to str implicitly + @all_requests + def get_mock(url, request): + return {'content': self.content, + 'headers': {'content-type': 'application/json'}, + 'status_code': 200, + 'elapsed': 5} + + with HTTMock(get_mock): + response = requests.get('http://example.com/') + self.assertEqual(self.content, response.json()) + + def test_mock_redirect(self): + @urlmatch(netloc='example.com') + def get_mock(url, request): + return {'status_code': 302, + 'headers': {'Location': 'http://google.com/'}} + + with HTTMock(get_mock, google_mock): + response = requests.get('http://example.com/') + self.assertEqual(len(response.history), 1) + self.assertEqual(response.content, b'Hello from Google') + + +class StreamTest(unittest.TestCase): + @with_httmock(any_mock) + def test_stream_request(self): + r = requests.get('http://domain.com/', stream=True) + self.assertEqual(r.raw.read(), b'Hello from domain.com') + + @with_httmock(dict_any_mock) + def test_stream_request_with_dict_mock(self): + r = requests.get('http://domain.com/', stream=True) + self.assertEqual(r.raw.read(), b'Hello from domain.com') + + @with_httmock(any_mock) + def test_non_stream_request(self): + r = requests.get('http://domain.com/') + self.assertEqual(r.raw.read(), b'') + + +class RememberCalledTest(unittest.TestCase): + + @staticmethod + def several_calls(count, method, *args, **kwargs): + results = [] + for _ in range(count): + results.append(method(*args, **kwargs)) + return results + + def test_several_calls(self): + with HTTMock(google_mock_count, facebook_mock_count): + results = self.several_calls( + 3, requests.get, 'http://facebook.com/') + + self.assertTrue(facebook_mock_count.call['called']) + self.assertEqual(facebook_mock_count.call['count'], 3) + + self.assertFalse(google_mock_count.call['called']) + self.assertEqual(google_mock_count.call['count'], 0) + + for r in results: + self.assertEqual(r.content, b'Hello from Facebook') + + # Negative case: cleanup call data + with HTTMock(facebook_mock_count): + results = self.several_calls( + 1, requests.get, 'http://facebook.com/') + + self.assertEquals(facebook_mock_count.call['count'], 1) + + @with_httmock(google_mock_count, facebook_mock_count) + def test_several_call_decorated(self): + results = self.several_calls(3, requests.get, 'http://facebook.com/') + + self.assertTrue(facebook_mock_count.call['called']) + self.assertEqual(facebook_mock_count.call['count'], 3) + + self.assertFalse(google_mock_count.call['called']) + self.assertEqual(google_mock_count.call['count'], 0) + + for r in results: + self.assertEqual(r.content, b'Hello from Facebook') + + self.several_calls(1, requests.get, 'http://facebook.com/') + self.assertEquals(facebook_mock_count.call['count'], 4) From 06f48356c82ff93903440a650351690b53a2c424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 19 Jun 2018 11:04:57 +0200 Subject: [PATCH 02/11] Rebuilt for Python 3.7 --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index 99724d5..6ab688e 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -3,7 +3,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 1%{?dist} +Release: 2%{?dist} Summary: A mocking library for requests License: ASL 2.0 @@ -79,5 +79,8 @@ cp %{SOURCE1} . %{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info %changelog +* Tue Jun 19 2018 Miro Hrončok - 1.2.6-2 +- Rebuilt for Python 3.7 + * Fri May 11 2018 Steve Traylen - 1.2.6-1 - Initial package. From 185c161e38729e75471f05c4c3a8e877b198ac46 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 14 Jul 2018 00:32:30 +0000 Subject: [PATCH 03/11] - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index 6ab688e..63f8d65 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -3,7 +3,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A mocking library for requests License: ASL 2.0 @@ -79,6 +79,9 @@ cp %{SOURCE1} . %{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info %changelog +* Sat Jul 14 2018 Fedora Release Engineering - 1.2.6-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild + * Tue Jun 19 2018 Miro Hrončok - 1.2.6-2 - Rebuilt for Python 3.7 From ba5b941d389db8e8e354f16ce62393b48bd2258c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 4 Jan 2019 15:20:15 +0100 Subject: [PATCH 04/11] Subpackage python2-httmock has been removed --- python-httmock.spec | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/python-httmock.spec b/python-httmock.spec index 63f8d65..bb2c61e 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -3,7 +3,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 3%{?dist} +Release: 4%{?dist} Summary: A mocking library for requests License: ASL 2.0 @@ -12,10 +12,6 @@ Source0: https://files.pythonhosted.org/packages/source/h/httmock/httmock Source1: https://raw.githubusercontent.com/patrys/httmock/%{version}/tests.py BuildArch: noarch -BuildRequires: python2-devel -BuildRequires: python2dist(requests) >= 1.0.0 -BuildRequires: python2dist(setuptools) - BuildRequires: python3-devel BuildRequires: python3dist(requests) >= 1.0.0 BuildRequires: python3dist(setuptools) @@ -25,16 +21,6 @@ A mocking library for requests for Python. You can use it to mock third-party APIs and test libraries that use requests internally. -%package -n python2-%{pypi_name} -Summary: %{summary} -%{?python_provide:%python_provide python2-%{pypi_name}} - -Requires: python2dist(requests) >= 1.0.0 -%description -n python2-%{pypi_name} -A mocking library for requests for Python. -You can use it to mock third-party APIs and test libraries -that use requests internally. - %package -n python3-%{pypi_name} Summary: %{summary} %{?python_provide:%python_provide python3-%{pypi_name}} @@ -52,25 +38,14 @@ rm -rf %{pypi_name}.egg-info cp %{SOURCE1} . %build -%py2_build %py3_build %install -# Must do the default python version install last because -# the scripts in /usr/bin are overwritten with every setup.py install. -%py2_install %py3_install %check -%{__python2} setup.py test %{__python3} setup.py test -%files -n python2-%{pypi_name} -%license LICENSE -%doc README.md -%{python2_sitelib}/%{pypi_name}.py* -%{python2_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info - %files -n python3-%{pypi_name} %license LICENSE %doc README.md @@ -79,6 +54,10 @@ cp %{SOURCE1} . %{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info %changelog +* Fri Jan 04 2019 Miro Hrončok - 1.2.6-4 +- Subpackage python2-httmock has been removed + See https://fedoraproject.org/wiki/Changes/Mass_Python_2_Package_Removal + * Sat Jul 14 2018 Fedora Release Engineering - 1.2.6-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild From a651d52507610e93dc1cdec9e48c9d4d1e012425 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Fri, 4 Jan 2019 21:47:37 +0100 Subject: [PATCH 05/11] Enable python dependency generator References: https://fedoraproject.org/wiki/Changes/EnablingPythonGeneratorsByDefault Signed-off-by: Igor Gnatenko --- python-httmock.spec | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/python-httmock.spec b/python-httmock.spec index bb2c61e..df363e3 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -1,9 +1,10 @@ +%{?python_enable_dependency_generator} # Created by pyp2rpm-3.3.0 %global pypi_name httmock Name: python-%{pypi_name} Version: 1.2.6 -Release: 4%{?dist} +Release: 5%{?dist} Summary: A mocking library for requests License: ASL 2.0 @@ -12,10 +13,6 @@ Source0: https://files.pythonhosted.org/packages/source/h/httmock/httmock Source1: https://raw.githubusercontent.com/patrys/httmock/%{version}/tests.py BuildArch: noarch -BuildRequires: python3-devel -BuildRequires: python3dist(requests) >= 1.0.0 -BuildRequires: python3dist(setuptools) - %description A mocking library for requests for Python. You can use it to mock third-party APIs and test libraries @@ -24,8 +21,10 @@ that use requests internally. %package -n python3-%{pypi_name} Summary: %{summary} %{?python_provide:%python_provide python3-%{pypi_name}} +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3dist(requests) >= 1.0.0 -Requires: python3dist(requests) >= 1.0.0 %description -n python3-%{pypi_name} A mocking library for requests for Python. You can use it to mock third-party APIs and test libraries @@ -54,6 +53,9 @@ cp %{SOURCE1} . %{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info %changelog +* Fri Jan 04 2019 Igor Gnatenko - 1.2.6-5 +- Enable python dependency generator + * Fri Jan 04 2019 Miro Hrončok - 1.2.6-4 - Subpackage python2-httmock has been removed See https://fedoraproject.org/wiki/Changes/Mass_Python_2_Package_Removal From 9587fb5b98f4aa4a65790e1618546ea36fb900c8 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sat, 2 Feb 2019 07:12:07 +0000 Subject: [PATCH 06/11] - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index df363e3..bcef5eb 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -4,7 +4,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 5%{?dist} +Release: 6%{?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 +* Sat Feb 02 2019 Fedora Release Engineering - 1.2.6-6 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + * Fri Jan 04 2019 Igor Gnatenko - 1.2.6-5 - Enable python dependency generator From 8a143fc15bead9186a4903340472c4d27c330b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 4 Jul 2019 16:21:49 +0200 Subject: [PATCH 07/11] Remove .0 from (Build)Requires See https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/NLMEX6MY7DQLWTD2PMX4WGC3L3ER4HFS/ --- python-httmock.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index bcef5eb..2a5384d 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -23,7 +23,7 @@ Summary: %{summary} %{?python_provide:%python_provide python3-%{pypi_name}} BuildRequires: python3-devel BuildRequires: python3-setuptools -BuildRequires: python3dist(requests) >= 1.0.0 +BuildRequires: python3dist(requests) >= 1 %description -n python3-%{pypi_name} A mocking library for requests for Python. From 5549c90fa1af92a1ab0c7e5039c9321a48721430 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Fri, 26 Jul 2019 13:54:30 +0000 Subject: [PATCH 08/11] - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index 2a5384d..6838656 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -4,7 +4,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 6%{?dist} +Release: 7%{?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 +* Fri Jul 26 2019 Fedora Release Engineering - 1.2.6-7 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + * Sat Feb 02 2019 Fedora Release Engineering - 1.2.6-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild From 3d96ff77f1a8d30aa5e585e4d7135bc9f4812fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 19 Aug 2019 10:40:58 +0200 Subject: [PATCH 09/11] Rebuilt for Python 3.8 --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index 6838656..c926987 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -4,7 +4,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 7%{?dist} +Release: 8%{?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 +* Mon Aug 19 2019 Miro Hrončok - 1.2.6-8 +- Rebuilt for Python 3.8 + * Fri Jul 26 2019 Fedora Release Engineering - 1.2.6-7 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild From 6f3b8629657a7b1001991981cba10d4b4d95f69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 3 Oct 2019 14:14:31 +0200 Subject: [PATCH 10/11] Rebuilt for Python 3.8.0rc1 (#1748018) --- python-httmock.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python-httmock.spec b/python-httmock.spec index c926987..a7c0490 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -4,7 +4,7 @@ Name: python-%{pypi_name} Version: 1.2.6 -Release: 8%{?dist} +Release: 9%{?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 +* Thu Oct 03 2019 Miro Hrončok - 1.2.6-9 +- Rebuilt for Python 3.8.0rc1 (#1748018) + * Mon Aug 19 2019 Miro Hrončok - 1.2.6-8 - Rebuilt for Python 3.8 From 5d192ad7854b41c1591455178409833d05347c7d Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Wed, 13 Nov 2019 12:06:58 +0100 Subject: [PATCH 11/11] Update to 1.3.0 --- .gitignore | 2 ++ python-httmock.spec | 7 +++++-- sources | 3 ++- tests.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index adc2300..99f6d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /httmock-1.2.6.tar.gz +/httmock-1.3.0.tar.gz +/tests.py diff --git a/python-httmock.spec b/python-httmock.spec index a7c0490..4de895e 100644 --- a/python-httmock.spec +++ b/python-httmock.spec @@ -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 - 1.3.0-1 +- Update to 1.3.0 + * Thu Oct 03 2019 Miro Hrončok - 1.2.6-9 - Rebuilt for Python 3.8.0rc1 (#1748018) diff --git a/sources b/sources index be3e2e0..29df162 100644 --- a/sources +++ b/sources @@ -1 +1,2 @@ -SHA512 (httmock-1.2.6.tar.gz) = a31b4a28383c052bb15ca5c2f07f96c8654f44d15df05fa7972e410b9c1a40f70c6ed48256dd7cf3a0486f8555142ba59330edd9c8beb003785ecdb535ddfb69 +SHA512 (tests.py) = f869c9923bdd68c8758c1937eb61a7b8e2aae1ef32dce9ca850460dfdfd8daae7c20e1e5b9c298c1ce600900cbe2c34ba9660bd0ded0dbd34e817e39a18eee72 +SHA512 (httmock-1.3.0.tar.gz) = f713ddf45675738582a3611e01a55babce2951231b34fb9ca6b1b64fcf60a3862994ff7ad4cd7a224a116c6acb1caa267978a7cb6fedd02676fa2a01f90e93aa diff --git a/tests.py b/tests.py index 7a13cb3..c396192 100644 --- a/tests.py +++ b/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')