Skip to content

Commit ff9e76c

Browse files
committed
test: add api integration test for ci_cd_token allowlist
Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk>
1 parent 9596e09 commit ff9e76c

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

gitlab/v4/objects/job_token_scope.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
)
1515
from gitlab.types import RequiredOptional
1616

17-
1817
__all__ = [
1918
"ProjectJobTokenScope",
2019
"ProjectJobTokenScopeManager",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def test_add_project_to_job_token_scope_allowlist(gl, project):
2+
project_to_add = gl.projects.create({"name": "Ci_Cd_token_add_proj"})
3+
4+
resp = project.job_token_scope.allowlist.create(
5+
{"target_project_id": project_to_add.id}
6+
)
7+
8+
assert resp.source_project_id == project.id
9+
assert resp.target_project_id == project_to_add.id
10+
11+
project_to_add.delete()
12+
13+
14+
def test_projects_job_token_scope_allowlist_contains_added_project_name(gl, project):
15+
allowlist = project.job_token_scope.allowlist.list()
16+
assert len(allowlist) == 0
17+
18+
project_name = "Ci_Cd_token_named_proj"
19+
project_to_add = gl.projects.create({"name": project_name})
20+
project.allowlist.create({"target_project_id": project_to_add.id})
21+
22+
allowlist = project.allowlist.list()
23+
assert any(allowed.name == project_name for allowed in allowlist)
24+
25+
project_to_add.delete()
26+
27+
28+
def test_remove_project_by_id_from_projects_job_token_scope_allowlist(gl, project):
29+
allowlist = project.job_token_scope.allowlist.list()
30+
assert len(allowlist) == 0
31+
32+
project_to_add = gl.projects.create({"name": "Ci_Cd_token_remove_proj"})
33+
34+
project.allowlist.create({"target_project_id": project_to_add.id})
35+
36+
allowlist = project.allowlist.list()
37+
assert len(allowlist) != 0
38+
39+
project.allowlist.remove(project_to_add.id)
40+
41+
allowlist = project.allowlist.list()
42+
assert len(allowlist) == 0
43+
44+
project_to_add.delete()

0 commit comments

Comments
 (0)