예제 #1
0
 def test_provides_resource(self):
     coll = create_collection()
     mb = iter(coll).next()
     self.assert_true(provides_member_resource(type(mb)))
     self.assert_true(provides_member_resource(mb))
     self.assert_false(provides_member_resource(coll))
     self.assert_true(provides_resource(type(mb)))
     self.assert_true(provides_resource(mb))
     self.assert_true(provides_collection_resource(type(coll)))
     self.assert_true(provides_collection_resource(coll))
     self.assert_false(provides_collection_resource(mb))
     self.assert_true(provides_resource(type(coll)))
     self.assert_true(provides_resource(coll))
     self.assert_false(provides_resource(mb.get_entity()))
예제 #2
0
 def test_provides_resource(self):
     coll = create_collection()
     mb = next(iter(coll))
     self.assert_true(provides_member_resource(type(mb)))
     self.assert_true(provides_member_resource(mb))
     self.assert_false(provides_member_resource(coll))
     self.assert_true(provides_resource(type(mb)))
     self.assert_true(provides_resource(mb))
     self.assert_true(provides_collection_resource(type(coll)))
     self.assert_true(provides_collection_resource(coll))
     self.assert_false(provides_collection_resource(mb))
     self.assert_true(provides_resource(type(coll)))
     self.assert_true(provides_resource(coll))
     self.assert_false(provides_resource(mb.get_entity()))
예제 #3
0
 def _process_request_data(self, data):
     if not provides_resource(data):
         rpr = self._get_request_representer()
         resource = rpr.resource_from_data(data)
     else:
         resource = data
     member_was_posted = provides_member_resource(resource)
     if member_was_posted:
         new_members = [resource]
     else:
         new_members = resource
     was_created = True
     for new_member in new_members:
         if self.context.get(new_member.__name__) is not None:
             # We have a member with the same name - 409 Conflict.
             response = self._handle_conflict(new_member.__name__)
             was_created = False
             break
         else:
             self.context.add(new_member)
     if was_created:
         if member_was_posted:
             new_location = resource_to_url(resource, request=self.request)
         else:
             new_location = resource_to_url(self.context,
                                            request=self.request)
         self.request.response.status = self._status(HTTPCreated)
         self.request.response.headerlist = [('Location', new_location)]
         response = self._get_result(resource)
     return response
예제 #4
0
 def _process_request_data(self, data):
     if not provides_resource(data):
         rpr = self._get_request_representer()
         resource = rpr.resource_from_data(data)
     else:
         resource = data
     data_is_member = provides_member_resource(resource)
     if data_is_member:
         new_members = [resource]
     else:
         new_members = resource
     was_created = True
     sync_with_repo = False
     for new_member in new_members:
         name_is_none = new_member.__name__ is None
         sync_with_repo |= name_is_none
         if not name_is_none \
            and not self.context.get(new_member.__name__) is None:
             # We have a member with the same name - 409 Conflict.
             result = self._handle_conflict(new_member.__name__)
             was_created = False
             break
         else:
             self.context.add(new_member)
     if was_created:
         if sync_with_repo:
             # This is not pretty, but necessary: When the resource
             # name depends on the entity ID, the pending entity needs
             # to be flushed to the repository before we can access
             # the ID.
             self.context.get_aggregate().sync_with_repository()
         self.request.response.status = self._status(HTTPCreated)
         if data_is_member:
             loc_rc = resource
         else:
             loc_rc = self.context
         self._update_response_location_header(loc_rc)
         result = self._get_result(resource)
     return result
예제 #5
0
 def _process_request_data(self, data):
     if not provides_resource(data):
         rpr = self._get_request_representer()
         resource = rpr.resource_from_data(data)
     else:
         resource = data
     data_is_member = provides_member_resource(resource)
     if data_is_member:
         new_members = [resource]
     else:
         new_members = resource
     was_created = True
     sync_with_repo = False
     for new_member in new_members:
         name_is_none = new_member.__name__ is None
         sync_with_repo |= name_is_none
         if not name_is_none \
            and not self.context.get(new_member.__name__) is None:
             # We have a member with the same name - 409 Conflict.
             result = self._handle_conflict(new_member.__name__)
             was_created = False
             break
         else:
             self.context.add(new_member)
     if was_created:
         if sync_with_repo:
             # This is not pretty, but necessary: When the resource
             # name depends on the entity ID, the pending entity needs
             # to be flushed to the repository before we can access
             # the ID.
             self.context.get_aggregate().sync_with_repository()
         self.request.response.status = self._status(HTTPCreated)
         if data_is_member:
             loc_rc = resource
         else:
             loc_rc = self.context
         self._update_response_location_header(loc_rc)
         result = self._get_result(resource)
     return result
예제 #6
0
 def _process_request_data(self, data):
     if not provides_resource(data):
         rpr = self._get_request_representer()
         resource = rpr.resource_from_data(data)
     else:
         resource = data
     member_was_posted = provides_member_resource(resource)
     if member_was_posted:
         new_members = [resource]
     else:
         new_members = resource
     was_created = True
     parent_collection_is_nested = self.context.is_nested
     for new_member in new_members:
         if parent_collection_is_nested:
             # If we are POSTing to a nested collection, the framework
             # tries to infer the parent for each member if it has not
             # been provided by the representation.
             self.__check_parent(new_member)
         if self.context.get(new_member.__name__) is not None:
             # We have a member with the same name - 409 Conflict.
             response = self._handle_conflict(new_member.__name__)
             was_created = False
             break
         else:
             self.context.add(new_member)
     if was_created:
         if member_was_posted:
             new_location = resource_to_url(resource, request=self.request)
         else:
             new_location = resource_to_url(self.context,
                                            request=self.request)
         self.request.response.status = self._status(HTTPCreated)
         self.request.response.headerlist = [('Location', new_location)]
         response = self._get_result(resource)
     return response
예제 #7
0
 def _process_request_data(self, data):
     if not provides_resource(data):
         rpr = self._get_request_representer()
         resource = rpr.resource_from_data(data)
     else:
         resource = data
     member_was_posted = provides_member_resource(resource)
     if member_was_posted:
         new_members = [resource]
     else:
         new_members = resource
     was_created = True
     parent_collection_is_nested = self.context.is_nested
     for new_member in new_members:
         if parent_collection_is_nested:
             # If we are POSTing to a nested collection, the framework
             # tries to infer the parent for each member if it has not
             # been provided by the representation.
             self.__check_parent(new_member)
         if self.context.get(new_member.__name__) is not None:
             # We have a member with the same name - 409 Conflict.
             response = self._handle_conflict(new_member.__name__)
             was_created = False
             break
         else:
             self.context.add(new_member)
     if was_created:
         if member_was_posted:
             new_location = resource_to_url(resource, request=self.request)
         else:
             new_location = resource_to_url(self.context,
                                            request=self.request)
         self.request.response.status = self._status(HTTPCreated)
         self.request.response.headerlist = [('Location', new_location)]
         response = self._get_result(resource)
     return response