Skip to content

Commit

Permalink
test: add test for content-metdata retrieve without customer query param
Browse files Browse the repository at this point in the history
ENT-7788
  • Loading branch information
pwnage101 committed Nov 2, 2023
1 parent 9a7e56b commit e4862a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions enterprise_subsidy/apps/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 13 additions & 1 deletion enterprise_subsidy/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions enterprise_subsidy/apps/api/v1/views/content_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +28,8 @@
)
from enterprise_subsidy.apps.subsidy.models import EnterpriseSubsidyRoleAssignment

from ...schema import Parameters

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e4862a9

Please sign in to comment.