Skip to content

Commit 55bf4ea

Browse files
committed
Add db_creds_test fixture
1 parent 7598441 commit 55bf4ea

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tests/conftest.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ def enable_filepath_feature(monkeypatch):
5656
monkeypatch.delenv(FILEPATH_FEATURE_SWITCH, raising=True)
5757

5858

59+
@pytest.fixture(scope="session")
60+
def db_creds_test() -> Dict:
61+
return dict(
62+
host=os.getenv("DJ_TEST_HOST", "fakeservices.datajoint.io"),
63+
user=os.getenv("DJ_TEST_USER", "datajoint"),
64+
password=os.getenv("DJ_TEST_PASSWORD", "datajoint"),
65+
)
66+
67+
5968
@pytest.fixture(scope="session")
6069
def db_creds_root() -> Dict:
6170
return dict(
@@ -142,12 +151,9 @@ def connection_root(connection_root_bare):
142151

143152

144153
@pytest.fixture(scope="session")
145-
def connection_test(connection_root):
154+
def connection_test(connection_root, db_creds_test):
146155
"""Test user database connection."""
147156
database = f"{PREFIX}%%"
148-
credentials = dict(
149-
host=os.getenv("DJ_HOST"), user="datajoint", password="datajoint"
150-
)
151157
permission = "ALL PRIVILEGES"
152158

153159
# Create MySQL users
@@ -157,14 +163,14 @@ def connection_test(connection_root):
157163
# create user if necessary on mysql8
158164
connection_root.query(
159165
f"""
160-
CREATE USER IF NOT EXISTS '{credentials["user"]}'@'%%'
161-
IDENTIFIED BY '{credentials["password"]}';
166+
CREATE USER IF NOT EXISTS '{db_creds_test["user"]}'@'%%'
167+
IDENTIFIED BY '{db_creds_test["password"]}';
162168
"""
163169
)
164170
connection_root.query(
165171
f"""
166172
GRANT {permission} ON `{database}`.*
167-
TO '{credentials["user"]}'@'%%';
173+
TO '{db_creds_test["user"]}'@'%%';
168174
"""
169175
)
170176
else:
@@ -173,14 +179,14 @@ def connection_test(connection_root):
173179
connection_root.query(
174180
f"""
175181
GRANT {permission} ON `{database}`.*
176-
TO '{credentials["user"]}'@'%%'
177-
IDENTIFIED BY '{credentials["password"]}';
182+
TO '{db_creds_test["user"]}'@'%%'
183+
IDENTIFIED BY '{db_creds_test["password"]}';
178184
"""
179185
)
180186

181-
connection = dj.Connection(**credentials)
187+
connection = dj.Connection(**db_creds_test)
182188
yield connection
183-
connection_root.query(f"""DROP USER `{credentials["user"]}`""")
189+
connection_root.query(f"""DROP USER `{db_creds_test["user"]}`""")
184190
connection.close()
185191

186192

0 commit comments

Comments
 (0)