def test_delete(self): ann = Annotation(id=1) ann.save() newann = Annotation.fetch(1) newann.delete() noann = Annotation.fetch(1) assert noann == None
def test_delete(self): ann = Annotation(id=1) ann.save() newann = Annotation.fetch(1) newann.delete() noann = Annotation.fetch(1) assert_true(noann == None)
def update_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found! No update performed.', status=404) failure = _check_action(annotation, 'update') if failure: return failure if request.json is not None: updated = _filter_input(request.json, UPDATE_FILTER_FIELDS) updated[ 'id'] = id # use id from URL, regardless of what arrives in JSON payload if 'permissions' in updated and updated[ 'permissions'] != annotation.get('permissions', {}): failure = _check_action(annotation, 'admin', message='permissions update') if failure: return failure annotation.update(updated) if hasattr(g, 'before_annotation_update'): g.before_annotation_update(annotation) refresh = request.args.get('refresh') != 'false' annotation.save(refresh=refresh) return jsonify(annotation)
def update_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify("Annotation not found! No update performed.", status=404) failure = _check_action(annotation, "update") if failure: return failure if request.json is not None: updated = _filter_input(request.json, UPDATE_FILTER_FIELDS) updated["id"] = id # use id from URL, regardless of what arrives in # JSON payload changing_permissions = "permissions" in updated and updated["permissions"] != annotation.get("permissions", {}) if changing_permissions: failure = _check_action(annotation, "admin", message="permissions update") if failure: return failure annotation.update(updated) if hasattr(g, "before_annotation_update"): g.before_annotation_update(annotation) refresh = request.args.get("refresh") != "false" annotation.save(refresh=refresh) if hasattr(g, "after_annotation_update"): g.after_annotation_update(annotation) return jsonify(annotation)
def update_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found! No update performed.', status=404) failure = _check_action(annotation, 'update') if failure: return failure if request.json: updated = _filter_input(request.json, UPDATE_FILTER_FIELDS) updated['id'] = id # use id from URL, regardless of what arrives in JSON payload if 'permissions' in updated and updated['permissions'] != annotation.get('permissions', {}): failure = _check_action(annotation, 'admin', message='permissions update') if failure: return failure annotation.update(updated) if hasattr(g, 'before_annotation_update'): g.before_annotation_update(annotation) annotation.save() return jsonify(annotation)
def read_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify("Annotation not found!", status=404) failure = _check_action(annotation, "read", g.user, g.consumer) if failure: return failure return jsonify(annotation)
def read_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found!', status=404) failure = _check_action(annotation, 'read') if failure: return failure return jsonify(annotation)
def read_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found!', status=404) print("[store.py, read_annotation] annotation:" + str(annotation)) failure = _check_action(annotation, 'read') if failure: return failure return jsonify(annotation)
def test_basics(self): user = "******" ann = Annotation(text="Hello there", user=user) ann['ranges'] = [] ann['ranges'].append({}) ann['ranges'].append({}) ann.save() ann = Annotation.fetch(ann.id) assert_equal(ann['text'], "Hello there") assert_equal(ann['user'], "alice") assert_equal(len(ann['ranges']), 2)
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found. No delete performed.', status=404) failure = _check_action(annotation, 'delete') if failure: return failure annotation.delete() return None, 204
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify("Annotation not found. No delete performed.", status=404) failure = _check_action(annotation, "delete", g.user, g.consumer) if failure: return failure annotation.delete() return None, 204
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found. No delete performed.', status=404) failure = _check_action(annotation, 'delete') if failure: return failure annotation.delete() return '', 204
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found. No delete performed.', status=404) failure = _check_action(annotation, 'delete') if failure: return failure annotation.delete() # Original perhaps # return None, 204 # From OKFN # return '', 204 return jsonify(annotation), 204
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify("Annotation not found. No delete performed.", status=404) failure = _check_action(annotation, "delete") if failure: return failure if hasattr(g, "before_annotation_delete"): g.before_annotation_delete(annotation) annotation.delete() if hasattr(g, "after_annotation_delete"): g.after_annotation_delete(annotation) return "", 204
def delete_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify('Annotation not found. No delete performed.', status=404) failure = _check_action(annotation, 'delete') if failure: return failure if hasattr(g, 'before_annotation_delete'): g.before_annotation_delete(annotation) annotation.delete() if hasattr(g, 'after_annotation_delete'): g.after_annotation_delete(annotation) return '', 204
def test_basics(self): user = "******" ann = Annotation(text="Hello there", user=user) ann['ranges'] = [] ann['ranges'].append({'startOffset': 3}) ann['ranges'].append({'startOffset': 5}) ann['document'] = { 'title': 'Annotation for Dummies', 'link': [ {'href': 'http://example.com/1234', 'type': 'application/pdf'} ] } ann.save() ann = Annotation.fetch(ann['id']) assert_equal(ann['text'], "Hello there") assert_equal(ann['user'], "alice") assert_equal(len(ann['ranges']), 2) assert_equal(ann['document']['title'], 'Annotation for Dummies') assert_equal(ann['document']['link'][0]['href'], 'http://example.com/1234') assert_equal(ann['document']['link'][0]['type'], 'application/pdf')
def update_annotation(id): annotation = Annotation.fetch(id) if not annotation: return jsonify("Annotation not found! No update performed.", status=404) failure = _check_action(annotation, "update", g.user, g.consumer) if failure: return failure if request.json: updated = _filter_input(request.json, UPDATE_FILTER_FIELDS) updated["id"] = id # use id from URL, regardless of what arrives in JSON payload if "permissions" in updated and updated["permissions"] != annotation.get("permissions", {}): if not g.authorize(annotation, "admin", g.user.username, g.consumer.key): return _failed_authz_response("permissions update") annotation.update(updated) annotation.save() return jsonify(annotation)
def test_basics(self): user = "******" ann = Annotation(text="Hello there", user=user) ann['ranges'] = [] ann['ranges'].append({}) ann['ranges'].append({}) ann['document'] = { 'title': 'Annotation for Dummies', 'link': [ {'href': 'http://example.com/1234', 'type': 'application/pdf'} ] } ann.save() ann = Annotation.fetch(ann.id) assert_equal(ann['text'], "Hello there") assert_equal(ann['user'], "alice") assert_equal(len(ann['ranges']), 2) assert_equal(ann['document']['title'], 'Annotation for Dummies') assert_equal(ann['document']['link'][0]['href'], 'http://example.com/1234') assert_equal(ann['document']['link'][0]['type'], 'application/pdf')
def test_fetch(self): a = Annotation(foo='bar') a.save() b = Annotation.fetch(a.id) assert_equal(b['foo'], 'bar')
def _get_annotation(self, id_): return Annotation.fetch(id_)
def test_fetch(self): a = Annotation(foo='bar') a.save() b = Annotation.fetch(a['id']) assert_equal(b['foo'], 'bar')