-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `construct_error` to `_testing` subpackage This helper replaces several "make_response" fixtures in error testing, not only making things more uniform and explicit within the SDK tests, but also making it possible for `_testing` users to leverage this art. `construct_error` replaces an entire error-testing `conftest.py` file and is generally a simplification. Several tests become more verbose as they now contain more of the test data. The type of `construct_error` needs to be declared with overrides to allow for the `error_class` to indicate the return type. * Apply suggestions from code review Co-authored-by: Kurt McKee <contactme@kurtmckee.org> * Add dedicated unit tests for construct_error Rather than "piggybacking" the testing of construct_error on the tests for errors themselves, the construct_error now has its own dedicated test module. Although there may be (significant) overlap between the two suites of tests, their differing targets simplify some decisions about how to test binary content handling and other details. It also makes it easier to assess whether or not there is a testing gap which isn't easily measurable via code coverage. * Update test_common_functionality.py Minor typo fix after rebase * Fix incorrect test fixture usage Introduced by the rebase. --------- Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
- Loading branch information
Showing
10 changed files
with
453 additions
and
421 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Added | ||
~~~~~ | ||
|
||
- ``globus_sdk._testing`` now exposes a method, ``construct_error`` which makes | ||
it simpler to explicitly construct and return a Globus SDK error object for | ||
testing. This is used in the SDK's own testsuite and is available for | ||
``_testing`` users. (: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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ Functions | |
|
||
.. autofunction:: load_response | ||
|
||
.. autofunction:: construct_error | ||
|
||
Classes | ||
------- | ||
|
||
|
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,50 @@ | ||
import pytest | ||
|
||
import globus_sdk | ||
from globus_sdk._testing import construct_error | ||
|
||
|
||
def test_construct_error_defaults_to_base_error_class(): | ||
err = construct_error(body="foo", http_status=400) | ||
assert isinstance(err, globus_sdk.GlobusAPIError) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"error_class", | ||
( | ||
globus_sdk.SearchAPIError, | ||
globus_sdk.AuthAPIError, | ||
globus_sdk.TransferAPIError, | ||
globus_sdk.FlowsAPIError, | ||
globus_sdk.GCSAPIError, | ||
), | ||
) | ||
def test_construct_error_can_be_customized_to_service_error_classes(error_class): | ||
err = construct_error(body="foo", http_status=400, error_class=error_class) | ||
assert isinstance(err, error_class) | ||
|
||
|
||
def test_construct_error_defaults_to_json_for_dict_body(): | ||
err = construct_error(body={"foo": "bar"}, http_status=400) | ||
assert err.text == '{"foo": "bar"}' | ||
assert err.headers == {"Content-Type": "application/json"} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"body, add_params, expect_encoding, expect_text", | ||
( | ||
(b"foo-bar", {}, "utf-8", "foo-bar"), | ||
(b"foo-bar", {"response_encoding": "utf-8"}, "utf-8", "foo-bar"), | ||
(b"foo-bar", {"response_encoding": "latin-1"}, "latin-1", "foo-bar"), | ||
# this is invalid utf-8 (continuation byte), | ||
# but valid in latin-1 (e with acute accent) | ||
(b"\xe9", {"response_encoding": "latin-1"}, "latin-1", "é"), | ||
), | ||
) | ||
def test_construct_error_allows_binary_content( | ||
body, add_params, expect_encoding, expect_text | ||
): | ||
err = construct_error(body=body, http_status=400, **add_params) | ||
assert err.binary_content == body | ||
assert err.text == expect_text | ||
assert err._underlying_response.encoding == expect_encoding |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.