11import json
22from configparser import ConfigParser
3+ from pathlib import Path
34
45import pytest
56from sqlmodel import Session
67
78from murfey .util .db import Session as MurfeySession
89from 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
1514def 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