Skip to content

Commit

Permalink
Merge pull request #283 from 4dn-dcic/fix_vapp_get_schema_url_and_res…
Browse files Browse the repository at this point in the history
…ponse

Fix to get_schema(s) to use URL prefixed with slash for vapp.
  • Loading branch information
dmichaels-harvard authored Sep 8, 2023
2 parents b079275 + f902173 commit 989593d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
======

Expand Down
11 changes: 7 additions & 4 deletions dcicutils/ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1488,7 +1488,10 @@ def get_response_json(res):
it is not present. Used with the metadata functions.
"""
try:
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' %
Expand Down
3 changes: 3 additions & 0 deletions dcicutils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ 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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions test/test_ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 989593d

Please sign in to comment.