def put(self, authcontext, entity_id): """ updates an omartestpy4 item """ try: model = omartestpy4ModelPut(**request.get_json()) context = authcontext['context'] omartestpy4Service(context).update(model, entity_id) return EMPTY, 204 except omartestpy4ServiceError as e: LOG.error(e) return ErrorModel(**{ 'error_code': str(e.errors.value), 'error_message': e.args[0] }), e.errors except ValueError as e: LOG.error(e) return ErrorModel(**{ 'error_code': '400', 'error_message': e.args[0] }), 400 except Exception as ex: LOG.error(ex) return ErrorModel(**{ 'error_code': '500', 'error_message': ex.args[0] }), 500
def delete(self, authcontext, entity_id): """ Delete omartestpy4 item """ try: omartestpy4Service(authcontext['context']).delete(entity_id) return EMPTY, 204 except omartestpy4ServiceError as e: LOG.error(e) return ErrorModel(**{ 'error_code': str(e.errors.value), 'error_message': e.args[0] }), e.errors except ValueError as e: LOG.error(e) return ErrorModel(**{ 'error_code': '400', 'error_message': e.args[0] }), 400 except Exception as ex: LOG.error(ex) return ErrorModel(**{ 'error_code': '500', 'error_message': ex.args[0] }), 500
def post(self, authcontext): """ Adds a omartestpy4 item. """ try: model = omartestpy4ModelPost(**request.get_json()) result = omartestpy4Service(authcontext['context'])\ .save(model) response = omartestpy4ModelPostResponse() for key in response.properties: response[key] = result[key] return (response, 201, { 'Location': request.path + '/' + str(response['id']) }) except ValueError as e: LOG.error(e) return ErrorModel(**{ 'error_code': str(e.errors.value), 'error_message': e.args[0] }), 400 except ExtraValueException as e: LOG.error(e) return ErrorModel( **{ 'error_code': '400', 'error_message': "{} is not valid input".format(e.args[0]) }), 400 except Exception as ex: LOG.error(ex) return ErrorModel(**{ 'error_code': '500', 'error_message': ex.args[0] }), 500
def get(self, authcontext): """ gets all omartestpy4 items """ LOG.debug("Serving Get all request") list = omartestpy4Service(authcontext['context']).get_all() # normalize the name for 'id' return list, 200
def setUp(self): context = AuthContext("23432523452345", "tenantname", "987656789765670", "orgname", "1009009009988", "username", False) self.omartestpy4Service = omartestpy4Service(context) self.omartestpy4_api_model = self.createTestModelData() self.omartestpy4_data = self.setupDatabaseRecords( self.omartestpy4_api_model) self.omartestpy4_someoneelses = \ self.setupDatabaseRecords(self.omartestpy4_api_model) self.omartestpy4_someoneelses.tenantId = "123432523452345" with patch('mongomock.write_concern.WriteConcern.__init__', return_value=None): self.omartestpy4_someoneelses.save() self.omartestpy4_api_model_put_description \ = self.createTestModelDataDescription() self.test_data_collection = [self.omartestpy4_data]
def get(self, authcontext, entity_id): """gets an omartestpy4 item that omar has changed """ try: LOG.debug("Get details by id %s ", entity_id) data = omartestpy4Service(authcontext['context'])\ .find_by_id(entity_id) clean_nonserializable_attributes(data) except omartestpy4ServiceError as e: LOG.error(e) return ErrorModel(**{ 'error_code': str(e.errors.value), 'error_message': e.args[0] }), e.errors except ValueError as e: LOG.error(e) return ErrorModel(**{ 'error_code': '400', 'error_message': e.args[0] }), 400 return omartestpy4Model(**data), 200