Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for content-metdata retrieve without customer query param #164

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading