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

fix: adding page size param to highlights #872

Merged
merged 2 commits into from
Jul 11, 2024
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
42 changes: 39 additions & 3 deletions enterprise_catalog/apps/api/v1/tests/test_curation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
# types including ones not supported by Curations/Highlighting feature, we set up a content type generator that
# deterministically provides supported content types.
supported_content_types = [COURSE, PROGRAM]
content_type_generator = (
self.content_type_generator = (
supported_content_types[idx % len(supported_content_types)]
for idx in itertools.count()
)
Expand All @@ -58,7 +58,7 @@ def setUp(self):
self.highlight_set_one = HighlightSetFactory(enterprise_curation=self.curation_config_one)
self.card_image_urls_one = [fake.image_url() + '.jpg' for idx in range(5)]
self.highlighted_content_metadata_one = [
ContentMetadataFactory(card_image_url=url, content_type=next(content_type_generator))
ContentMetadataFactory(card_image_url=url, content_type=next(self.content_type_generator))
for url in self.card_image_urls_one
]
self.highlighted_content_list_one = [
Expand All @@ -72,7 +72,7 @@ def setUp(self):
self.highlight_set_two = HighlightSetFactory(enterprise_curation=self.curation_config_two)
self.card_image_urls_two = [fake.image_url() + '.jpg' for idx in range(5)]
self.highlighted_content_metadata_two = [
ContentMetadataFactory(card_image_url=url, content_type=next(content_type_generator))
ContentMetadataFactory(card_image_url=url, content_type=next(self.content_type_generator))
for url in self.card_image_urls_two
]
self.highlighted_content_list_two = [
Expand Down Expand Up @@ -420,6 +420,42 @@ def test_list_catalog_learner_with_caching(self, include_customer_param):
assert second_response.json() == response.json()
assert second_response.status_code == status.HTTP_200_OK

def test_list_test(self):
"""
A catalog learner should be able to list the highlight sets of their own enterprise customer, but not that of
other enterprise customers.
"""
self.highlight_set_two = HighlightSetFactory(enterprise_curation=self.curation_config_one)
self.card_image_urls_two = [fake.image_url() + '.jpg' for idx in range(5)]
self.highlighted_content_metadata_two = [
ContentMetadataFactory(card_image_url=url, content_type=next(self.content_type_generator))
for url in self.card_image_urls_one
]
self.highlighted_content_list_two = [
HighlightedContentFactory(catalog_highlight_set=self.highlight_set_two, content_metadata=cm)
for cm in self.highlighted_content_metadata_two
]

url = reverse('api:v1:highlight-sets-list')
url = url + f'?enterprise_customer={self.enterprise_uuid}'

self.set_up_catalog_learner()
self.remove_role_assignments()

response = self.client.get(url)

assert response.status_code == status.HTTP_200_OK
highlight_sets_results = response.json()['results']
assert len(highlight_sets_results) == 2

limited_url = url + '&page_size=1'

response = self.client.get(limited_url)

assert response.status_code == status.HTTP_200_OK
highlight_sets_results = response.json()['results']
assert len(highlight_sets_results) == 1

def test_detail_invalid_uuid(self):
"""
An enterprise learner should get a 403 error trying to access a non-existent highlight set.
Expand Down
10 changes: 9 additions & 1 deletion enterprise_catalog/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,15 @@ def test_catalog_query_list(self):
self.set_up_invalid_jwt_role()
self.remove_role_assignments()
response = self.client.get(url)
assert response.json() == {'count': 0, 'next': None, 'previous': None, 'results': []}
assert response.json() == {
'count': 0,
'current_page': 1,
'next': None,
'num_pages': 1,
'previous': None,
'results': [],
'start': 0,
}

self.client.logout()
response = self.client.get(url)
Expand Down
3 changes: 0 additions & 3 deletions enterprise_catalog/apps/api/v1/views/curation/highlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
from enterprise_catalog.apps.api.v1.event_utils import (
track_highlight_set_changes,
)
from enterprise_catalog.apps.api.v1.pagination import (
PageNumberWithSizePagination,
)
from enterprise_catalog.apps.api.v1.serializers import (
ContentMetadataSerializer,
EnterpriseCurationConfigSerializer,
Expand Down
2 changes: 1 addition & 1 deletion enterprise_catalog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@

# Django Rest Framework
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'DEFAULT_PAGINATION_CLASS': 'edx_rest_framework_extensions.paginators.DefaultPagination',
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
Expand Down
Loading