From e4862a9e63de3204f669c8bc0dbab3939fe39cd7 Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Thu, 26 Oct 2023 18:58:22 -0400 Subject: [PATCH] test: add test for content-metdata retrieve without customer query param ENT-7788 --- enterprise_subsidy/apps/api/schema.py | 10 ++++++++++ enterprise_subsidy/apps/api/v1/tests/test_views.py | 14 +++++++++++++- .../apps/api/v1/views/content_metadata.py | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/enterprise_subsidy/apps/api/schema.py b/enterprise_subsidy/apps/api/schema.py index 39a5fede..a7a0d4a9 100644 --- a/enterprise_subsidy/apps/api/schema.py +++ b/enterprise_subsidy/apps/api/schema.py @@ -32,6 +32,16 @@ class Parameters: "The content key/identifier to which the query pertains." ), ) + ENTERPRISE_CUSTOMER_UUID = OpenApiParameter( + 'enterprise_customer_uuid', + type=OpenApiTypes.UUID, + location=OpenApiParameter.QUERY, + required=True, + allow_blank=False, + description=( + "The UUID associated with the requesting user's enterprise customer." + ), + ) def _open_api_error_response(exception_class, detail_str, example_name): diff --git a/enterprise_subsidy/apps/api/v1/tests/test_views.py b/enterprise_subsidy/apps/api/v1/tests/test_views.py index e79478a1..a6288501 100644 --- a/enterprise_subsidy/apps/api/v1/tests/test_views.py +++ b/enterprise_subsidy/apps/api/v1/tests/test_views.py @@ -1461,13 +1461,25 @@ def test_successful_get( 'geag_variant_id': expected_geag_variant_id, } - def test_failure_no_permission(self): + def test_retrieve_failure_no_permission(self): self.set_up_admin(enterprise_uuids=[str(uuid.uuid4())]) url = reverse('api:v1:content-metadata', kwargs={'content_identifier': self.content_key_1}) response = self.client.get(url + f'?enterprise_customer_uuid={str(uuid.uuid4())}') assert response.status_code == 403 assert response.json() == {'detail': 'MISSING: subsidy.can_read_metadata'} + def test_retrieve_failure_no_query_param(self): + """ + When no `enterprise_customer_uuid` query param is supplied by the requesting operator, test response is 400. + """ + self.set_up_operator() + url = reverse('api:v1:content-metadata', kwargs={'content_identifier': self.content_key_1}) + response = self.client.get(url) + assert response.status_code == 400 + assert response.json() == [ + 'You must provide at least one of the following query parameters: enterprise_customer_uuid.' + ] + @ddt.data( { 'catalog_status_code': 404, diff --git a/enterprise_subsidy/apps/api/v1/views/content_metadata.py b/enterprise_subsidy/apps/api/v1/views/content_metadata.py index 90a1c81f..602fcf6c 100644 --- a/enterprise_subsidy/apps/api/v1/views/content_metadata.py +++ b/enterprise_subsidy/apps/api/v1/views/content_metadata.py @@ -7,6 +7,7 @@ from django.conf import settings from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page +from drf_spectacular.utils import extend_schema from edx_rbac.mixins import PermissionRequiredMixin from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from rest_framework import permissions @@ -27,6 +28,8 @@ ) from enterprise_subsidy.apps.subsidy.models import EnterpriseSubsidyRoleAssignment +from ...schema import Parameters + logger = logging.getLogger(__name__) @@ -79,6 +82,7 @@ def requested_enterprise_customer_uuid(self): """ return utils.get_enterprise_uuid_from_request_query_params(self.request) + @extend_schema(parameters=[Parameters.ENTERPRISE_CUSTOMER_UUID]) @method_decorator(cache_page(CONTENT_METADATA_VIEW_CACHE_TIMEOUT_SECONDS)) @method_decorator(require_at_least_one_query_parameter('enterprise_customer_uuid')) @action(detail=True)