From df706bff012e5bfa06ee1ad1288cc7fef900536d Mon Sep 17 00:00:00 2001 From: David Michaels Date: Fri, 8 Sep 2023 13:35:19 -0400 Subject: [PATCH 1/5] Fix to get_schema(s) to use URL prefixed with slash for vapp. --- dcicutils/ff_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dcicutils/ff_utils.py b/dcicutils/ff_utils.py index 280bdc0df..cad9f4028 100644 --- a/dcicutils/ff_utils.py +++ b/dcicutils/ff_utils.py @@ -990,7 +990,7 @@ def get_schema(name, key=None, ff_env: Optional[str] = None, portal_env: Optiona base_url = f"profiles/{to_camel_case(name)}.json" add_on = 'frame=raw' if portal_vapp: - full_url = f"{base_url}?{add_on}" + full_url = f"/{base_url}?{add_on}" res = portal_vapp.get(full_url) return get_response_json(res) else: @@ -1022,7 +1022,7 @@ def get_schemas(key=None, ff_env: Optional[str] = None, *, allow_abstract: bool base_url = 'profiles/' add_on = 'frame=raw' if portal_vapp: - full_url = f"{base_url}?{add_on}" + full_url = f"/{base_url}?{add_on}" schemas: Dict[str, Dict] = portal_vapp.get(full_url) else: schemas: Dict[str, Dict] = get_metadata(obj_id=base_url, key=key, ff_env=portal_env, add_on=add_on) @@ -1488,6 +1488,7 @@ def get_response_json(res): it is not present. Used with the metadata functions. """ try: + # TODO: Fix for res being from vapp (webtest.response.TestRespons) call, using MockResponse ... res_json = res.json() except Exception: raise Exception('Cannot get json for request to %s. Status' From aaba4986445915f636dd256ba7697c26de840bc5 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Fri, 8 Sep 2023 13:47:56 -0400 Subject: [PATCH 2/5] Updated version and CHANGELOG --- CHANGELOG.rst | 9 +++++++++ dcicutils/ff_utils.py | 2 +- pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a92be15a1..345c0a1d1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,15 @@ Change Log ---------- +7.11.0 +====== + +* In ``ff_utils``: + + * Fix in ``get_schema`` and ``get_schemas`` for the ``portal_vapp`` case needing a leading slash on the URL. + * Fix in ``get_schema`` and ``get_schemas`` for the ``portal_vapp`` returning webtest.response.TestResponse + which has a ``json`` object property rather than a function. + 7.10.0 ====== diff --git a/dcicutils/ff_utils.py b/dcicutils/ff_utils.py index cad9f4028..d6ca184c6 100644 --- a/dcicutils/ff_utils.py +++ b/dcicutils/ff_utils.py @@ -1488,7 +1488,7 @@ def get_response_json(res): it is not present. Used with the metadata functions. """ try: - # TODO: Fix for res being from vapp (webtest.response.TestRespons) call, using MockResponse ... + # TODO: Fix for res being from vapp (webtest.response.TestResponse) call, using MockResponse ... res_json = res.json() except Exception: raise Exception('Cannot get json for request to %s. Status' diff --git a/pyproject.toml b/pyproject.toml index 1078a57ea..65dba0353 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "7.10.0" +version = "7.11.0" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT" From d89319263aa8fe6e01f223676fcb88513cd609cc Mon Sep 17 00:00:00 2001 From: David Michaels Date: Fri, 8 Sep 2023 15:31:58 -0400 Subject: [PATCH 3/5] Fix ff_utils.get_response_json to handle webtest.response.TestResponse. --- dcicutils/ff_utils.py | 8 +++++--- dcicutils/misc_utils.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dcicutils/ff_utils.py b/dcicutils/ff_utils.py index d6ca184c6..6f011bea4 100644 --- a/dcicutils/ff_utils.py +++ b/dcicutils/ff_utils.py @@ -17,7 +17,7 @@ # S3BucketName, S3KeyName, ) from .lang_utils import disjoined_list -from .misc_utils import PRINT, to_camel_case, remove_suffix, VirtualApp +from .misc_utils import PRINT, to_camel_case, remove_suffix, VirtualApp, VirtualAppResponse # TODO (C4-92, C4-102): Probably to centralize this information in env_utils. Also figure out relation to CGAP. @@ -1488,8 +1488,10 @@ def get_response_json(res): it is not present. Used with the metadata functions. """ try: - # TODO: Fix for res being from vapp (webtest.response.TestResponse) call, using MockResponse ... - res_json = res.json() + if isinstance(res, VirtualAppResponse): + res_json = res.json + else: + res_json = res.json() except Exception: raise Exception('Cannot get json for request to %s. Status' ' code: %s. Response text: %s' % diff --git a/dcicutils/misc_utils.py b/dcicutils/misc_utils.py index 88c228c7f..748d79a6d 100644 --- a/dcicutils/misc_utils.py +++ b/dcicutils/misc_utils.py @@ -295,6 +295,7 @@ def app(self): """ return self.wrapped_app.app +VirtualAppResponse = webtest.response.TestResponse def exported(*variables): """ From 10b6aac820cf998a2c43a4f6521fec888ff762bd Mon Sep 17 00:00:00 2001 From: David Michaels Date: Fri, 8 Sep 2023 15:39:30 -0400 Subject: [PATCH 4/5] flake8 fix --- dcicutils/misc_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dcicutils/misc_utils.py b/dcicutils/misc_utils.py index 748d79a6d..cc18f4b19 100644 --- a/dcicutils/misc_utils.py +++ b/dcicutils/misc_utils.py @@ -295,8 +295,10 @@ def app(self): """ return self.wrapped_app.app + VirtualAppResponse = webtest.response.TestResponse + def exported(*variables): """ This function does nothing but is used for declaration purposes. From f90217350ca5a52270a59eaecf92f6419249b264 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Fri, 8 Sep 2023 15:54:48 -0400 Subject: [PATCH 5/5] test fix --- test/test_ff_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_ff_utils.py b/test/test_ff_utils.py index 16413a519..b221ae693 100644 --- a/test/test_ff_utils.py +++ b/test/test_ff_utils.py @@ -1366,7 +1366,7 @@ def test_get_schema_with_vapp(): mock_get_authentication_with_server.assert_not_called() mock_get_metadata.assert_not_called() - sample_vapp.get.assert_called_once_with('profiles/User.json?frame=raw') + sample_vapp.get.assert_called_once_with('/profiles/User.json?frame=raw') @pytest.mark.unit @@ -1418,7 +1418,7 @@ def test_get_schemas_with_vapp(): mock_get_authentication_with_server.assert_not_called() mock_get_metadata.assert_not_called() - sample_vapp.get.assert_called_once_with('profiles/?frame=raw') + sample_vapp.get.assert_called_once_with('/profiles/?frame=raw') def test_get_schemas_options():