Skip to content

Commit

Permalink
Simplifications per Will's code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
netsettler committed Sep 7, 2023
1 parent 53de60a commit 630720f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions dcicutils/ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ def get_schema(name, key=None, ff_env: Optional[str] = None, portal_env: Optiona
res = portal_vapp.get(full_url)
return get_response_json(res)
else:
auth = get_authentication_with_server(auth=key, ff_env=portal_env)
schema = get_metadata(obj_id=base_url, key=auth, add_on=add_on)
schema = get_metadata(obj_id=base_url, key=key, ff_env=portal_env, add_on=add_on)
return schema


Expand Down Expand Up @@ -1026,8 +1025,7 @@ def get_schemas(key=None, ff_env: Optional[str] = None, *, allow_abstract: bool
full_url = f"{base_url}?{add_on}"
schemas: Dict[str, Dict] = portal_vapp.get(full_url)
else:
auth = get_authentication_with_server(auth=key, ff_env=portal_env)
schemas: Dict[str, Dict] = get_metadata(obj_id=base_url, key=auth, add_on=add_on)
schemas: Dict[str, Dict] = get_metadata(obj_id=base_url, key=key, ff_env=portal_env, add_on=add_on)
filtered_schemas = {}
for schema_name, schema in schemas.items():
if allow_abstract or not schema.get('isAbstract'):
Expand Down
14 changes: 7 additions & 7 deletions test/test_ff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,8 @@ def test_get_schema_with_vapp():
# When called with no vapp, get_metadata is consulted (after getting auth info)
assert ff_utils.get_schema('User', **env_args) == sample_schema_metadata

mock_get_authentication_with_server.assert_called_once_with(auth=None, ff_env=expected_env)
mock_get_metadata.assert_called_once_with(obj_id='profiles/User.json', key=sample_auth,
mock_get_authentication_with_server.assert_not_called()
mock_get_metadata.assert_called_once_with(obj_id='profiles/User.json', key=None, ff_env=expected_env,
add_on='frame=raw')

sample_vapp.get.assert_not_called()
Expand Down Expand Up @@ -1398,11 +1398,10 @@ def test_get_schemas_with_vapp():
mock_get_metadata.return_value = sample_schema_metadata
mock_get_authentication_with_server.return_value = sample_auth

# When called with no vapp, get_metadata is consulted (after getting auth info)
assert ff_utils.get_schemas(**env_args) == sample_schema_metadata

mock_get_authentication_with_server.assert_called_once_with(auth=None, ff_env=expected_env)
mock_get_metadata.assert_called_once_with(obj_id='profiles/', key=sample_auth,
mock_get_authentication_with_server.assert_not_called()
mock_get_metadata.assert_called_once_with(obj_id='profiles/', key=None, ff_env=expected_env,
add_on='frame=raw')

sample_vapp.get.assert_not_called()
Expand Down Expand Up @@ -1456,9 +1455,10 @@ def mocked_schemas_subset(keys):

with mock.patch.object(ff_utils, "get_metadata") as mock_get_metadata:

def mocked_get_metadata(obj_id, key, add_on):
def mocked_get_metadata(obj_id, key, ff_env, add_on):
assert obj_id == "profiles/" # this is the web API to ask for all profiles
assert key == 'some-auth' # we assume auth is tested elsewhere
assert key is None # it would get looked up
assert ff_env is None # it would get looked up, too
assert add_on == "frame=raw" # we presently always send this
return mocked_schemas

Expand Down

0 comments on commit 630720f

Please sign in to comment.