Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Damien Toma committed Jan 16, 2018
1 parent 2685e5d commit 6875426
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion coreapi/transports/http.py
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_integration.py
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_transport.py
Expand Up @@ -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)
Expand All @@ -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'"}'
Expand All @@ -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'"}'
Expand All @@ -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)}))
Expand All @@ -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)
Expand Down

0 comments on commit 6875426

Please sign in to comment.