def to_be_enqueued_with_value(topic, expected_key, expected_val=None): """Asserts that `job is enqueued with proper value`.""" topic = utils.fix_string(topic) expected_key = utils.fix_string(expected_key) queue_job_id = topic["queueJobId"] hash_key = f"rq:job:{queue_job_id}" if expected_val is None: exists = current_app.redis.hexists(hash_key, expected_key) if not exists: has_key(current_app.redis, topic, hash_key, expected_key) return if not current_app.redis.hexists(hash_key, expected_key): has_key(current_app.redis, topic, hash_key, expected_key) curr_val = utils.fix_string(current_app.redis.hget(hash_key, expected_key)) if curr_val != utils.fix_string(expected_val): raise AssertionError( f"Expected job to be enqueued with {expected_key}=" f"'{expected_val}', but it's value was '{curr_val}'.")
def to_be_enqueued(topic): """Asserts that `job is enqueued`.""" topic = utils.fix_string(topic) queue_job_id = utils.fix_string(topic["queueJobId"]) hash_key = f"rq:job:{queue_job_id}" exists = current_app.redis.exists(hash_key) if not exists: raise AssertionError( f"Expected job '{queue_job_id}' to exist but it was not found") queue_name = "rq:queue:jobs" res = [ utils.fix_string(job_id) for job_id in current_app.redis.lrange(queue_name, -1, 1) ] for j in res: if j == queue_job_id: return raise AssertionError( f"Expected job '{queue_job_id}' to be in the 'jobs' queue, but it was not found(" f"found jobs: {','.join(res)}.")
def to_equal(topic, expected): '''Asserts that `topic == expected`.''' topic = utils.fix_string(topic) expected = utils.fix_string(expected) try: return expected == topic except: return False
def to_be_lesser_or_equal_to(topic, expected): '''Asserts that `topic <= expected`.''' topic = utils.fix_string(topic) expected = utils.fix_string(expected) if isinstance(expected, (tuple, list, set, dict)): return len(topic) <= len(expected) return topic <= expected
def to_be_greater_than(topic, expected): '''Asserts that `topic > expected`.''' topic = utils.fix_string(topic) expected = utils.fix_string(expected) if isinstance(expected, (tuple, list, set, dict)): return len(topic) > len(expected) return topic > expected
def _strip_string(text): if not text: return text text = utils.fix_string(text) text = REMOVE_COLORS_REGEX.sub('', text) text = _filter_str(text) return text
def to_be_enqueued(topic): """Asserts that `job is enqueued`.""" topic = utils.fix_string(topic) queue_job_id = utils.fix_string(topic["queueJobId"]) hash_key = f"{Queue.QUEUE_NAME}:jobs" exists = current_app.redis.exists(hash_key) if not exists: raise AssertionError( f"Expected job '{queue_job_id}' to exist but it was not found") message_ids = current_app.redis.lrange(hash_key, 0, -1) for message_id in message_ids: if message_id.decode("utf-8") == queue_job_id: return raise AssertionError( f"Expected job '{queue_job_id}' to be in the 'jobs' queue, but it was not found(" f"found jobs: {','.join([message_id.decode('utf-8') for message_id in message_ids])})." )