1- import time
21import tempfile
2+ import time
3+ import uuid
34from pathlib import Path
45from random import randint
56from subprocess import check_output
1314TEST_DIR = Path (__file__ ).resolve ().parent
1415
1516
16- def random_id ():
17- """
18- Helper to ensure new resource creation does not clash with
19- existing resources, for example when a previous test deleted a
20- resource but GitLab is still deleting it asynchronously in the
21- background. TODO: Expand to make it 100% safe.
22- """
23- return randint (9 ,9999 )
24-
25-
2617def reset_gitlab (gl ):
2718# previously tools/reset_gitlab.py
2819for project in gl .projects .list ():
@@ -125,7 +116,7 @@ def gl(gitlab_config):
125116@pytest .fixture (scope = "module" )
126117def group (gl ):
127118"""Group fixture for group API resource tests."""
128- _id = random_id ()
119+ _id = uuid . uuid4 (). hex
129120data = {
130121"name" :f"test-group-{ _id } " ,
131122"path" :f"group-{ _id } " ,
@@ -143,7 +134,7 @@ def group(gl):
143134@pytest .fixture (scope = "module" )
144135def project (gl ):
145136"""Project fixture for project API resource tests."""
146- _id = random_id ()
137+ _id = uuid . uuid4 (). hex
147138name = f"test-project-{ _id } "
148139
149140project = gl .projects .create (name = name )
@@ -159,7 +150,7 @@ def project(gl):
159150@pytest .fixture (scope = "module" )
160151def user (gl ):
161152"""User fixture for user API resource tests."""
162- _id = random_id ()
153+ _id = uuid . uuid4 (). hex
163154email = f"user{ _id } @email.com"
164155username = f"user{ _id } "
165156name = f"User{ _id } "
@@ -178,7 +169,7 @@ def user(gl):
178169@pytest .fixture (scope = "module" )
179170def issue (project ):
180171"""Issue fixture for issue API resource tests."""
181- _id = random_id ()
172+ _id = uuid . uuid4 (). hex
182173data = {"title" :f"Issue{ _id } " ,"description" :f"Issue{ _id } description" }
183174
184175return project .issues .create (data )
@@ -187,7 +178,7 @@ def issue(project):
187178@pytest .fixture (scope = "module" )
188179def label (project ):
189180"""Label fixture for project label API resource tests."""
190- _id = random_id ()
181+ _id = uuid . uuid4 (). hex
191182data = {
192183"name" :f"prjlabel{ _id } " ,
193184"description" :f"prjlabel1{ _id } description" ,
@@ -200,7 +191,7 @@ def label(project):
200191@pytest .fixture (scope = "module" )
201192def group_label (group ):
202193"""Label fixture for group label API resource tests."""
203- _id = random_id ()
194+ _id = uuid . uuid4 (). hex
204195data = {
205196"name" :f"grplabel{ _id } " ,
206197"description" :f"grplabel1{ _id } description" ,
@@ -213,7 +204,7 @@ def group_label(group):
213204@pytest .fixture (scope = "module" )
214205def variable (project ):
215206"""Variable fixture for project variable API resource tests."""
216- _id = random_id ()
207+ _id = uuid . uuid4 (). hex
217208data = {"key" :f"var{ _id } " ,"value" :f"Variable{ _id } " }
218209
219210return project .variables .create (data )
@@ -222,7 +213,7 @@ def variable(project):
222213@pytest .fixture (scope = "module" )
223214def deploy_token (project ):
224215"""Deploy token fixture for project deploy token API resource tests."""
225- _id = random_id ()
216+ _id = uuid . uuid4 (). hex
226217data = {
227218"name" :f"token-{ _id } " ,
228219"username" :"root" ,
@@ -236,7 +227,7 @@ def deploy_token(project):
236227@pytest .fixture (scope = "module" )
237228def group_deploy_token (group ):
238229"""Deploy token fixture for group deploy token API resource tests."""
239- _id = random_id ()
230+ _id = uuid . uuid4 (). hex
240231data = {
241232"name" :f"group-token-{ _id } " ,
242233"username" :"root" ,