Skip to content

Commit

Permalink
apply changes for flatten listing (#345) + align with eventual resour…
Browse files Browse the repository at this point in the history
…ce response formats (#346)
  • Loading branch information
fmigneault committed Aug 25, 2020
1 parent fa645a0 commit c6cbf00
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ Features / Changes
* Add documentation details about different types of ``Permission``, interaction between various `Magpie` models,
glossary and other general improvements (relates to `#332 <https://github.com/Ouranosinc/Magpie/issues/332>`_ and
`#341 <https://github.com/Ouranosinc/Magpie/issues/341>`_).
* Add alternative response format for service and service-type paths using ``list`` query parameter to obtain a flat
* Add alternative response format for service and service-type paths using ``flatten`` query parameter to obtain a flat
list of services instead of nested dictionaries (fixes `#345 <https://github.com/Ouranosinc/Magpie/issues/345>`_).
* Change pre-existing ``list`` query parameter of user-scoped views to ``flatten`` response format to match new query
of service-scoped views.

Bug Fixes
~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion magpie/api/management/service/service_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_services_runner(request):
path and query parameters.
"""
service_type_filter = request.matchdict.get("service_type") # no check because None/empty is for 'all services'
services_as_list = asbool(ar.get_query_param(request, "list", False))
services_as_list = asbool(ar.get_query_param(request, "flatten", False))

if not service_type_filter:
service_types = SERVICE_TYPE_DICT.keys()
Expand Down
2 changes: 1 addition & 1 deletion magpie/api/management/user/user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get_user_services_view(request):
user = ar.get_user_matchdict_checked_or_logged(request)
cascade_resources = asbool(ar.get_query_param(request, "cascade"))
inherit_groups_perms = asbool(ar.get_query_param(request, "inherit"))
format_as_list = asbool(ar.get_query_param(request, "list"))
format_as_list = asbool(ar.get_query_param(request, "flatten"))

svc_json = uu.get_user_services(user, request=request,
cascade_resources=cascade_resources,
Expand Down
12 changes: 6 additions & 6 deletions magpie/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ class QueryRequestSchemaAPI(colander.MappingSchema):
colander.Boolean(), default=False, missing=colander.drop,
description="Display any service that has at least one sub-resource user permission, "
"or only services that have user permissions directly set on them.", )
QueryFlattenResources = colander.SchemaNode(
colander.Boolean(), default=False, missing=colander.drop,
description="Return services as a flattened list of JSON objects. Default is a nested JSON of service-type keys "
"with children service-name keys pointing to each corresponding service definition.")


class BaseRequestSchemaAPI(colander.MappingSchema):
Expand Down Expand Up @@ -1017,9 +1021,7 @@ class ServiceTypesList(colander.SequenceSchema):


class ServiceListingQuerySchema(QueryRequestSchemaAPI):
list = colander.SchemaNode(
colander.Boolean(), default=False, missing=colander.drop,
description="Return services as a list of dicts. Default is a dict by service type, and by service name.")
flatten = QueryFlattenResources


class ServiceTypes_GET_RequestSchema(BaseRequestSchemaAPI):
Expand Down Expand Up @@ -1833,9 +1835,7 @@ class UserServicePermission_DELETE_RequestSchema(BaseRequestSchemaAPI):
class UserServices_GET_QuerySchema(QueryRequestSchemaAPI):
cascade = QueryCascadeResourcesPermissions
inherit = QueryInheritGroupsPermissions
list = colander.SchemaNode(
colander.Boolean(), default=False, missing=colander.drop,
description="Return services as a list of dicts. Default is a dict by service type, and by service name.")
flatten = QueryFlattenResources


class UserServices_GET_RequestSchema(BaseRequestSchemaAPI):
Expand Down
9 changes: 5 additions & 4 deletions tests/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ def test_GetGroupServiceResources(self):
utils.check_val_type(svc_dict["service_url"], six.string_types)

@runner.MAGPIE_TEST_SERVICES
def test_GetServices_ResponseFormat(self):
def test_GetServices_ResponseFormat_Default(self):
utils.TestSetup.create_TestService(self)
resp = utils.test_request(self, "GET", "/services", headers=self.json_headers, cookies=self.cookies)
body = utils.check_response_basic_info(resp, 200, expected_method="GET")
Expand Down Expand Up @@ -2024,8 +2024,8 @@ def test_GetServices_ResponseFormat(self):
utils.check_val_type(body["service"]["service_sync_type"], utils.OptionalStringType)

@runner.MAGPIE_TEST_SERVICES
def test_GetServices_ResponseFormat(self):
utils.warn_version(self, "Service listing as object list with query parameter", "2.0.0", skip=True)
def test_GetServices_ResponseFormat_Flatten(self):
utils.warn_version(self, "Service flattened listing as objects with query parameter", "2.0.0", skip=True)

resp = utils.test_request(self, "GET", "/services", headers=self.json_headers, cookies=self.cookies)
body = utils.check_response_basic_info(resp, 200, expected_method="GET")
Expand All @@ -2034,7 +2034,8 @@ def test_GetServices_ResponseFormat(self):
for svc_name in body["services"][svc_type]:
svc_name_list.append(svc_name)

resp = utils.test_request(self, "GET", "/services?list=true", headers=self.json_headers, cookies=self.cookies)
path = "/services?flatten=true"
resp = utils.test_request(self, "GET", path, headers=self.json_headers, cookies=self.cookies)
body = utils.check_response_basic_info(resp, 200, expected_method="GET")
utils.check_val_is_in("services", body)
utils.check_val_type(body["services"], list)
Expand Down

0 comments on commit c6cbf00

Please sign in to comment.