8000 Merge environment settings for SSL requests · core-api/python-client@6875426 · GitHub
[go: up one dir, main page]

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

Commit 6875426

Browse files
author
Damien Toma
committed
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.
1 parent 2685e5d commit 6875426

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

coreapi/transports/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def transition(self, link, decoders, params=None, link_ancestors=None, force_cod
376376
headers.update(self.headers)
377377

378378
request = _build_http_request(session, url, method, headers, encoding, params)
379-
response = session.send(request)
379+
settings = session.merge_environment_settings(request.url, None, None, None, None)
380+
response = session.send(request, **settings)
380381
result = _decode_result(response, decoders, force_codec)
381382

382383
if isinstance(result, Document) and link_ancestors:

tests/test_integration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_dump(document):
4141

4242

4343
def test_get(monkeypatch):
44-
def mockreturn(self, request):
44+
def mockreturn(self, request, *args, **kwargs):
4545
return MockResponse(b'{"_type": "document", "example": 123}')
4646

4747
monkeypatch.setattr(requests.Session, 'send', mockreturn)
@@ -52,7 +52,7 @@ def mockreturn(self, request):
5252

5353

5454
def test_follow(monkeypatch, document):
55-
def mockreturn(self, request):
55+
def mockreturn(self, request, *args, **kwargs):
5656
return MockResponse(b'{"_type": "document", "example": 123}')
5757

5858
monkeypatch.setattr(requests.Session, 'send', mockreturn)
@@ -63,7 +63,7 @@ def mockreturn(self, request):
6363

6464

6565
def test_reload(monkeypatch):
66-
def mockreturn(self, request):
66+
def mockreturn(self, request, *args, **kwargs):
6767
return MockResponse(b'{"_type": "document", "example": 123}')
6868

6969
monkeypatch.setattr(requests.Session, 'send', mockreturn)
@@ -75,7 +75,7 @@ def mockreturn(self, request):
7575

7676

7777
def test_error(monkeypatch, document):
78-
def mockreturn(self, request):
78+
def mockreturn(self, request, *args, **kwargs):
7979
return MockResponse(b'{"_type": "error", "message": ["failed"]}')
8080

8181
monkeypatch.setattr(requests.Session, 'send', mockreturn)

tests/test_transport.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_missing_hostname():
4747
# Test basic transition types.
4848

4949
def test_get(monkeypatch, http):
50-
def mockreturn(self, request):
50+
def mockreturn(self, request, *args, **kwargs):
5151
return MockResponse(b'{"_type": "document", "example": 123}')
5252

5353
monkeypatch.setattr(requests.Session, 'send', mockreturn)
@@ -58,7 +58,7 @@ def mockreturn(self, request):
5858

5959

6060
def test_get_with_parameters(monkeypatch, http):
61-
def mockreturn(self, request):
61+
def mockreturn(self, request, *args, **kwargs):
6262
insert = request.path_url.encode('utf-8')
6363
return MockResponse(
6464
b'{"_type": "document", "url": "' + insert + b'"}'
@@ -72,7 +72,7 @@ def mockreturn(self, request):
7272

7373

7474
def test_get_with_path_parameter(monkeypatch, http):
75-
def mockreturn(self, request):
75+
def mockreturn(self, request, *args, **kwargs):
7676
insert = request.url.encode('utf-8')
7777
return MockResponse(
7878
b'{"_type": "document", "example": "' + insert + b'"}'
@@ -90,7 +90,7 @@ def mockreturn(self, request):
9090

9191

9292
def test_post(monkeypatch, http):
93-
def mockreturn(self, request):
93+
def mockreturn(self, request, *args, **kwargs):
9494
codec = CoreJSONCodec()
9595
body = force_text(request.body)
9696
content = codec.encode(Document(content={'data': json.loads(body)}))
@@ -104,7 +104,7 @@ def mockreturn(self, request):
104104

105105

106106
def test_delete(monkeypatch, http):
107-
def mockreturn(self, request):
107+
def mockreturn(self, request, *args, **kwargs):
108108
return MockResponse(b'')
109109

110110
monkeypatch.setattr(requests.Session, 'send', mockreturn)

0 commit comments

Comments
 (0)
0