Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[controller] Improved structure of register view response #6
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jan 14, 2016
1 parent f85ecda commit a2f2c43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions django_netjsonconfig/controller/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ def register(request):
config = Config.objects.create(name=request.POST.get('name'),
backend=request.POST.get('backend'))
# return id and key in response
content = '{id}\n{key}'.format(**config.__dict__)
return HttpResponse(content, content_type='text/plain', status=201)
s = 'registration-result: success\n' \
'uuid: {id}\n' \
'key: {key}\n'
return ControllerResponse(s.format(**config.__dict__),
content_type='text/plain',
status=201)
5 changes: 4 additions & 1 deletion django_netjsonconfig/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def test_register(self):
'backend': 'netjsonconfig.OpenWrt'
})
self.assertEqual(response.status_code, 201)
uuid, key = response.content.decode().split('\n')
lines = response.content.decode().split('\n')
self.assertEqual(lines[0], 'registration-result: success')
uuid = lines[1].replace('uuid: ', '')
key = lines[2].replace('key: ', '')
self.assertEqual(Config.objects.filter(pk=uuid, key=key).count(), 1)

def test_register_400(self):
Expand Down

0 comments on commit a2f2c43

Please sign in to comment.