Hello community, here is the log from the commit of package python-requests-mock for openSUSE:Factory checked in at 2017-06-22 10:40:42 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-requests-mock (Old) and /work/SRC/openSUSE:Factory/.python-requests-mock.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-requests-mock" Thu Jun 22 10:40:42 2017 rev:7 rq:505524 version:1.3.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-requests-mock/python-requests-mock.changes 2017-06-08 15:02:33.126842384 +0200 +++ /work/SRC/openSUSE:Factory/.python-requests-mock.new/python-requests-mock.changes 2017-06-22 10:40:44.950609638 +0200 @@ -1,0 +2,15 @@ +Wed Jun 14 16:37:14 UTC 2017 - dmueller@suse.com + +- fix build for SLE12 + +------------------------------------------------------------------- +Sat Jun 10 07:47:41 UTC 2017 - dmueller@suse.com + +- update to 1.3.0: + * Add a releasenote for additional_matcher + * Add documentation for the exception response + * Fix occurences of `adatper` + * Type check the empty string when creating repsonse + * Allow arbirtrary matcher to be add to match + +------------------------------------------------------------------- Old: ---- requests-mock-1.2.0.tar.gz New: ---- requests-mock-1.3.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-requests-mock.spec ++++++ --- /var/tmp/diff_new_pack.YRxBVF/_old 2017-06-22 10:40:46.626373370 +0200 +++ /var/tmp/diff_new_pack.YRxBVF/_new 2017-06-22 10:40:46.626373370 +0200 @@ -19,7 +19,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %bcond_without test Name: python-requests-mock -Version: 1.2.0 +Version: 1.3.0 Release: 0 Summary: Mock out responses from the requests package License: Apache-2.0 @@ -37,10 +37,10 @@ BuildRequires: %{python_module testrepository >= 0.0.18} BuildRequires: %{python_module testtools} BuildRequires: fdupes -BuildRequires: python3-dbm Requires: python-requests >= 1.1 Requires: python-six %ifpython3 +BuildRequires: python3-dbm Requires: python3-dbm %endif BuildRoot: %{_tmppath}/%{name}-%{version}-build ++++++ requests-mock-1.2.0.tar.gz -> requests-mock-1.3.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/ChangeLog new/requests-mock-1.3.0/ChangeLog --- old/requests-mock-1.2.0/ChangeLog 2016-12-05 02:24:47.000000000 +0100 +++ new/requests-mock-1.3.0/ChangeLog 2017-02-01 06:38:55.000000000 +0100 @@ -1,6 +1,15 @@ CHANGES ======= +1.3.0 +----- + +* Add a releasenote for additional_matcher +* Add documentation for the exception response +* Fix occurences of `adatper` +* Type check the empty string when creating repsonse +* Allow arbirtrary matcher to be add to match + 1.2.0 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/PKG-INFO new/requests-mock-1.3.0/PKG-INFO --- old/requests-mock-1.2.0/PKG-INFO 2016-12-05 02:24:48.000000000 +0100 +++ new/requests-mock-1.3.0/PKG-INFO 2017-02-01 06:38:55.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: requests-mock -Version: 1.2.0 +Version: 1.3.0 Summary: Mock out responses from the requests package Home-page: https://requests-mock.readthedocs.org/ Author: Jamie Lennox @@ -23,7 +23,7 @@ ========== Everything in `requests`_ eventually goes through an adapter to do the transport work. - `requests-mock` creates a custom `adatper` that allows you to predefine responses when certain URIs are called. + `requests-mock` creates a custom `adapter` that allows you to predefine responses when certain URIs are called. There are then a number of methods provided to get the adapter used. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/README.rst new/requests-mock-1.3.0/README.rst --- old/requests-mock-1.2.0/README.rst 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/README.rst 2017-02-01 06:37:40.000000000 +0100 @@ -15,7 +15,7 @@ ========== Everything in `requests`_ eventually goes through an adapter to do the transport work. -`requests-mock` creates a custom `adatper` that allows you to predefine responses when certain URIs are called. +`requests-mock` creates a custom `adapter` that allows you to predefine responses when certain URIs are called. There are then a number of methods provided to get the adapter used. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/doc/source/matching.rst new/requests-mock-1.3.0/doc/source/matching.rst --- old/requests-mock-1.2.0/doc/source/matching.rst 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/doc/source/matching.rst 2017-02-01 06:37:40.000000000 +0100 @@ -209,6 +209,38 @@ requests_mock.exceptions.NoMockAddress: No mock address: POST mock://test.com/headers +Additional Matchers +=================== + +As distinct from `Custom Matching` below we can add an additional matcher callback that lets us do more dynamic matching in addition to the standard options. +This is handled by a callback function that takes the request as a parameter: + +.. doctest:: + :hide: + + >>> import requests + >>> import requests_mock + >>> adapter = requests_mock.Adapter() + >>> session = requests.Session() + >>> session.mount('mock', adapter) + +.. doctest:: + + >>> def match_request_text(request): + ... # request.text may be None, or '' prevents a TypeError. + ... return 'hello' in (request.text or '') + ... + >>> adapter.register_uri('POST', 'mock://test.com/additional', additional_matcher=match_request_text, text='resp') + >>> session.post('mock://test.com/headers', data='hello world').text + 'resp' + >>> resp = session.post('mock://test.com/additional', data='goodbye world') + Traceback (most recent call last): + ... + requests_mock.exceptions.NoMockAddress: No mock address: POST mock://test.com/additional + +Using this mechanism lets you do custom handling such as parsing yaml or XML structures and matching on features of that data or anything else that is not directly handled via the provided matchers rather than build in every possible option to `requests_mock`. + + Custom Matching =============== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/doc/source/response.rst new/requests-mock-1.3.0/doc/source/response.rst --- old/requests-mock-1.2.0/doc/source/response.rst 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/doc/source/response.rst 2017-02-01 06:37:40.000000000 +0100 @@ -43,6 +43,7 @@ :content: A byte string. This should be used for including binary data in responses. :body: A file like object that contains a `.read()` function. :raw: A prepopulated :py:class:`urllib3.response.HTTPResponse` to be returned. +:exc: An exception that will be raised instead of returning a response. These options are named to coincide with the parameters on a :py:class:`requests.Response` object. For example: @@ -133,6 +134,20 @@ >>> resp.status_code, resp.headers, resp.text (200, {'Test1': 'value1', 'Test2': 'value2'}, 'response') +Raising Exceptions +================== + +When trying to emulate a connection timeout or SSLError you need to be able to throw an exception when a mock is hit. +This can be achieved by passing the `exc` parameter instead of a body parameter. + +.. doctest:: + + >>> adapter.register_uri('GET', 'mock://test.com/6', exc=requests.exceptions.ConnectTimeout), + >>> session.get('mock://test.com/6') + Traceback (most recent call last): + ... + ConnectTimeout: + Handling Cookies ================ @@ -145,8 +160,8 @@ .. doctest:: - >>> adapter.register_uri('GET', 'mock://test.com/6', cookies={'foo': 'bar'}), - >>> resp = session.get('mock://test.com/6') + >>> adapter.register_uri('GET', 'mock://test.com/7', cookies={'foo': 'bar'}), + >>> resp = session.get('mock://test.com/7') >>> resp.cookies['foo'] 'bar' @@ -156,8 +171,8 @@ >>> jar = requests_mock.CookieJar() >>> jar.set('foo', 'bar', domain='.test.com', path='/baz') - >>> adapter.register_uri('GET', 'mock://test.com/7', cookies=jar), - >>> resp = session.get('mock://test.com/7') + >>> adapter.register_uri('GET', 'mock://test.com/8', cookies=jar), + >>> resp = session.get('mock://test.com/8') >>> resp.cookies['foo'] 'bar' >>> resp.cookies.list_paths() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/releasenotes/notes/additional-matcher-5c5cd466a6d70080.yaml new/requests-mock-1.3.0/releasenotes/notes/additional-matcher-5c5cd466a6d70080.yaml --- old/requests-mock-1.2.0/releasenotes/notes/additional-matcher-5c5cd466a6d70080.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/requests-mock-1.3.0/releasenotes/notes/additional-matcher-5c5cd466a6d70080.yaml 2017-02-01 06:37:40.000000000 +0100 @@ -0,0 +1,4 @@ +--- +features: + - Allow specifying an `additional_matcher` to the mocker that will call a + function to allow a user to add their own custom request matching logic. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/adapter.py new/requests-mock-1.3.0/requests_mock/adapter.py --- old/requests-mock-1.2.0/requests_mock/adapter.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/adapter.py 2017-02-01 06:37:40.000000000 +0100 @@ -66,7 +66,7 @@ """Contains all the information about a provided URL to match.""" def __init__(self, method, url, responses, complete_qs, request_headers, - real_http, case_sensitive): + additional_matcher, real_http, case_sensitive): """ :param bool complete_qs: Match the entire query string. By default URLs match if all the provided matcher query arguments are matched and @@ -81,6 +81,7 @@ self._complete_qs = complete_qs self._request_headers = request_headers self._real_http = real_http + self._additional_matcher = additional_matcher # url can be a regex object or ANY so don't always run urlparse if isinstance(url, six.string_types): @@ -169,10 +170,20 @@ return True + def _match_additional(self, request): + if callable(self._additional_matcher): + return self._additional_matcher(request) + + if self._additional_matcher is not None: + raise TypeError("Unexpected format of additional matcher.") + + return True + def _match(self, request): return (self._match_method(request) and self._match_url(request) and - self._match_headers(request)) + self._match_headers(request) and + self._match_additional(request)) def __call__(self, request): if not self._match(request): @@ -231,6 +242,7 @@ :param str url: The URL to match. """ complete_qs = kwargs.pop('complete_qs', False) + additional_matcher = kwargs.pop('additional_matcher', None) request_headers = kwargs.pop('request_headers', {}) real_http = kwargs.pop('_real_http', False) @@ -255,6 +267,7 @@ responses, case_sensitive=self._case_sensitive, complete_qs=complete_qs, + additional_matcher=additional_matcher, request_headers=request_headers, real_http=real_http) self.add_matcher(matcher) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/response.py new/requests-mock-1.3.0/requests_mock/response.py --- old/requests-mock-1.2.0/requests_mock/response.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/response.py 2017-02-01 06:37:40.000000000 +0100 @@ -147,9 +147,9 @@ json = kwargs.pop('json', None) encoding = None - if content and not isinstance(content, six.binary_type): + if content is not None and not isinstance(content, six.binary_type): raise TypeError('Content should be binary data') - if text and not isinstance(text, six.string_types): + if text is not None and not isinstance(text, six.string_types): raise TypeError('Text should be string data') if json is not None: @@ -207,12 +207,12 @@ content = self._params.get('content') text = self._params.get('text') - if content and not (callable(content) or - isinstance(content, six.binary_type)): + if content is not None and not (callable(content) or + isinstance(content, six.binary_type)): raise TypeError('Content should be a callback or binary data') - if text and not (callable(text) or - isinstance(text, six.string_types)): + if text is not None and not (callable(text) or + isinstance(text, six.string_types)): raise TypeError('Text should be a callback or string data') def get_response(self, request): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/tests/test_adapter.py new/requests-mock-1.3.0/requests_mock/tests/test_adapter.py --- old/requests-mock-1.2.0/requests_mock/tests/test_adapter.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/tests/test_adapter.py 2017-02-01 06:37:40.000000000 +0100 @@ -265,6 +265,13 @@ self.url, content=six.u('unicode')) + def test_dont_pass_empty_string_as_content(self): + self.assertRaises(TypeError, + self.adapter.register_uri, + 'GET', + self.url, + content=six.u('')) + def test_dont_pass_bytes_as_text(self): if six.PY2: self.skipTest('Cannot enforce byte behaviour in PY2') @@ -275,6 +282,16 @@ self.url, text=six.b('bytes')) + def test_dont_pass_empty_string_as_text(self): + if six.PY2: + self.skipTest('Cannot enforce byte behaviour in PY2') + + self.assertRaises(TypeError, + self.adapter.register_uri, + 'GET', + self.url, + text=six.b('')) + def test_dont_pass_non_str_as_content(self): self.assertRaises(TypeError, self.adapter.register_uri, @@ -357,7 +374,7 @@ self.assertTrue(self.adapter.called) self.assertFalse(m.called_once) - def test_adapter_picks_correct_adatper(self): + def test_adapter_picks_correct_adapter(self): good = '%s://test3.url/' % self.PREFIX self.adapter.register_uri('GET', '%s://test1.url' % self.PREFIX, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/tests/test_matcher.py new/requests-mock-1.3.0/requests_mock/tests/test_matcher.py --- old/requests-mock-1.2.0/requests_mock/tests/test_matcher.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/tests/test_matcher.py 2017-02-01 06:37:40.000000000 +0100 @@ -27,24 +27,28 @@ request_method='GET', complete_qs=False, headers=None, + request_data=None, request_headers={}, + additional_matcher=None, real_http=False, case_sensitive=False): matcher = adapter._Matcher(matcher_method, target, [], - complete_qs, - request_headers, + complete_qs=complete_qs, + additional_matcher=additional_matcher, + request_headers=request_headers, real_http=real_http, case_sensitive=case_sensitive) request = adapter._RequestObjectProxy._create(request_method, url, - headers) + headers, + data=request_data) return matcher._match(request) def assertMatch(self, - target, - url, + target=ANY, + url='http://example.com/requests-mock', matcher_method='GET', request_method='GET', **kwargs): @@ -58,8 +62,8 @@ (matcher_method, target, request_method, url)) def assertMatchBoth(self, - target, - url, + target=ANY, + url='http://example.com/requests-mock', matcher_method='GET', request_method='GET', **kwargs): @@ -75,8 +79,8 @@ **kwargs) def assertNoMatch(self, - target, - url, + target=ANY, + url='http://example.com/requests-mock', matcher_method='GET', request_method='GET', **kwargs): @@ -90,8 +94,8 @@ (matcher_method, target, request_method, url)) def assertNoMatchBoth(self, - target, - url, + target=ANY, + url='http://example.com/requests-mock', matcher_method='GET', request_method='GET', **kwargs): @@ -265,3 +269,18 @@ self.assertSensitiveMatch('http://abc.com/path?abcd=efGH', 'http://abc.com/path?abcd=eFGH') + + def test_additional_matcher(self): + + def test_match_body(request): + return 'hello' in request.text + + self.assertMatch(request_method='POST', + matcher_method='POST', + request_data='hello world', + additional_matcher=test_match_body) + + self.assertNoMatch(request_method='POST', + matcher_method='POST', + request_data='goodbye world', + additional_matcher=test_match_body) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/tests/test_mocker.py new/requests-mock-1.3.0/requests_mock/tests/test_mocker.py --- old/requests-mock-1.2.0/requests_mock/tests/test_mocker.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/tests/test_mocker.py 2017-02-01 06:37:40.000000000 +0100 @@ -409,3 +409,20 @@ self.assertEqual(6, m1.call_count) self.assertEqual(2, r1.call_count) + + @requests_mock.mock() + def test_mocker_additional(self, m): + url = 'http://www.example.com' + good_text = 'success' + + def additional_cb(req): + return 'hello' in req.text + + m.post(url, additional_matcher=additional_cb, text=good_text) + + self.assertEqual(good_text, + requests.post(url, data='hello world').text) + self.assertRaises(exceptions.NoMockAddress, + requests.post, + url, + data='goodbye world') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock/tests/test_response.py new/requests-mock-1.3.0/requests_mock/tests/test_response.py --- old/requests-mock-1.2.0/requests_mock/tests/test_response.py 2016-12-05 02:23:37.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock/tests/test_response.py 2017-02-01 06:37:40.000000000 +0100 @@ -46,9 +46,14 @@ self.assertRaises(TypeError, self.create_response, text=55) self.assertRaises(TypeError, self.create_response, text={'a': 1}) + # this only works on python 2 because bytes is a string + if six.PY3: + self.assertRaises(TypeError, self.create_response, text=six.b('')) + def test_text_type(self): self.assertRaises(TypeError, self.create_response, content=six.u('t')) self.assertRaises(TypeError, self.create_response, content={'a': 1}) + self.assertRaises(TypeError, self.create_response, content=six.u('')) def test_json_body(self): data = {'a': 1} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock.egg-info/PKG-INFO new/requests-mock-1.3.0/requests_mock.egg-info/PKG-INFO --- old/requests-mock-1.2.0/requests_mock.egg-info/PKG-INFO 2016-12-05 02:24:47.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock.egg-info/PKG-INFO 2017-02-01 06:38:55.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: requests-mock -Version: 1.2.0 +Version: 1.3.0 Summary: Mock out responses from the requests package Home-page: https://requests-mock.readthedocs.org/ Author: Jamie Lennox @@ -23,7 +23,7 @@ ========== Everything in `requests`_ eventually goes through an adapter to do the transport work. - `requests-mock` creates a custom `adatper` that allows you to predefine responses when certain URIs are called. + `requests-mock` creates a custom `adapter` that allows you to predefine responses when certain URIs are called. There are then a number of methods provided to get the adapter used. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock.egg-info/SOURCES.txt new/requests-mock-1.3.0/requests_mock.egg-info/SOURCES.txt --- old/requests-mock-1.2.0/requests_mock.egg-info/SOURCES.txt 2016-12-05 02:24:48.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock.egg-info/SOURCES.txt 2017-02-01 06:38:55.000000000 +0100 @@ -29,6 +29,7 @@ doc/source/readme.rst doc/source/response.rst releasenotes/notes/Add-called_once-property-a69546448cbd5542.yaml +releasenotes/notes/additional-matcher-5c5cd466a6d70080.yaml releasenotes/notes/case-insensitive-matching-a3143221359bbf2d.yaml releasenotes/notes/fixture-extras-699a5b5fb5bd6aab.yaml requests_mock/__init__.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/requests_mock.egg-info/pbr.json new/requests-mock-1.3.0/requests_mock.egg-info/pbr.json --- old/requests-mock-1.2.0/requests_mock.egg-info/pbr.json 2016-12-05 02:24:47.000000000 +0100 +++ new/requests-mock-1.3.0/requests_mock.egg-info/pbr.json 2017-02-01 06:38:55.000000000 +0100 @@ -1 +1 @@ -{"git_version": "95dffef", "is_release": true} \ No newline at end of file +{"git_version": "aa3e87c", "is_release": true} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/requests-mock-1.2.0/setup.cfg new/requests-mock-1.3.0/setup.cfg --- old/requests-mock-1.2.0/setup.cfg 2016-12-05 02:24:48.000000000 +0100 +++ new/requests-mock-1.3.0/setup.cfg 2017-02-01 06:38:55.000000000 +0100 @@ -39,5 +39,4 @@ [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0