Commit 0a6f7166 by zubair-arbi

Revert "ENT-960 Fix catalogs creation bug due to request data format"

This reverts commit c2abe452.
parent c4f757cd
...@@ -129,10 +129,11 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi ...@@ -129,10 +129,11 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
data = { data = {
'name': 'Test Catalog', 'name': 'Test Catalog',
'query': '*:*', 'query': '*:*',
'viewers': str(viewers), 'viewers': ','.join(viewers)
} }
response = self.client.post(self.catalog_list_url, data, format='json') # NOTE: We explicitly avoid using the JSON data type so that we properly test string parsing.
response = self.client.post(self.catalog_list_url, data)
self.assertEqual(response.status_code, 201) self.assertEqual(response.status_code, 201)
catalog = Catalog.objects.latest() catalog = Catalog.objects.latest()
...@@ -144,10 +145,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi ...@@ -144,10 +145,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
""" Verify no users are created if an error occurs while processing a create request. """ """ Verify no users are created if an error occurs while processing a create request. """
# The missing name and query fields should trigger an error # The missing name and query fields should trigger an error
data = { data = {
'viewers': str(['new-guy']) 'viewers': ['new-guy']
} }
original_user_count = User.objects.count() original_user_count = User.objects.count()
response = self.client.post(self.catalog_list_url, data, format='json') response = self.client.post(self.catalog_list_url, data)
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
self.assertEqual(User.objects.count(), original_user_count) self.assertEqual(User.objects.count(), original_user_count)
......
import ast
import datetime import datetime
from django.db import transaction from django.db import transaction
...@@ -33,13 +32,13 @@ class CatalogViewSet(viewsets.ModelViewSet): ...@@ -33,13 +32,13 @@ class CatalogViewSet(viewsets.ModelViewSet):
@transaction.atomic @transaction.atomic
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
""" Create a new catalog. """ """ Create a new catalog. """
data = dict(request.data.copy()) data = request.data.copy()
usernames = request.data.get('viewers', ()) usernames = request.data.get('viewers', ())
# Add support for parsing a comma-separated list from Swagger # Add support for parsing a comma-separated list from Swagger
if isinstance(usernames, str): if isinstance(usernames, str):
usernames = ast.literal_eval(usernames) usernames = usernames.split(',')
data['viewers'] = usernames data.setlist('viewers', usernames)
# Ensure the users exist # Ensure the users exist
for username in usernames: for username in usernames:
......
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