From 27f4f6ed71703fe4787364090158a542ca954eb1 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 5 Oct 2017 15:02:10 +0100 Subject: [PATCH 1/5] Version 2.3.2 (Compat with API Star schemas) --- coreapi/__init__.py | 2 +- coreapi/codecs/corejson.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/coreapi/__init__.py b/coreapi/__init__.py index af3be54..c368812 100644 --- a/coreapi/__init__.py +++ b/coreapi/__init__.py @@ -4,7 +4,7 @@ from coreapi.document import Array, Document, Link, Object, Error, Field -__version__ = '2.3.1' +__version__ = '2.3.2' __all__ = [ 'Array', 'Document', 'Link', 'Object', 'Error', 'Field', 'Client', diff --git a/coreapi/codecs/corejson.py b/coreapi/codecs/corejson.py index fd88a58..f025533 100644 --- a/coreapi/codecs/corejson.py +++ b/coreapi/codecs/corejson.py @@ -32,13 +32,16 @@ def encode_schema_to_corejson(schema): - type_id = SCHEMA_CLASS_TO_TYPE_ID.get(schema.__class__, 'anything') + if hasattr(schema, 'typename'): + type_id = schema.typename + else: + type_id = SCHEMA_CLASS_TO_TYPE_ID.get(schema.__class__, 'anything') retval = { '_type': type_id, 'title': schema.title, 'description': schema.description } - if isinstance(schema, coreschema.Enum): + if hasattr(schema, 'enum'): retval['enum'] = schema.enum return retval From 2685e5dc7e2d3a56fffb4d680f58de6e9446a5ab Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 5 Oct 2017 15:04:25 +0100 Subject: [PATCH 2/5] Version 2.3.3 (Clean up PyPI package) --- coreapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreapi/__init__.py b/coreapi/__init__.py index c368812..92ac890 100644 --- a/coreapi/__init__.py +++ b/coreapi/__init__.py @@ -4,7 +4,7 @@ from coreapi.document import Array, Document, Link, Object, Error, Field -__version__ = '2.3.2' +__version__ = '2.3.3' __all__ = [ 'Array', 'Document', 'Link', 'Object', 'Error', 'Field', 'Client', From 687542679f64eafea4120de2fdeb92eefce5feb9 Mon Sep 17 00:00:00 2001 From: Damien Toma Date: Tue, 16 Jan 2018 14:36:15 +0800 Subject: [PATCH 3/5] Merge environment settings for SSL requests When using requests' builder, we bypass the environment settings, which include information about SSL certificates. This makes requests to a SSL endpoint fail. This commit adds a call to `session.merge_environment_settings` to fix this issue, and updates the test suite accordingly. --- coreapi/transports/http.py | 3 ++- tests/test_integration.py | 8 ++++---- tests/test_transport.py | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/coreapi/transports/http.py b/coreapi/transports/http.py index a548024..7338e61 100644 --- a/coreapi/transports/http.py +++ b/coreapi/transports/http.py @@ -376,7 +376,8 @@ def transition(self, link, decoders, params=None, link_ancestors=None, force_cod headers.update(self.headers) request = _build_http_request(session, url, method, headers, encoding, params) - response = session.send(request) + settings = session.merge_environment_settings(request.url, None, None, None, None) + response = session.send(request, **settings) result = _decode_result(response, decoders, force_codec) if isinstance(result, Document) and link_ancestors: diff --git a/tests/test_integration.py b/tests/test_integration.py index b38de9a..0a2e602 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -41,7 +41,7 @@ def test_dump(document): def test_get(monkeypatch): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'{"_type": "document", "example": 123}') monkeypatch.setattr(requests.Session, 'send', mockreturn) @@ -52,7 +52,7 @@ def mockreturn(self, request): def test_follow(monkeypatch, document): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'{"_type": "document", "example": 123}') monkeypatch.setattr(requests.Session, 'send', mockreturn) @@ -63,7 +63,7 @@ def mockreturn(self, request): def test_reload(monkeypatch): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'{"_type": "document", "example": 123}') monkeypatch.setattr(requests.Session, 'send', mockreturn) @@ -75,7 +75,7 @@ def mockreturn(self, request): def test_error(monkeypatch, document): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'{"_type": "error", "message": ["failed"]}') monkeypatch.setattr(requests.Session, 'send', mockreturn) diff --git a/tests/test_transport.py b/tests/test_transport.py index 09cb849..eeeb17a 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -47,7 +47,7 @@ def test_missing_hostname(): # Test basic transition types. def test_get(monkeypatch, http): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'{"_type": "document", "example": 123}') monkeypatch.setattr(requests.Session, 'send', mockreturn) @@ -58,7 +58,7 @@ def mockreturn(self, request): def test_get_with_parameters(monkeypatch, http): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): insert = request.path_url.encode('utf-8') return MockResponse( b'{"_type": "document", "url": "' + insert + b'"}' @@ -72,7 +72,7 @@ def mockreturn(self, request): def test_get_with_path_parameter(monkeypatch, http): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): insert = request.url.encode('utf-8') return MockResponse( b'{"_type": "document", "example": "' + insert + b'"}' @@ -90,7 +90,7 @@ def mockreturn(self, request): def test_post(monkeypatch, http): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): codec = CoreJSONCodec() body = force_text(request.body) content = codec.encode(Document(content={'data': json.loads(body)})) @@ -104,7 +104,7 @@ def mockreturn(self, request): def test_delete(monkeypatch, http): - def mockreturn(self, request): + def mockreturn(self, request, *args, **kwargs): return MockResponse(b'') monkeypatch.setattr(requests.Session, 'send', mockreturn) From c4000c26fcaca35f72ae3274049f76f24903d487 Mon Sep 17 00:00:00 2001 From: Saeed Esfandi Date: Tue, 30 Jan 2018 12:48:51 +0330 Subject: [PATCH 4/5] use input session for get default transports --- coreapi/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreapi/client.py b/coreapi/client.py index d02a59c..00b0057 100644 --- a/coreapi/client.py +++ b/coreapi/client.py @@ -105,7 +105,7 @@ def __init__(self, decoders=None, transports=None, auth=None, session=None): if decoders is None: decoders = get_default_decoders() if transports is None: - transports = get_default_transports(auth=auth) + transports = get_default_transports(auth=auth, session=session) self._decoders = itypes.List(decoders) self._transports = itypes.List(transports) From d264fd277a878ea40f9f75755e461f8a9418671f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 4 Jun 2018 09:19:12 +0100 Subject: [PATCH 5/5] Create LICENSE.md --- LICENSE.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e92b342 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,29 @@ +# License + +Copyright © 2017-present, Tom Christie. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.