@@ -60,6 +60,27 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None:
6060 helpers .safe_delete (user , hard_delete = True )
6161
6262
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+
6384def pytest_report_collectionfinish (config , startdir , items ):
6485 return [
6586 "" ,
@@ -146,7 +167,7 @@ def _wait(timeout=30, step=0.5):
146167
147168
148169@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 ):
150171 config_file = temp_dir / "python-gitlab.cfg"
151172 port = docker_services .port_for ("gitlab" , 80 )
152173
@@ -163,13 +184,15 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir):
163184 f"GitLab container is now ready after { minutes } minute(s), { seconds } seconds"
164185 )
165186
187+ token = set_token ("gitlab-test" , fixture_dir = fixture_dir )
188+
166189 config = f"""[global]
167190default = local
168191timeout = 60
169192
170193[local]
171194url = http://{ docker_ip } :{ port }
172- private_token = python-gitlab- token
195+ private_token = { token }
173196api_version = 4"""
174197
175198 with open (config_file , "w" , encoding = "utf-8" ) as f :
0 commit comments