def put(self, authcontext, entity_id): """ updates an jeff2 item """ try: model = jeff2ModelPut(**request.get_json()) context = authcontext['context'] jeff2Service(context).update(model, entity_id) return EMPTY, 204 except jeff2ServiceError 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 jeff2 item """ try: jeff2Service(authcontext['context']).delete(entity_id) return EMPTY, 204 except jeff2ServiceError 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 jeff2 item. """ try: model = jeff2ModelPost(**request.get_json()) result = jeff2Service(authcontext['context'])\ .save(model) response = jeff2ModelPostResponse() 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 jeff2 items """ LOG.debug("Serving Get all request") list = jeff2Service(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.jeff2Service = jeff2Service(context) self.jeff2_api_model = self.createTestModelData() self.jeff2_data = self.setupDatabaseRecords(self.jeff2_api_model) self.jeff2_someoneelses = \ self.setupDatabaseRecords(self.jeff2_api_model) self.jeff2_someoneelses.tenantId = "123432523452345" with patch('mongomock.write_concern.WriteConcern.__init__', return_value=None): self.jeff2_someoneelses.save() self.jeff2_api_model_put_description \ = self.createTestModelDataDescription() self.test_data_collection = [self.jeff2_data]
def get(self, authcontext, entity_id): """gets an jeff2 item that omar has changed """ try: LOG.debug("Get details by id %s ", entity_id) data = jeff2Service(authcontext['context'])\ .find_by_id(entity_id) clean_nonserializable_attributes(data) except jeff2ServiceError 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 jeff2Model(**data), 200