|
1 | 1 | import pytest |
2 | 2 | import responses |
3 | 3 |
|
4 | | -ci_lint_get_content = { |
| 4 | +gitlab_ci_yml = """--- |
| 5 | +:test_job: |
| 6 | + :script: echo 1 |
| 7 | +""" |
| 8 | + |
| 9 | +ci_lint_create_content = {"status": "valid", "errors": [], "warnings": []} |
| 10 | + |
| 11 | + |
| 12 | +project_ci_lint_content = { |
5 | 13 | "valid": True, |
6 | 14 | "merged_yaml": "---\n:test_job:\n :script: echo 1\n", |
7 | 15 | "errors": [], |
|
10 | 18 |
|
11 | 19 |
|
12 | 20 | @pytest.fixture |
13 | | -def resp_get_ci_lint(): |
| 21 | +def resp_create_ci_lint(): |
| 22 | + with responses.RequestsMock() as rsps: |
| 23 | + rsps.add( |
| 24 | + method=responses.POST, |
| 25 | + url="http://localhost/api/v4/ci/lint", |
| 26 | + json=ci_lint_create_content, |
| 27 | + content_type="application/json", |
| 28 | + status=200, |
| 29 | + ) |
| 30 | + yield rsps |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def resp_get_project_ci_lint(): |
14 | 35 | with responses.RequestsMock() as rsps: |
15 | 36 | rsps.add( |
16 | 37 | method=responses.GET, |
17 | 38 | url="http://localhost/api/v4/projects/1/ci/lint", |
18 | | - json=ci_lint_get_content, |
| 39 | + json=project_ci_lint_content, |
19 | 40 | content_type="application/json", |
20 | 41 | status=200, |
21 | 42 | ) |
22 | 43 | yield rsps |
23 | 44 |
|
24 | 45 |
|
25 | 46 | @pytest.fixture |
26 | | -def resp_create_ci_lint(): |
| 47 | +def resp_create_project_ci_lint(): |
27 | 48 | with responses.RequestsMock() as rsps: |
28 | 49 | rsps.add( |
29 | 50 | method=responses.POST, |
30 | 51 | url="http://localhost/api/v4/projects/1/ci/lint", |
31 | | - json=ci_lint_get_content, |
| 52 | + json=project_ci_lint_content, |
32 | 53 | content_type="application/json", |
33 | 54 | status=200, |
34 | 55 | ) |
35 | 56 | yield rsps |
36 | 57 |
|
37 | 58 |
|
38 | | -def test_project_ci_lint_get(project, resp_get_ci_lint): |
| 59 | +def test_ci_lint_create(gl, resp_create_ci_lint): |
| 60 | + lint_result = gl.ci_lint.create({"content": gitlab_ci_yml}) |
| 61 | + assert lint_result.status == "valid" |
| 62 | + |
| 63 | + |
| 64 | +def test_project_ci_lint_get(project, resp_get_project_ci_lint): |
39 | 65 | lint_result = project.ci_lint.get() |
40 | 66 | assert lint_result.valid is True |
41 | 67 |
|
42 | 68 |
|
43 | | -def test_project_ci_lint_create(project, resp_create_ci_lint): |
44 | | - gitlab_ci_yml = """--- |
45 | | -:test_job: |
46 | | - :script: echo 1 |
47 | | -""" |
| 69 | +def test_project_ci_lint_create(project, resp_create_project_ci_lint): |
48 | 70 | lint_result = project.ci_lint.create({"content": gitlab_ci_yml}) |
49 | 71 | assert lint_result.valid is True |
0 commit comments