def test_you_cannot_change_an_annotations_userid(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, "", "") appstruct = schema.validate({"userid": "new_userid"}) assert "userid" not in appstruct assert "userid" not in appstruct.get("extra", {})
def test_you_cannot_change_an_annotations_references(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, "", "") appstruct = schema.validate({"references": ["new_parent"]}) assert "references" not in appstruct assert "references" not in appstruct.get("extra", {})
def test_you_cannot_change_an_annotations_userid(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, '', '') appstruct = schema.validate({'userid': 'new_userid'}) assert 'userid' not in appstruct assert 'userid' not in appstruct.get('extra', {})
def test_you_cannot_change_an_annotations_references(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, '', '') appstruct = schema.validate({'references': ['new_parent']}) assert 'references' not in appstruct assert 'references' not in appstruct.get('extra', {})
def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, "", "__world__") appstruct = schema.validate({"permissions": {"read": ["group:__world__"]}}) assert appstruct["shared"] is True assert "permissions" not in appstruct assert "permissions" not in appstruct.get("extras", {})
def update_annotation_schema_validate(request, data, existing_target_uri='', groupid=''): schema = UpdateAnnotationSchema(request, existing_target_uri, groupid) return schema.validate(data)
def test_it_passes_existing_target_uri_to_document_metas_from_data( self, document_claims, pyramid_request): """ If no 'uri' is given it should use the existing target_uri. If no 'uri' is given in the update request then document_metas_from_data() should be called with the existing target_uri of the annotation in the database. """ document_data = {"foo": "bar"} schema = UpdateAnnotationSchema(pyramid_request, mock.sentinel.target_uri, "") schema.validate({"document": document_data}) document_claims.document_metas_from_data.assert_called_once_with( document_data, claimant=mock.sentinel.target_uri)
def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, "", "") appstruct = schema.validate( {"permissions": {"read": ["acct:[email protected]"]}} ) assert not appstruct["shared"] assert "permissions" not in appstruct assert "permissions" not in appstruct.get("extras", {})
def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, '', '') appstruct = schema.validate({ 'permissions': {'read': ['acct:[email protected]']} }) assert appstruct['shared'] is False assert 'permissions' not in appstruct assert 'permissions' not in appstruct.get('extras', {})
def test_it_passes_existing_target_uri_to_document_metas_from_data( self, document_claims, pyramid_request ): """ If no 'uri' is given it should use the existing target_uri. If no 'uri' is given in the update request then document_metas_from_data() should be called with the existing target_uri of the annotation in the database. """ document_data = {"foo": "bar"} schema = UpdateAnnotationSchema(pyramid_request, mock.sentinel.target_uri, "") schema.validate({"document": document_data}) document_claims.document_metas_from_data.assert_called_once_with( document_data, claimant=mock.sentinel.target_uri )
def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, "", "") appstruct = schema.validate( {"permissions": {"read": ["acct:[email protected]"]}} ) assert appstruct["shared"] is False assert "permissions" not in appstruct assert "permissions" not in appstruct.get("extras", {})
def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request): schema = UpdateAnnotationSchema(pyramid_request, '', '__world__') appstruct = schema.validate({ 'permissions': {'read': ['group:__world__']} }) assert appstruct['shared'] is True assert 'permissions' not in appstruct assert 'permissions' not in appstruct.get('extras', {})
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" schema = UpdateAnnotationSchema( request, context.annotation.target_uri, context.annotation.groupid ) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request, context.annotation.id, appstruct) _publish_annotation_event(request, annotation, "update") return request.find_service(name="annotation_json").present_for_user( annotation=annotation, user=request.user )
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" schema = UpdateAnnotationSchema(request, context.annotation.target_uri, context.annotation.groupid) appstruct = schema.validate(_json_payload(request)) group_service = request.find_service(IGroupService) annotation = storage.update_annotation(request, context.annotation.id, appstruct, group_service) _publish_annotation_event(request, annotation, "update") svc = request.find_service(name="annotation_json_presentation") annotation_resource = _annotation_resource(request, annotation) return svc.present(annotation_resource)
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" if request.method == 'PUT' and hasattr(request, 'stats'): request.stats.incr('api.deprecated.put_update_annotation') schema = UpdateAnnotationSchema(request, context.annotation.target_uri, context.annotation.groupid) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request.db, context.annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') svc = request.find_service(name='annotation_json_presentation') annotation_resource = _annotation_resource(request, annotation) return svc.present(annotation_resource)
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" if request.method == 'PUT' and hasattr(request, 'stats'): request.stats.incr('api.deprecated.put_update_annotation') schema = UpdateAnnotationSchema(request, context.annotation.target_uri, context.annotation.groupid) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request.db, context.annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') links_service = request.find_service(name='links') group_service = request.find_service(IGroupService) resource = AnnotationResource(annotation, group_service, links_service) presenter = AnnotationJSONPresenter(resource) return presenter.asdict()
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" if request.method == "PUT" and hasattr(request, "stats"): request.stats.incr("api.deprecated.put_update_annotation") schema = UpdateAnnotationSchema( request, context.annotation.target_uri, context.annotation.groupid ) appstruct = schema.validate(_json_payload(request)) group_service = request.find_service(IGroupService) annotation = storage.update_annotation( request, context.annotation.id, appstruct, group_service ) _publish_annotation_event(request, annotation, "update") svc = request.find_service(name="annotation_json_presentation") annotation_resource = _annotation_resource(request, annotation) return svc.present(annotation_resource)