-
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.
Merge pull request #885 from sirosen/introduce-missingtype
Introduce the MISSING sentinel and use it for HA timeout on GroupPolicies
- Loading branch information
Showing
11 changed files
with
262 additions
and
9 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog.d/20231025_122826_sirosen_introduce_missingtype.rst
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,9 @@ | ||
Added | ||
~~~~~ | ||
|
||
- A new sentinel value, ``globus_sdk.MISSING``, has been introduced. | ||
It is used for method calls which need to distinguish missing parameters from | ||
an explicit ``None`` used to signify ``null`` (:pr:`NUMBER`) | ||
|
||
- ``globus_sdk.MISSING`` is now supported in payload data for all methods, and | ||
will be automatically removed from the payload before sending to the server |
5 changes: 5 additions & 0 deletions
5
changelog.d/20231025_125551_sirosen_introduce_missingtype.rst
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,5 @@ | ||
Changed | ||
~~~~~~~ | ||
|
||
- ``GroupPolicies`` objects now treat an explicit instantiation with | ||
``high_assurance_timeout=None`` as setting the timeout to ``null`` (:pr:`NUMBER`) |
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
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"]} |
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,53 @@ | ||
import pytest | ||
|
||
from globus_sdk import utils | ||
|
||
|
||
def test_payload_preparation_strips_missing_dict(): | ||
original = {"foo": None, "bar": utils.MISSING} | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == {"foo": None} | ||
|
||
|
||
# this is a weird case (not really recommended usage), but we have well defined behavior | ||
# for it, so exercise it here | ||
@pytest.mark.parametrize("type_", (list, tuple)) | ||
def test_payload_preparation_strips_missing_list_or_tuple(type_): | ||
original = type_([None, 1, utils.MISSING, 0]) | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == [None, 1, 0] | ||
|
||
|
||
@pytest.mark.parametrize("original", (None, 1, 0, True, False, "foo", object())) | ||
def test_payload_preparation_retains_simple_datatype_identity(original): | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
# check not only that the values are equal, but that they pass the identity test | ||
assert prepared is original | ||
|
||
|
||
# this test makes sense in the context of the identity test above: | ||
# check that the values are equal, although the type may be reconstructed | ||
@pytest.mark.parametrize("original", (["foo", "bar"], {"foo": "bar"})) | ||
def test_payload_preparation_retains_complex_datatype_equality(original): | ||
prepared = utils.PayloadWrapper._prepare(original) | ||
assert prepared == original | ||
|
||
|
||
def test_payload_preparation_dictifies_wrappers(): | ||
x = utils.PayloadWrapper() | ||
x["foo"] = 1 | ||
prepared = utils.PayloadWrapper._prepare(x) | ||
assert prepared == {"foo": 1} | ||
assert isinstance(prepared, dict) | ||
assert prepared is not x | ||
assert not isinstance(prepared, utils.PayloadWrapper) | ||
|
||
|
||
def test_payload_preparation_recursively_dictifies_wrappers(): | ||
x = utils.PayloadWrapper() | ||
x["foo"] = 1 | ||
y = utils.PayloadWrapper() | ||
y["bar"] = x | ||
y["baz"] = [2, x] | ||
prepared = utils.PayloadWrapper._prepare(y) | ||
assert prepared == {"bar": {"foo": 1}, "baz": [2, {"foo": 1}]} |
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,28 @@ | ||
import copy | ||
import pickle | ||
|
||
import pytest | ||
|
||
from globus_sdk import utils | ||
|
||
|
||
def test_missing_type_cannot_be_instantiated(): | ||
with pytest.raises(TypeError, match="MissingType should not be instantiated"): | ||
utils.MissingType() | ||
|
||
|
||
def test_missing_sentinel_bools_as_false(): | ||
assert bool(utils.MISSING) is False | ||
|
||
|
||
def test_str_of_missing(): | ||
assert str(utils.MISSING) == "<globus_sdk.MISSING>" | ||
|
||
|
||
def test_copy_of_missing_is_self(): | ||
assert copy.copy(utils.MISSING) is utils.MISSING | ||
assert copy.deepcopy(utils.MISSING) is utils.MISSING | ||
|
||
|
||
def test_pickle_of_missing_is_self(): | ||
assert pickle.loads(pickle.dumps(utils.MISSING)) is utils.MISSING |