I am having some trouble with writing a unit test that checks my custom resource post attribute is working. I have managed to make it work with a simple manual jquery, but that isn’t helpful for long term testing.
Suppose my test looks like this:
def testCollectionPost(self):
""" Test Create Entry operation.
"""
initialData = self.client.get(self.collectionUrl, format='json')
jsonObject = json.loads(initialData.content)
initialCount = jsonObject['meta']['total_count']
dataToPost = {'id': initialCount + 1} # Real version contains other appropiate data
response = self.client.post(self.collectionUrl, data=json.dumps(dataToPost), content_type='application/json')
self.assertEqual(response.status_code, 201)
responseGet = self.client.get(self.collectionUrl, format='json')
jsonObject = json.loads(responseGet.content)
self.assertEqual(jsonObject['meta']['total_count'], initialCount + 1)
This gives me back a 500 error, and I have been utterly unable to get back a real traceback.
Off my main page, I ran the following which worked fine:
dataToPost = {'id': 277} # Real version has more data, that matches the unit test.
pResp = $.ajax({ type: 'POST',
url: 'http://nelsog2.blah.example.com/metrics/api/v1/system_info/',
data: JSON.stringify(dataToPost),
contentType: 'application/json'})
Anyone have an idea fo what the issue is?
Problem seems to have fixed itself. My guess is the request was being caught by a cache returning the 500 error, after I had already fixed the issue.