-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
MISSING
in params and headers
This is an internal feature of the client class. Entirely independently from the payload filtering process (which needs to handle the complex payload types which may be used), a simple helper for `dict|None` data is used to strip out MISSING from any query params and headers before sending. Testing also confirms the behavior of MISSING on simple JSON and Form-POST data.
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import json | ||
import urllib.parse | ||
|
||
import pytest | ||
|
||
from globus_sdk import utils | ||
from globus_sdk._testing import RegisteredResponse, get_last_request, load_response | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup_mock_responses(): | ||
load_response( | ||
RegisteredResponse( | ||
path="https://foo.api.globus.org/bar", | ||
json={"foo": "bar"}, | ||
) | ||
) | ||
load_response( | ||
RegisteredResponse( | ||
path="https://foo.api.globus.org/bar", | ||
method="POST", | ||
json={"foo": "bar"}, | ||
) | ||
) | ||
|
||
|
||
def test_query_params_can_filter_missing(client): | ||
res = client.get("/bar", query_params={"foo": "bar", "baz": utils.MISSING}) | ||
assert res.http_status == 200 | ||
req = get_last_request() | ||
assert req.params == {"foo": "bar"} | ||
|
||
|
||
def test_headers_can_filter_missing(client): | ||
res = client.get("/bar", headers={"foo": "bar", "baz": utils.MISSING}) | ||
assert res.http_status == 200 | ||
req = get_last_request() | ||
assert req.headers["foo"] == "bar" | ||
assert "baz" not in req.headers | ||
|
||
|
||
def test_json_body_can_filter_missing(client): | ||
res = client.post("/bar", data={"foo": "bar", "baz": utils.MISSING}) | ||
assert res.http_status == 200 | ||
req = get_last_request() | ||
sent = json.loads(req.body) | ||
assert sent == {"foo": "bar"} | ||
|
||
|
||
def test_form_body_can_filter_missing(client): | ||
res = client.post( | ||
"/bar", data={"foo": "bar", "baz": utils.MISSING}, encoding="form" | ||
) | ||
assert res.http_status == 200 | ||
req = get_last_request() | ||
sent = urllib.parse.parse_qs(req.body) | ||
assert sent == {"foo": ["bar"]} |