@@ -56,6 +56,15 @@ def enable_filepath_feature(monkeypatch):
56
56
monkeypatch .delenv (FILEPATH_FEATURE_SWITCH , raising = True )
57
57
58
58
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
+
59
68
@pytest .fixture (scope = "session" )
60
69
def db_creds_root () -> Dict :
61
70
return dict (
@@ -142,12 +151,9 @@ def connection_root(connection_root_bare):
142
151
143
152
144
153
@pytest .fixture (scope = "session" )
145
- def connection_test (connection_root ):
154
+ def connection_test (connection_root , db_creds_test ):
146
155
"""Test user database connection."""
147
156
database = f"{ PREFIX } %%"
148
- credentials = dict (
149
- host = os .getenv ("DJ_HOST" ), user = "datajoint" , password = "datajoint"
150
- )
151
157
permission = "ALL PRIVILEGES"
152
158
153
159
# Create MySQL users
@@ -157,14 +163,14 @@ def connection_test(connection_root):
157
163
# create user if necessary on mysql8
158
164
connection_root .query (
159
165
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" ]} ';
162
168
"""
163
169
)
164
170
connection_root .query (
165
171
f"""
166
172
GRANT { permission } ON `{ database } `.*
167
- TO '{ credentials ["user" ]} '@'%%';
173
+ TO '{ db_creds_test ["user" ]} '@'%%';
168
174
"""
169
175
)
170
176
else :
@@ -173,14 +179,14 @@ def connection_test(connection_root):
173
179
connection_root .query (
174
180
f"""
175
181
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" ]} ';
178
184
"""
179
185
)
180
186
181
- connection = dj .Connection (** credentials )
187
+ connection = dj .Connection (** db_creds_test )
182
188
yield connection
183
- connection_root .query (f"""DROP USER `{ credentials ["user" ]} `""" )
189
+ connection_root .query (f"""DROP USER `{ db_creds_test ["user" ]} `""" )
184
190
connection .close ()
185
191
186
192
0 commit comments