Skip to content

Commit

Permalink
Unit tests that reproduce issue wlanslovenija#58
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Demboski committed Aug 5, 2013
1 parent 3dfa8f8 commit 893fdb1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_project/test_app/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,19 @@ def test_referencedlistnonfull(self):

self.assertEqual(response['name'], 'Person 1')

def test_embeddedreferencedlist_create(self):
response = self.c.post(self.resourceListURI('person'), '{"name": "Person 1"}', content_type='application/json')
self.assertEqual(response.status_code, 201)

person1_uri = response['location']

response = self.c.post(self.resourceListURI('embeddedreferencedlistfieldtest'), '{"embedded": {"referencedlist": ["' + self.fullURItoAbsoluteURI(person1_uri) + '"]}}', content_type='application/json')
self.assertEqual(response.status_code, 201)

person = resources.PersonResource().get_via_uri(self.fullURItoAbsoluteURI(person1_uri))
obj = resources.EmbeddedReferencedListFieldTestResource().get_via_uri(self.fullURItoAbsoluteURI(response['location']))
self.assertListEqual(obj.embedded.referencedlist, [person])

def test_embeddedreferencedlist_get(self):
person = documents.Person.objects.create(name="Person 1")
obj = documents.EmbeddedReferencedListFieldTest.objects.create(embedded=documents.EmbeddedWithReferencedList(referencedlist=[person]))
Expand All @@ -925,6 +938,20 @@ def test_embeddedreferencedlist_get(self):
self.assertIn('referencedlist', embedded)
self.assertEqual(embedded['referencedlist'], [resources.PersonResource().get_resource_uri(person)])

def test_listofembeddedreferencedlist_create(self):
response = self.c.post(self.resourceListURI('person'), '{"name": "Person 1"}', content_type='application/json')
self.assertEqual(response.status_code, 201)

person1_uri = response['location']

response = self.c.post(self.resourceListURI('listofembeddedreferencedlistfieldtest'), '{"embeddedlist": [{"referencedlist": ["' + self.fullURItoAbsoluteURI(person1_uri) + '"]}]}', content_type='application/json')
self.assertEqual(response.status_code, 201)

person = resources.PersonResource().get_via_uri(self.fullURItoAbsoluteURI(person1_uri))
obj = resources.ListOfEmbeddedReferencedListFieldTestResource().get_via_uri(self.fullURItoAbsoluteURI(response['location']))
self.assertEqual(len(obj.embeddedlist), 1)
self.assertListEqual(obj.embeddedlist[0].referencedlist, [person])

def test_listofembeddedreferencedlist_get(self):
person = documents.Person.objects.create(name="Person 1")
obj = documents.ListOfEmbeddedReferencedListFieldTest.objects.create(embeddedlist=[
Expand Down

0 comments on commit 893fdb1

Please sign in to comment.