mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-05 07:51:51 -05:00
Fix for 500 error when POST data is not a dict.
This commit is contained in:
@@ -257,6 +257,9 @@ class SubListCreateAPIView(SubListAPIView, ListCreateAPIView):
|
|||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
if not isinstance(request.DATA, dict):
|
||||||
|
return Response('invalid type for post data',
|
||||||
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
if 'disassociate' in request.DATA:
|
if 'disassociate' in request.DATA:
|
||||||
return self.unattach(request, *args, **kwargs)
|
return self.unattach(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ class BaseTestMixin(object):
|
|||||||
data_type=None, accept=None, remote_addr=None):
|
data_type=None, accept=None, remote_addr=None):
|
||||||
assert method is not None
|
assert method is not None
|
||||||
method_name = method.lower()
|
method_name = method.lower()
|
||||||
if method_name not in ('options', 'head', 'get', 'delete'):
|
#if method_name not in ('options', 'head', 'get', 'delete'):
|
||||||
assert data is not None
|
# assert data is not None
|
||||||
client_kwargs = {}
|
client_kwargs = {}
|
||||||
if accept:
|
if accept:
|
||||||
client_kwargs['HTTP_ACCEPT'] = accept
|
client_kwargs['HTTP_ACCEPT'] = accept
|
||||||
|
|||||||
@@ -394,4 +394,21 @@ class OrganizationsTest(BaseTest):
|
|||||||
# also check that DELETE on the collection doesn't work
|
# also check that DELETE on the collection doesn't work
|
||||||
self.delete(self.collection(), expect=405, auth=self.get_super_credentials())
|
self.delete(self.collection(), expect=405, auth=self.get_super_credentials())
|
||||||
|
|
||||||
|
def test_invalid_post_data(self):
|
||||||
|
url = reverse('main:organization_list')
|
||||||
|
# API should gracefully handle data of an invalid type.
|
||||||
|
self.post(url, expect=400, data=None, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=99, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data='abcd', auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=3.14, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=True, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=[1,2,3], auth=self.get_super_credentials())
|
||||||
|
url = reverse('main:organization_users_list', args=(self.organizations[0].pk,))
|
||||||
|
self.post(url, expect=400, data=None, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=99, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data='abcd', auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=3.14, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=True, auth=self.get_super_credentials())
|
||||||
|
self.post(url, expect=400, data=[1,2,3], auth=self.get_super_credentials())
|
||||||
|
|
||||||
# TODO: tests for tag disassociation
|
# TODO: tests for tag disassociation
|
||||||
|
|||||||
Reference in New Issue
Block a user