forked from python-gitlab/python-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_artifacts.py
More file actions
99 lines (82 loc) · 2.33 KB
/
test_cli_artifacts.py
File metadata and controls
99 lines (82 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import subprocess
import textwrap
import time
from io import BytesIO
from zipfile import is_zipfile
import pytest
content = textwrap.dedent(
"""\
test-artifact:
script: echo "test" > artifact.txt
artifacts:
untracked: true
"""
)
data = {
"file_path": ".gitlab-ci.yml",
"branch": "main",
"content": content,
"commit_message": "Initial commit",
}
@pytest.fixture(scope="module")
def job_with_artifacts(gitlab_runner, project):
project.files.create(data)
jobs = None
while not jobs:
time.sleep(0.5)
jobs = project.jobs.list(scope="success")
return project.jobs.get(jobs[0].id)
def test_cli_job_artifacts(capsysbinary, gitlab_config, job_with_artifacts):
cmd = [
"gitlab",
"--config-file",
gitlab_config,
"project-job",
"artifacts",
"--id",
str(job_with_artifacts.id),
"--project-id",
str(job_with_artifacts.pipeline["project_id"]),
]
with capsysbinary.disabled():
artifacts = subprocess.check_output(cmd)
assert isinstance(artifacts, bytes)
artifacts_zip = BytesIO(artifacts)
assert is_zipfile(artifacts_zip)
def test_cli_project_artifact_download(gitlab_config, job_with_artifacts):
cmd = [
"gitlab",
"--config-file",
gitlab_config,
"project-artifact",
"download",
"--project-id",
str(job_with_artifacts.pipeline["project_id"]),
"--ref-name",
job_with_artifacts.ref,
"--job",
job_with_artifacts.name,
]
artifacts = subprocess.run(cmd, capture_output=True, check=True)
assert isinstance(artifacts.stdout, bytes)
artifacts_zip = BytesIO(artifacts.stdout)
assert is_zipfile(artifacts_zip)
def test_cli_project_artifact_raw(gitlab_config, job_with_artifacts):
cmd = [
"gitlab",
"--config-file",
gitlab_config,
"project-artifact",
"raw",
"--project-id",
str(job_with_artifacts.pipeline["project_id"]),
"--ref-name",
job_with_artifacts.ref,
"--job",
job_with_artifacts.name,
"--artifact-path",
"artifact.txt",
]
artifacts = subprocess.run(cmd, capture_output=True, check=True)
assert isinstance(artifacts.stdout, bytes)
assert artifacts.stdout == b"test\n"