@@ -60,6 +60,27 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None:
60
60
helpers .safe_delete (user , hard_delete = True )
61
61
62
62
63
+ def set_token (container , fixture_dir ):
64
+ logging .info ("Creating API token." )
65
+ set_token_rb = fixture_dir / "set_token.rb"
66
+
67
+ with open (set_token_rb , "r" , encoding = "utf-8" ) as f :
68
+ set_token_command = f .read ().strip ()
69
+
70
+ rails_command = [
71
+ "docker" ,
72
+ "exec" ,
73
+ container ,
74
+ "gitlab-rails" ,
75
+ "runner" ,
76
+ set_token_command ,
77
+ ]
78
+ output = check_output (rails_command ).decode ().strip ()
79
+ logging .info ("Finished creating API token." )
80
+
81
+ return output
82
+
83
+
63
84
def pytest_report_collectionfinish (config , startdir , items ):
64
85
return [
65
86
"" ,
@@ -146,7 +167,7 @@ def _wait(timeout=30, step=0.5):
146
167
147
168
148
169
@pytest .fixture (scope = "session" )
149
- def gitlab_config (check_is_alive , docker_ip , docker_services , temp_dir ):
170
+ def gitlab_config (check_is_alive , docker_ip , docker_services , temp_dir , fixture_dir ):
150
171
config_file = temp_dir / "python-gitlab.cfg"
151
172
port = docker_services .port_for ("gitlab" , 80 )
152
173
@@ -163,13 +184,15 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir):
163
184
f"GitLab container is now ready after { minutes } minute(s), { seconds } seconds"
164
185
)
165
186
187
+ token = set_token ("gitlab-test" , fixture_dir = fixture_dir )
188
+
166
189
config = f"""[global]
167
190
default = local
168
191
timeout = 60
169
192
170
193
[local]
171
194
url = http://{ docker_ip } :{ port }
172
- private_token = python-gitlab- token
195
+ private_token = { token }
173
196
api_version = 4"""
174
197
175
198
with open (config_file , "w" , encoding = "utf-8" ) as f :
0 commit comments