Commit c2abe452 by zubair-arbi

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

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