Commit fbd4e1c5 by Clinton Blackburn

Restored full ProgramSerializer for the programs endpoint

parent 953ea17d
......@@ -2,7 +2,7 @@ import ddt
from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase, APIRequestFactory
from course_discovery.apps.api.serializers import ProgramSerializer, MinimalProgramSerializer
from course_discovery.apps.api.serializers import ProgramSerializer
from course_discovery.apps.core.tests.factories import USER_PASSWORD, UserFactory
from course_discovery.apps.course_metadata.choices import ProgramStatus
from course_discovery.apps.course_metadata.models import Program
......@@ -69,21 +69,21 @@ class ProgramViewSetTests(APITestCase):
self.assertEqual(
response.data['results'],
MinimalProgramSerializer(expected, many=True, context={'request': self.request}).data
ProgramSerializer(expected, many=True, context={'request': self.request}).data
)
def test_list(self):
""" Verify the endpoint returns a list of all programs. """
expected = ProgramFactory.create_batch(3)
expected.reverse()
self.assert_list_results(self.list_path, expected, 7)
self.assert_list_results(self.list_path, expected, 40)
def test_filter_by_type(self):
""" Verify that the endpoint filters programs to those of a given type. """
program_type_name = 'foo'
program = ProgramFactory(type__name=program_type_name)
url = self.list_path + '?type=' + program_type_name
self.assert_list_results(url, [program], 7)
self.assert_list_results(url, [program], 18)
url = self.list_path + '?type=bar'
self.assert_list_results(url, [], 4)
......@@ -98,11 +98,11 @@ class ProgramViewSetTests(APITestCase):
# Create a third program, which should be filtered out.
ProgramFactory()
self.assert_list_results(url, expected, 7)
self.assert_list_results(url, expected, 29)
@ddt.data(
(ProgramStatus.Unpublished, False, 4),
(ProgramStatus.Active, True, 7),
(ProgramStatus.Active, True, 40),
)
@ddt.unpack
def test_filter_by_marketable(self, status, is_marketable, expected_query_count):
......
......@@ -395,6 +395,7 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
lookup_value_regex = '[0-9a-f-]+'
queryset = prefetch_related_objects_for_programs(Program.objects.all())
permission_classes = (IsAuthenticated,)
serializer_class = serializers.ProgramSerializer
filter_backends = (DjangoFilterBackend,)
filter_class = filters.ProgramFilter
......@@ -403,12 +404,6 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
context['published_course_runs_only'] = int(self.request.GET.get('published_course_runs_only', 0))
return context
def get_serializer_class(self):
if self.action == 'list':
return serializers.MinimalProgramSerializer
return serializers.ProgramSerializer
def list(self, request, *args, **kwargs):
""" List all programs.
---
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment