aboutsummaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 90d8264..be5f9f2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -103,7 +103,7 @@ def redis_conn_with_completed_job_no_errors(redis_url, job_id): # pylint: disabl
the_job = {
"job_id": job_id, "command": "some_test_command",
"status": "success", "filename": "/path/to/some/file.tsv",
- "percent": 100
+ "percent": 100, "errors": jsonpickle.encode(tuple())
}
with redis.Redis.from_url(redis_url, decode_responses=True) as rconn:
rconn.hset(name=job_id, mapping=the_job)
@@ -127,3 +127,44 @@ def redis_conn_with_completed_job_some_errors(redis_url, job_id): # pylint: disa
yield rconn
rconn.hdel(job_id, *the_job.keys())
rconn.delete(job_id)
+
+@pytest.fixture(scope="function")
+def uploads_dir(client): # pylint: disable=[redefined-outer-name]
+ """Returns the configured, uploads directory, creating it if it does not
+ exist."""
+ the_dir = client.application.config["UPLOAD_FOLDER"]
+ if not os.path.exists(the_dir):
+ os.mkdir(the_dir)
+
+ return the_dir
+
+@pytest.fixture(scope="function")
+def jobs_errors_dir(uploads_dir): # pylint: disable=[redefined-outer-name]
+ """Returns the configured, jobs errors directory, creating it if it does not
+ exist."""
+ the_dir = f"{uploads_dir}/job_errors"
+ if not os.path.exists(the_dir):
+ os.mkdir(the_dir)
+
+ return the_dir
+
+@pytest.fixture(scope="function")
+def stderr_with_output(jobs_errors_dir, job_id): # pylint: disable=[redefined-outer-name]
+ """Creates a sample worker error file with some content"""
+ filepath = f"{jobs_errors_dir}/job_{job_id}.error"
+ with open(filepath, "w", encoding="utf8") as error_file:
+ error_file.write("This is an non-empty error file.")
+ error_file.flush()
+ yield filepath
+
+ os.remove(filepath)
+
+@pytest.fixture(scope="function")
+def stderr_with_no_output(jobs_errors_dir, job_id): # pylint: disable=[redefined-outer-name]
+ """Creates a sample worker error file with no content"""
+ filepath = f"{jobs_errors_dir}/job_{job_id}.error"
+ with open(filepath, "w", encoding="utf-8") as error_file:
+ error_file.flush()
+ yield filepath
+
+ os.remove(filepath)