def get(cls, context, test_id): """Find a test based on its id or uuid and return a Cpulse object. :param test_id: the id *or* uuid of a test. :returns: a :class:`Cpulse` object. """ if utils.is_int_like(test_id): return cls.get_by_id(context, test_id) elif utils.is_uuid_like(test_id): return cls.get_by_uuid(context, test_id) else: raise exception.InvalidIdentity(identity=test_id)
def add_identity_filter(query, value): """Adds an identity filter to a query. Filters results by ID, if supplied value is a valid integer. Otherwise attempts to filter results by UUID. :param query: Initial query to add filter to. :param value: Value for filtering results by. :return: Modified query. """ if utils.is_int_like(value): return query.filter_by(id=value) elif utils.is_uuid_like(value): return query.filter_by(uuid=value) else: raise exception.InvalidIdentity(identity=value)