def test_one_to_many(self): # Sanity checks. self.assertEqual(Note.objects.count(), 2) self.assertEqual(MediaBit.objects.count(), 0) fnr = FreshNoteResource() data = { 'title': 'Create with related URIs', 'slug': 'create-with-related-uris', 'content': 'Some content here', 'is_active': True, 'media_bits': [{ 'title': 'Picture #1' }] } request = MockRequest() request.GET = {'format': 'json'} request.method = 'POST' request.raw_post_data = json.dumps(data) resp = fnr.post_list(request) self.assertEqual(resp.status_code, 201) self.assertEqual(Note.objects.count(), 3) note = Note.objects.latest('created') self.assertEqual(note.media_bits.count(), 1) self.assertEqual(note.media_bits.all()[0].title, u'Picture #1')
def test_one_to_many(self): # Sanity checks. self.assertEqual(Note.objects.count(), 2) self.assertEqual(MediaBit.objects.count(), 0) fnr = FreshNoteResource() data = { "title": "Create with related URIs", "slug": "create-with-related-uris", "content": "Some content here", "is_active": True, "media_bits": [{"title": "Picture #1"}], } request = MockRequest() request.GET = {"format": "json"} request.method = "POST" request.body = json.dumps(data) resp = fnr.post_list(request) self.assertEqual(resp.status_code, 201) self.assertEqual(Note.objects.count(), 3) note = Note.objects.latest("created") self.assertEqual(note.media_bits.count(), 1) self.assertEqual(note.media_bits.all()[0].title, u"Picture #1")
def test_one_to_many(self): # Sanity checks. self.assertEqual(Note.objects.count(), 2) self.assertEqual(MediaBit.objects.count(), 0) fnr = FreshNoteResource() data = { 'title': 'Create with related URIs', 'slug': 'create-with-related-uris', 'content': 'Some content here', 'is_active': True, 'media_bits': [ { 'title': 'Picture #1' } ] } request = MockRequest() request.GET = {'format': 'json'} request.method = 'POST' request.set_body(json.dumps(data)) resp = fnr.post_list(request) self.assertEqual(resp.status_code, 201) self.assertEqual(Note.objects.count(), 3) note = Note.objects.latest('created') self.assertEqual(note.media_bits.count(), 1) self.assertEqual(note.media_bits.all()[0].title, u'Picture #1')
ForumResource, CompanyResource, ProductResource, AddressResource,\ PersonResource, DogResource, DogHouseResource, BoneResource,\ LabelResource, PostResource, OrderResource, OrderItemResource,\ NoteWithUpdatableUserResource, ContactResource, ContactGroupResource api = Api(api_name='v1') api.register(NoteResource(), canonical=True) api.register(NoteWithUpdatableUserResource(), canonical=True) api.register(UserResource(), canonical=True) api.register(CategoryResource(), canonical=True) api.register(TagResource(), canonical=True) api.register(TaggableResource(), canonical=True) api.register(TaggableTagResource(), canonical=True) api.register(ExtraDataResource(), canonical=True) api.register(FreshNoteResource(), canonical=True) api.register(FreshMediaBitResource(), canonical=True) api.register(ForumResource(), canonical=True) api.register(CompanyResource(), canonical=True) api.register(ProductResource(), canonical=True) api.register(AddressResource(), canonical=True) api.register(PersonResource(), canonical=True) api.register(DogResource(), canonical=True) api.register(DogHouseResource(), canonical=True) api.register(BoneResource(), canonical=True) api.register(PostResource(), canonical=True) api.register(LabelResource(), canonical=True) api.register(OrderResource(), canonical=True) api.register(OrderItemResource(), canonical=True) api.register(ContactResource(), canonical=True) api.register(ContactGroupResource(), canonical=True)