def find_user_by(name=None, user_type=None): if name is None: raise exceptions.InvalidParameter("Name for User must be present") if user_type is None: raise exceptions.InvalidParameter( "You must indicate if you are a Client or an Owner") users_found = User.filter_by(name, user_type) if not users_found: raise exceptions.NotFound("There's no User matching the criteria") return users_found[0]
def create_for_user(cls, id, user_id): db_instance = cls.repository.one_or_none(id=id) if db_instance is None: raise exceptions.NotFound( 'Could not find a note with id {}'.format(id)) if db_instance.user_id != user_id: raise exceptions.NotMine( 'Could not create note because it dont belong to user id {}'. format(user_id)) return cls(db_instance=db_instance)
def fetch(self, sql: TextClause, **params) -> typing.List[RowProxy]: res = self.engine.execute(sql, **params).fetchall() if not res: raise excs.NotFound() return res
def _create_with_keys(cls, **keys): db_instance = cls.repository.one_or_none(**keys) if db_instance is None: raise exceptions.NotFound('Could not find a user with keys: {}'.format(keys)) return cls(db_instance=db_instance)
def create_with_id(cls, id): db_instance = cls.repository.one_or_none(id=id) if db_instance is None: raise exceptions.NotFound('Could not find a entity with id {}'.format(id)) return cls(db_instance=db_instance)
def test_NotFound_detail(): # NOQA assert exceptions.NotFound().detail == 'Not Found'
def test_NotFound_status_code(): # NOQA assert exceptions.NotFound().status_code == 404
def get_client_by_external_id_and_source_id(external_client_id, system_id): searched_client = Client.query.filter_by(externalId=external_client_id, sourceId=system_id).first() if searched_client is None: raise exceptions.NotFound("There is no client with that ID") return searched_client
def get_client(client_id): searched_client = Client.query.get(client_id) if searched_client is None: raise exceptions.NotFound("There is no client with that ID") return searched_client
def get_queue(queue_id): searched_queue = ConceptQueue.query.get(queue_id) if searched_queue is None: raise exceptions.NotFound("There is no queue with that ID") return searched_queue
def get_owner(owner_id): searched_owner = Owner.query.get(owner_id) if searched_owner is None: raise exceptions.NotFound("There is no owner with that ID") return searched_owner
def create_with_id(cls, something_id): db_instance = cls.repository.one_or_none(id=something_id) if db_instance is None: raise exceptions.NotFound( 'Could not find a something with id = {}'.format(something_id)) return cls(db_instance=db_instance)