Skip to content

Commit 97dc116

Browse files
committed
Added fixture for ISPyB credentials file; modified security configuration file fixture to return file path as part of the fixture
1 parent 03897de commit 97dc116

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

tests/conftest.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import json
22
from configparser import ConfigParser
3+
from pathlib import Path
34

45
import pytest
56
from sqlmodel import Session
67

78
from murfey.util.db import Session as MurfeySession
89
from murfey.util.db import clear, setup
9-
from tests import engine, url
10-
11-
mock_security_config_name = "security_config.yaml"
10+
from tests import murfey_db_engine, murfey_db_url
1211

1312

1413
@pytest.fixture
1514
def start_postgres():
16-
clear(url)
17-
setup(url)
15+
clear(murfey_db_url)
16+
setup(murfey_db_url)
1817

1918
murfey_session = MurfeySession(id=2, name="cm12345-6")
20-
with Session(engine) as murfey_db:
19+
with Session(murfey_db_engine) as murfey_db:
2120
murfey_db.add(murfey_session)
2221
murfey_db.commit()
2322

@@ -37,15 +36,37 @@ def mock_client_configuration() -> ConfigParser:
3736

3837

3938
@pytest.fixture()
40-
def mock_security_configuration(tmp_path):
41-
config_file = tmp_path / mock_security_config_name
39+
def mock_ispyb_credentials(tmp_path: Path):
40+
creds_file = tmp_path / "ispyb_creds.cfg"
41+
ispyb_config = ConfigParser()
42+
# Use values from the GitHub workflow ISPyB config file
43+
ispyb_config["ispyb_sqlalchemy"] = {
44+
"username": "ispyb_api_sqlalchemy",
45+
"password": "password_5678",
46+
"host": "localhost",
47+
"port": "3306",
48+
"database": "ispybtest",
49+
}
50+
with open(creds_file, "w") as file:
51+
ispyb_config.write(file)
52+
return creds_file
53+
54+
55+
@pytest.fixture()
56+
def mock_security_configuration(
57+
tmp_path: Path,
58+
mock_ispyb_credentials: Path,
59+
):
60+
config_file = tmp_path / "security_config.yaml"
4261
security_config = {
62+
"murfey_db_credentials": "/path/to/murfey_db_credentials",
63+
"crypto_key": "crypto_key",
4364
"auth_key": "auth_key",
4465
"auth_algorithm": "auth_algorithm",
45-
"feedback_queue": "murfey_feedback",
4666
"rabbitmq_credentials": "/path/to/rabbitmq.yaml",
47-
"murfey_db_credentials": "/path/to/murfey_db_credentials",
48-
"crypto_key": "crypto_key",
67+
"feedback_queue": "murfey_feedback",
68+
"ispyb_credentials": str(mock_ispyb_credentials),
4969
}
5070
with open(config_file, "w") as f:
5171
json.dump(security_config, f)
72+
return config_file

0 commit comments

Comments
 (0)