| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c8c2fa7 commit 8ce0336
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ | |||
| 4 | 4 | from io import BytesIO | |
| 5 | 5 | from zipfile import is_zipfile | |
| 6 | 6 | ||
| 7 | + import pytest | ||
| 8 | + | ||
| 7 | 9 | content = textwrap.dedent( | |
| 8 | 10 | """\ | |
| 9 | 11 | test-artifact: | |
@@ -20,25 +22,29 @@ | |||
| 20 | 22 | } | |
| 21 | 23 | ||
| 22 | 24 | ||
| 23 | - def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project): | ||
| 25 | + @pytest.fixture(scope="module") | ||
| 26 | + def job_with_artifacts(gitlab_runner, project): | ||
| 24 | 27 | project.files.create(data) | |
| 25 | 28 | ||
| 26 | 29 | jobs = None | |
| 27 | 30 | while not jobs: | |
| 28 | - jobs = project.jobs.list(scope="success") | ||
| 29 | 31 | time.sleep(0.5) | |
| 32 | + jobs = project.jobs.list(scope="success") | ||
| 30 | 33 | ||
| 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): | ||
| 32 | 38 | cmd = [ | |
| 33 | 39 | "gitlab", | |
| 34 | 40 | "--config-file", | |
| 35 | 41 | gitlab_config, | |
| 36 | 42 | "project-job", | |
| 37 | 43 | "artifacts", | |
| 38 | 44 | "--id", | |
| 39 | - str(job.id), | ||
| 45 | + str(job_with_artifacts.id), | ||
| 40 | 46 | "--project-id", | |
| 41 | - str(project.id), | ||
| 47 | + str(job_with_artifacts.pipeline["project_id"]), | ||
| 42 | 48 | ] | |
| 43 | 49 | ||
| 44 | 50 | with capsysbinary.disabled(): | |
@@ -47,3 +53,93 @@ def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project): | |||
| 47 | 53 | ||
| 48 | 54 | artifacts_zip = BytesIO(artifacts) | |
| 49 | 55 | 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" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,18 @@ def resp_artifacts_by_ref_name(binary_content): | |||
| 24 | 24 | yield rsps | |
| 25 | 25 | ||
| 26 | 26 | ||
| 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 | + ): | ||
| 28 | 30 | 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) | ||
| 30 | 41 | assert artifacts == binary_content | |
| Back | FazBrowse Home | New Git URL |
0 commit comments