def post(self, id): try: patching.reject(id, g.identity.id) database.commit() return None, 204 except patching.MergeError as e: return {'message': e.message}, 404
def load_data(datafile): with app.app_context(): with open(datafile) as f: data = json.load(f) user_id = "initial-data-loader" patch = JsonPatch.from_diff({}, data) patch_request_id = patching.create_request(patch, user_id) patching.merge(patch_request_id, user_id) database.commit()
def patch(self): try: patch_request_id = patching.create_request( patching.from_text(request.data), g.identity.id) database.commit() return None, 202, { 'Location': api.url_for(PatchRequest, id=patch_request_id) } except patching.InvalidPatchError as e: return {'status': 400, 'message': str(e)}, 400
def post(self, id): try: patching.merge(id, g.identity.id) database.commit() cache.purge_history() cache.purge_dataset() cache.purge_graphs() return None, 204 except patching.MergeError as e: return {'message': e.message}, 404 except patching.UnmergeablePatchError as e: return {'message': e.message}, 400
def patch(self): try: patch_request_id = patching.create_request( JsonPatch(parse_json(request)), g.identity.id) database.commit() return None, 202, { 'Location': url_for('patchrequest', id=patch_request_id) } except ResourceError as e: return e.response() except patching.InvalidPatchError as e: return {'status': 400, 'message': str(e)}, 400
def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True self.client = app.test_client() commands.init_db() with app.app_context(): self.identity = auth.add_user_or_update_credentials( {'name': 'Testy Testerson', 'access_token': '5005eb18-be6b-4ac0-b084-0443289b3378', 'expires_in': 631138518, 'orcid': '1234-5678-9101-112X'}) self.expired_identity = auth.add_user_or_update_credentials({ 'name': 'Eric Expired', 'access_token': 'f7c64584-0750-4cb6-8c81-2932f5daabb8', 'expires_in': -3600, 'orcid': '1211-1098-7654-321X', }) database.commit()
def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True self.client = app.test_client() commands.init_db() commands.load_data(filepath('test-data.json')) with app.app_context(): self.user_identity = auth.add_user_or_update_credentials({ 'name': 'Regular Gal', 'access_token': '5005eb18-be6b-4ac0-b084-0443289b3378', 'expires_in': 631138518, 'orcid': '1234-5678-9101-112X', }) self.admin_identity = auth.add_user_or_update_credentials({ 'name': 'Super Admin', 'access_token': 'f7c64584-0750-4cb6-8c81-2932f5daabb8', 'expires_in': 3600, 'orcid': '1211-1098-7654-321X', }, (ActionNeed('accept-patch'),)) database.commit()
def post(self, id): data = request.data or '' if isinstance(data, bytes): data = data.decode() try: data = json.loads(data) message = data['message'] except KeyError: return {'message': 'No message present in request data.'}, 400 try: patching.add_comment(id, g.identity.id, message) database.commit() return None, 200, { 'Location': url_for('patchrequest', id=id) } except patching.MergeError as e: return {'message': e.message}, 404