Skip to content

Instantly share code, notes, and snippets.

@mikeywaites
Created March 3, 2012 10:18
Show Gist options
  • Save mikeywaites/1965389 to your computer and use it in GitHub Desktop.
Save mikeywaites/1965389 to your computer and use it in GitHub Desktop.
#api_tests.py
def test_can_add_multiple_new_projects(self):
""" tests that a user can add multiple new objects at once using the
patch method
"""
data = {'objects':[
{'name': 'this is a test patch project 1'},
{'name': 'this is a test pacth project 2'}
]}
response = requests.patch(self.api_project_endpoint,
json.dumps(data),
headers={
'content_type':'application/json'}
)
self.assertEqual(response.status_code, 202)
#project_resource.py
class ProjectResource(BaseModelResource):
""" Prostack Issue api resource. exposes crud opertains for Issue types
"""
created_by = fields.ForeignKey(UserResource, 'created_by',
full=True,
related_name='created_by')
class Meta:
queryset = Project.objects.all()
resource_name = 'projects'
authentication = ProStackAuthentication()
authorization = ProStackAuthorization()
allowed_methods = ['get', 'post', 'put', 'delete', 'patch']
serializer = JSONSerializer()
default_format = 'application/json'
always_return_data = True
def obj_create(self, bundle, request=None, **kwargs):
return super(ProjectResource, self).obj_create(bundle, request, created_by=request.user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment