Skip to content

Commit

Permalink
Create read-only list of services, content formats, content categories.
Browse files Browse the repository at this point in the history
And link to them from content-delivery-repos.
Add some simple testcases.

JIRA: PDC-917
      PDC-918
      PDC-919
  • Loading branch information
simozhan committed Aug 28, 2015
1 parent fb59a06 commit 1ad81be
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pdc/apps/repository/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,24 @@ class RepoFamilySerializer(StrictSerializerMixin, serializers.ModelSerializer):
class Meta:
model = models.RepoFamily
fields = ("name", "description")


class ContentCategorySerializer(StrictSerializerMixin, serializers.ModelSerializer):

class Meta:
model = models.ContentCategory
fields = ('name', 'description',)


class ContentFormatSerializer(StrictSerializerMixin, serializers.ModelSerializer):

class Meta:
model = models.ContentFormat
fields = ('name', 'description',)


class ServiceSerializer(StrictSerializerMixin, serializers.ModelSerializer):

class Meta:
model = models.Service
fields = ('name', 'description',)
21 changes: 21 additions & 0 deletions pdc/apps/repository/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,24 @@ def test_removing_non_relevant_variant_by_patch_succeeds(self):
self.assertDictEqual(dict(response.data),
{'release': 'release-1.0', 'name': 'Server name', 'type': 'variant',
'id': 'Server', 'uid': 'Server-UID', 'arches': ['x86_64']})


class ContentCategoryTestCase(APITestCase):
def test_list_all(self):
response = self.client.get(reverse('contentdeliverycontentcategory-list'))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 3)


class ContentFormatTestCase(APITestCase):
def test_list_all(self):
response = self.client.get(reverse('contentdeliverycontentformat-list'))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 6)


class ServiceTestCase(APITestCase):
def test_list_all(self):
response = self.client.get(reverse('contentdeliveryservice-list'))
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 3)
72 changes: 72 additions & 0 deletions pdc/apps/repository/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def create(self, *args, **kwargs):
%(WRITABLE_SERIALIZER)s
*content_category*: $LINK:contentdeliverycontentcategory-list$
*content_format*: $LINK:contentdeliverycontentformat-list$
*repo_family*: $LINK:contentdeliveryrepofamily-list$
There are additional validations for the content delivery repository name for specific
Expand All @@ -62,6 +66,8 @@ def create(self, *args, **kwargs):
aus | .aus or .ll
els | els
*service*: $LINK:contentdeliveryservice-list$
__Response__: Same as input data.
"""
return super(RepoViewSet, self).create(*args, **kwargs)
Expand Down Expand Up @@ -283,3 +289,69 @@ def list(self, request, *args, **kwargs):
}
"""
return super(RepoFamilyViewSet, self).list(request, *args, **kwargs)


class ContentCategoryViewSet(StrictQueryParamMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
"""
API endpoint that allows content_category to be viewed.
"""
serializer_class = serializers.ContentCategorySerializer
queryset = models.ContentCategory.objects.all()

def list(self, request, *args, **kwargs):
"""
__Method__: GET
__URL__: $LINK:contentdeliverycontentcategory-list$
__Response__:
%(SERIALIZER)s
"""
return super(ContentCategoryViewSet, self).list(request, *args, **kwargs)


class ContentFormatViewSet(StrictQueryParamMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
"""
API endpoint that allows content_format to be viewed.
"""
serializer_class = serializers.ContentFormatSerializer
queryset = models.ContentFormat.objects.all()

def list(self, request, *args, **kwargs):
"""
__Method__: GET
__URL__: $LINK:contentdeliverycontentformat-list$
__Response__:
%(SERIALIZER)s
"""
return super(ContentFormatViewSet, self).list(request, *args, **kwargs)


class ServiceViewSet(StrictQueryParamMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
"""
API endpoint that allows service to be viewed.
"""
serializer_class = serializers.ServiceSerializer
queryset = models.Service.objects.all()

def list(self, request, *args, **kwargs):
"""
__Method__: GET
__URL__: $LINK:contentdeliveryservice-list$
__Response__:
%(SERIALIZER)s
"""
return super(ServiceViewSet, self).list(request, *args, **kwargs)
6 changes: 6 additions & 0 deletions pdc/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@
release_views.ReleaseVariantViewSet)
router.register(r'variant-types', release_views.VariantTypeViewSet,
base_name='varianttype')
router.register(r'content-delivery-content-category', repo_views.ContentCategoryViewSet,
base_name='contentdeliverycontentcategory')
router.register(r'content-delivery-content-format', repo_views.ContentFormatViewSet,
base_name='contentdeliverycontentformat')
router.register(r'content-delivery-service', repo_views.ServiceViewSet,
base_name='contentdeliveryservice')

0 comments on commit 1ad81be

Please sign in to comment.