Skip to content

Commit

Permalink
Merge branch 'release/0.6.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlov99 committed Feb 26, 2015
2 parents 21f004f + 41f78a7 commit e3f431b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jsonapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" JSON:API realization."""
__version = (0, 6, 10)
__version = (0, 6, 11)

__version__ = version = '.'.join(map(str, __version))
__project__ = PROJECT = __name__
6 changes: 5 additions & 1 deletion jsonapi/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ def post(cls, request=None, **kwargs):
items = [items]

objects = []
Form = cls.Meta.form or cls.get_form()
for item in items:
if 'links' in item:
item.update(item.pop('links'))
Form = cls.Meta.form or cls.get_form(item.keys())
form = Form(item)
objects.append(form.save())

Expand Down Expand Up @@ -361,6 +363,8 @@ def put(cls, request=None, **kwargs):

objects = []
for item in items:
if 'links' in item:
item.update(item.pop('links'))
Form = cls.Meta.form or cls.get_form(item.keys())
instance = objects_map[item["id"]]
form = Form(item, instance=instance)
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Meta:
class PostResource(Resource):
class Meta:
model = 'testapp.Post'
allowed_methods = 'GET', 'POST'

@staticmethod
def dump_document_title(obj):
Expand Down
35 changes: 34 additions & 1 deletion tests/testapp/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
import unittest

from ..models import Author
from ..models import Author, Post
from ..urls import api

User = get_user_model()
Expand Down Expand Up @@ -253,6 +253,39 @@ def test_create_models(self):
location = "http://testserver/api/author/1,2,3"
self.assertEqual(response["Location"], location)

def test_create_model_partial_generated_form(self):
""" Post does not require user, it could be omitted."""
author = mixer.blend('testapp.author')
response = self.client.post(
'/api/post',
{
"posts": {
"title": "title",
"links": {
"author": author.id
}
},
},
content_type='application/vnd.api+json',
HTTP_ACCEPT='application/vnd.api+json'
)
self.assertEqual(response.status_code, 201)

post = Post.objects.get()
expected_data = {
"posts": {
"id": post.id,
"title": "title",
"links": {
"author": author.id,
"user": None
}
}
}

data = json.loads(response.content.decode("utf-8"))
self.assertEqual(data, expected_data)

def test_update_model(self):
author = mixer.blend("testapp.author", name="")
response = self.client.put(
Expand Down

0 comments on commit e3f431b

Please sign in to comment.