Skip to content

Commit 8ce0336

Browse files
nejchJohnVillalovos
authored andcommitted
test(objects): add tests for project artifacts
1 parent c8c2fa7 commit 8ce0336

File tree

2 files changed

+114
-7
lines changed

2 files changed

+114
-7
lines changed

tests/functional/cli/test_cli_artifacts.py

+101-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from io import BytesIO
55
from zipfile import is_zipfile
66

7+
import pytest
8+
79
content = textwrap.dedent(
810
"""\
911
test-artifact:
@@ -20,25 +22,29 @@
2022
}
2123

2224

23-
def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project):
25+
@pytest.fixture(scope="module")
26+
def job_with_artifacts(gitlab_runner, project):
2427
project.files.create(data)
2528

2629
jobs = None
2730
while not jobs:
28-
jobs = project.jobs.list(scope="success")
2931
time.sleep(0.5)
32+
jobs = project.jobs.list(scope="success")
3033

31-
job = project.jobs.get(jobs[0].id)
34+
return project.jobs.get(jobs[0].id)
35+
36+
37+
def test_cli_job_artifacts(capsysbinary, gitlab_config, job_with_artifacts):
3238
cmd = [
3339
"gitlab",
3440
"--config-file",
3541
gitlab_config,
3642
"project-job",
3743
"artifacts",
3844
"--id",
39-
str(job.id),
45+
str(job_with_artifacts.id),
4046
"--project-id",
41-
str(project.id),
47+
str(job_with_artifacts.pipeline["project_id"]),
4248
]
4349

4450
with capsysbinary.disabled():
@@ -47,3 +53,93 @@ def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project):
4753

4854
artifacts_zip = BytesIO(artifacts)
4955
assert is_zipfile(artifacts_zip)
56+
57+
58+
def test_cli_project_artifact_download(gitlab_config, job_with_artifacts):
59+
cmd = [
60+
"gitlab",
61+
"--config-file",
62+
gitlab_config,
63+
"project-artifact",
64+
"download",
65+
"--project-id",
66+
str(job_with_artifacts.pipeline["project_id"]),
67+
"--ref-name",
68+
job_with_artifacts.ref,
69+
"--job",
70+
job_with_artifacts.name,
71+
]
72+
73+
artifacts = subprocess.run(cmd, capture_output=True, check=True)
74+
assert isinstance(artifacts.stdout, bytes)
75+
76+
artifacts_zip = BytesIO(artifacts.stdout)
77+
assert is_zipfile(artifacts_zip)
78+
79+
80+
def test_cli_project_artifacts_warns_deprecated(gitlab_config, job_with_artifacts):
81+
cmd = [
82+
"gitlab",
83+
"--config-file",
84+
gitlab_config,
85+
"project",
86+
"artifacts",
87+
"--id",
88+
str(job_with_artifacts.pipeline["project_id"]),
89+
"--ref-name",
90+
job_with_artifacts.ref,
91+
"--job",
92+
job_with_artifacts.name,
93+
]
94+
95+
artifacts = subprocess.run(cmd, capture_output=True, check=True)
96+
assert isinstance(artifacts.stdout, bytes)
97+
assert b"DeprecationWarning" in artifacts.stderr
98+
99+
artifacts_zip = BytesIO(artifacts.stdout)
100+
assert is_zipfile(artifacts_zip)
101+
102+
103+
def test_cli_project_artifact_raw(gitlab_config, job_with_artifacts):
104+
cmd = [
105+
"gitlab",
106+
"--config-file",
107+
gitlab_config,
108+
"project-artifact",
109+
"raw",
110+
"--project-id",
111+
str(job_with_artifacts.pipeline["project_id"]),
112+
"--ref-name",
113+
job_with_artifacts.ref,
114+
"--job",
115+
job_with_artifacts.name,
116+
"--artifact-path",
117+
"artifact.txt",
118+
]
119+
120+
artifacts = subprocess.run(cmd, capture_output=True, check=True)
121+
assert isinstance(artifacts.stdout, bytes)
122+
assert artifacts.stdout == b"test\n"
123+
124+
125+
def test_cli_project_artifact_warns_deprecated(gitlab_config, job_with_artifacts):
126+
cmd = [
127+
"gitlab",
128+
"--config-file",
129+
gitlab_config,
130+
"project",
131+
"artifact",
132+
"--id",
133+
str(job_with_artifacts.pipeline["project_id"]),
134+
"--ref-name",
135+
job_with_artifacts.ref,
136+
"--job",
137+
job_with_artifacts.name,
138+
"--artifact-path",
139+
"artifact.txt",
140+
]
141+
142+
artifacts = subprocess.run(cmd, capture_output=True, check=True)
143+
assert isinstance(artifacts.stdout, bytes)
144+
assert b"DeprecationWarning" in artifacts.stderr
145+
assert artifacts.stdout == b"test\n"

tests/unit/objects/test_job_artifacts.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ def resp_artifacts_by_ref_name(binary_content):
2424
yield rsps
2525

2626

27-
def test_download_artifacts_by_ref_name(gl, binary_content, resp_artifacts_by_ref_name):
27+
def test_project_artifacts_download_by_ref_name(
28+
gl, binary_content, resp_artifacts_by_ref_name
29+
):
2830
project = gl.projects.get(1, lazy=True)
29-
artifacts = project.artifacts(ref_name=ref_name, job=job)
31+
artifacts = project.artifacts.download(ref_name=ref_name, job=job)
32+
assert artifacts == binary_content
33+
34+
35+
def test_project_artifacts_by_ref_name_warns(
36+
gl, binary_content, resp_artifacts_by_ref_name
37+
):
38+
project = gl.projects.get(1, lazy=True)
39+
with pytest.warns(DeprecationWarning):
40+
artifacts = project.artifacts(ref_name=ref_name, job=job)
3041
assert artifacts == binary_content

0 commit comments

Comments
 (0)