44from io import BytesIO
55from zipfile import is_zipfile
66
7+ import pytest
8+
79content = textwrap .dedent (
810"""\
911 test-artifact:
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 ):
2427project .files .create (data )
2528
2629jobs = None
2730while not jobs :
28- jobs = project .jobs .list (scope = "success" )
2931time .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 ):
3238cmd = [
3339"gitlab" ,
3440"--config-file" ,
3541gitlab_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
4450with capsysbinary .disabled ():
@@ -47,3 +53,93 @@ def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project):
4753
4854artifacts_zip = BytesIO (artifacts )
4955assert 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 "