diff options
author | Frederick Muriuki Muriithi | 2022-06-15 08:05:11 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-06-15 08:05:11 +0300 |
commit | 6760d322637a3d875242a66e9c1a784866d7df1d (patch) | |
tree | 9c789b3f25cb1b1c04dc7974f9aab0ffcb6acdf4 /tests/conftest.py | |
parent | c2fa70ec8503d10b990575a547036bfd70a53825 (diff) | |
download | gn-uploader-6760d322637a3d875242a66e9c1a784866d7df1d.tar.gz |
Setup test fixtures and initial tests for web-UI
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 6ef5374..70bbd37 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,40 @@ """Set up fixtures for tests""" +import os +import socket +import subprocess +from contextlib import closing import pytest +from qc_app import create_app from quality_control.parsing import strain_names @pytest.fixture(scope="session") def strains(): """Parse the strains once every test session""" return strain_names("etc/strains.csv") + +def is_port_in_use(port: int) -> bool: + "Check whether `port` is in use" + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sckt: + return sckt.connect_ex(("localhost", port)) == 0 + +@pytest.fixture(scope="session") +def redis_server(): + "Fixture to launch a new redis instance and return appropriate URI" + port = next(# pylint: disable=[stop-iteration-return] + port for port in range(6379,65535) if not is_port_in_use(port)) + redis_path = f"{os.getenv('GUIX_ENVIRONMENT')}/bin/redis-server" + command = [redis_path, "--port", str(port)] + process = subprocess.Popen(command) # pylint: disable=[consider-using-with] + yield f"redis://localhost:{port}" + process.kill() + +@pytest.fixture(scope="module") +def client(redis_server): # pylint: disable=[redefined-outer-name] + "Fixture for test client" + app = create_app(f"{os.path.abspath('.')}/tests/test_instance_dir") + app.config.update({ + "REDIS_URL": redis_server + }) + yield app.test_client() |