From 07deef46a3f3ba53cc632a9381fb25c55e1017b1 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 24 Jan 2024 12:29:10 +0300 Subject: Checks: Update code and tests to ensure all checks pass. --- tests/conftest.py | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'tests/conftest.py') diff --git a/tests/conftest.py b/tests/conftest.py index b7d3f8a..013c30d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,10 @@ import jsonpickle from redis import Redis from functional_tools import take + from qc_app import jobs, create_app +from qc_app.jobs import JOBS_PREFIX + from quality_control.errors import InvalidValue, DuplicateHeading @pytest.fixture(scope="session") @@ -55,11 +58,26 @@ def client(): cleanup_redis(app.config["REDIS_URL"], test_prefix) +@pytest.fixture(scope="module") +def db_url(client):#pylint: disable=[redefined-outer-name] + """Return the database URI""" + return client.application.config["SQL_URI"] + @pytest.fixture(scope="module") def redis_url(client):#pylint: disable=[redefined-outer-name] """Return the redis URI""" return client.application.config["REDIS_URL"] +@pytest.fixture(scope="module") +def redis_prefix(client):#pylint: disable=[redefined-outer-name] + """Return the redis prefix""" + return client.application.config["GNQC_REDIS_PREFIX"] + +@pytest.fixture(scope="module") +def jobs_prefix(redis_prefix):#pylint: disable=[redefined-outer-name] + """Return the redis prefix for jobs.""" + return f"{redis_prefix}:{JOBS_PREFIX}" + @pytest.fixture(scope="module") def redis_ttl(client):#pylint: disable=[redefined-outer-name] """Return the redis URI""" @@ -81,11 +99,11 @@ def cleanup_job(rconn, jobid, thejob): rconn.delete(jobs.job_key(jobs.jobsnamespace(), jobid)) @pytest.fixture(scope="function") -def redis_conn_with_fresh_job(redis_url, redis_ttl, job_id):#pylint: disable=[redefined-outer-name] +def redis_conn_with_fresh_job(redis_url, redis_ttl, jobs_prefix, job_id):#pylint: disable=[redefined-outer-name] "redis connection with fresh, unprocessed job" thejob = { - "job_id": job_id, "command": "some_test_command", "job_type": "testjob", - "ttl_seconds": redis_ttl, "extra_meta": { + "jobid": job_id, "command": "some_test_command", "job_type": "testjob", + "ttl_seconds": redis_ttl, "rprefix": jobs_prefix, "extra_meta": { "filename": "/path/to/some/file.tsv", "percent": 0, "status": "pending"}} with redis.Redis.from_url(redis_url, decode_responses=True) as rconn: @@ -94,11 +112,12 @@ def redis_conn_with_fresh_job(redis_url, redis_ttl, job_id):#pylint: disable=[re cleanup_job(rconn, job_id, thejob) @pytest.fixture(scope="function") -def redis_conn_with_in_progress_job_no_errors(redis_url, redis_ttl, job_id):#pylint: disable=[redefined-outer-name] +def redis_conn_with_in_progress_job_no_errors(redis_url, redis_ttl, jobs_prefix, job_id):#pylint: disable=[redefined-outer-name] "redis connection with partially processed job, with no errors" thejob = { - "job_id": job_id, "command": "some_test_command", - "ttl_seconds": redis_ttl, "job_type": "testjob", "extra_meta": { + "jobid": job_id, "command": "some_test_command", + "ttl_seconds": redis_ttl, "rprefix": jobs_prefix, "job_type": "testjob", + "extra_meta": { "status": "Processing", "filename": "/path/to/some/file.tsv", "percent": 32.242342}} with redis.Redis.from_url(redis_url, decode_responses=True) as rconn: @@ -107,11 +126,12 @@ def redis_conn_with_in_progress_job_no_errors(redis_url, redis_ttl, job_id):#pyl cleanup_job(rconn, job_id, thejob) @pytest.fixture(scope="function") -def redis_conn_with_in_progress_job_some_errors(redis_url, redis_ttl, job_id): # pylint: disable=[redefined-outer-name] +def redis_conn_with_in_progress_job_some_errors(redis_url, redis_ttl, jobs_prefix, job_id): # pylint: disable=[redefined-outer-name] "redis connection with partially processed job, with some errors" the_job = { - "job_id": job_id, "command": "some_test_command", - "ttl_seconds": redis_ttl, "job_type": "testjob", "extra_meta": { + "jobid": job_id, "command": "some_test_command", + "ttl_seconds": redis_ttl, "rprefix": jobs_prefix, "job_type": "testjob", + "extra_meta": { "status": "Processing", "filename": "/path/to/some/file.tsv", "percent": 45.34245, "errors": jsonpickle.encode(( DuplicateHeading( @@ -124,11 +144,12 @@ def redis_conn_with_in_progress_job_some_errors(redis_url, redis_ttl, job_id): # cleanup_job(rconn, job_id, the_job) @pytest.fixture(scope="function") -def redis_conn_with_completed_job_no_errors(redis_url, redis_ttl, job_id): # pylint: disable=[redefined-outer-name] +def redis_conn_with_completed_job_no_errors(redis_url, redis_ttl, jobs_prefix, job_id): # pylint: disable=[redefined-outer-name] "redis connection with completely processed job, with no errors" the_job = { - "job_id": job_id, "command": "some_test_command", - "ttl_seconds": redis_ttl, "job_type": "testjob", "extra_meta": { + "jobid": job_id, "command": ["complete", "--woerror", "test-command"], + "ttl_seconds": redis_ttl, "rprefix": jobs_prefix, "job_type": "testjob", + "extra_meta": { "status": "success", "filename": "/path/to/some/file.tsv", "percent": 100, "errors": jsonpickle.encode(tuple())}} with redis.Redis.from_url(redis_url, decode_responses=True) as rconn: @@ -137,11 +158,12 @@ def redis_conn_with_completed_job_no_errors(redis_url, redis_ttl, job_id): # pyl cleanup_job(rconn, job_id, the_job) @pytest.fixture(scope="function") -def redis_conn_with_completed_job_some_errors(redis_url, redis_ttl, job_id): # pylint: disable=[redefined-outer-name] +def redis_conn_with_completed_job_some_errors(redis_url, redis_ttl, jobs_prefix, job_id): # pylint: disable=[redefined-outer-name] "redis connection with completely processed job, with some errors" the_job = { - "job_id": job_id, "command": "some_test_command", - "ttl_seconds": redis_ttl, "job_type": "testjob", "extra_meta": { + "jobid": job_id, "command": ["complete", "--werror", "test-command"], + "ttl_seconds": redis_ttl, "rprefix": jobs_prefix, "job_type": "testjob", + "extra_meta": { "status": "success", "filename": "/path/to/some/file.tsv", "percent": 100, "errors": jsonpickle.encode(( DuplicateHeading( -- cgit v1.2.3