def post(self, authcontext): """ Adds a hjqubeship item. """ try: model = hjqubeshipModelPost(**request.get_json()) result = hjqubeshipService(authcontext['context'])\ .save(model) response = hjqubeshipModelPostResponse() 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 hjqubeship items """ LOG.debug("Serving Get all request") list = hjqubeshipService(authcontext['context']).get_all() # normalize the name for 'id' return list, 200
def delete(self, authcontext, entity_id): """ Delete hjqubeship item """ try: hjqubeshipService(authcontext['context']).delete(entity_id) return EMPTY, 204 except hjqubeshipServiceError 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 put(self, authcontext, entity_id): """ updates an hjqubeship item """ try: model = hjqubeshipModelPut(**request.get_json()) context = authcontext['context'] hjqubeshipService(context).update(model, entity_id) return EMPTY, 204 except hjqubeshipServiceError 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 get(self, authcontext, entity_id): """gets an hjqubeship item that omar has changed """ try: LOG.debug("Get details by id %s ", entity_id) data = hjqubeshipService(authcontext['context'])\ .find_by_id(entity_id) clean_nonserializable_attributes(data) except hjqubeshipServiceError 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 hjqubeshipModel(**data), 200
def setUp(self): context = AuthContext("23432523452345", "tenantname", "987656789765670", "orgname", "1009009009988", "username", False) self.hjqubeshipService = hjqubeshipService(context) self.hjqubeship_api_model = self.createTestModelData() self.hjqubeship_data = \ self.setupDatabaseRecords(self.hjqubeship_api_model) self.hjqubeship_someoneelses = \ self.setupDatabaseRecords(self.hjqubeship_api_model) self.hjqubeship_someoneelses.tenantId = "123432523452345" with patch('mongomock.write_concern.WriteConcern.__init__', return_value=None): self.hjqubeship_someoneelses.save() self.hjqubeship_api_model_put_description \ = self.createTestModelDataDescription() self.test_data_collection = [self.hjqubeship_data]