|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ce/api/pull_mirror.html |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import responses |
| 7 | + |
| 8 | +from gitlab.v4.objects import ProjectPullMirror |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def resp_pull_mirror(): |
| 13 | + content = { |
| 14 | + "update_status": "none", |
| 15 | + "url": "https://gitlab.example.com/root/mirror.git", |
| 16 | + "last_error": None, |
| 17 | + "last_update_at": "2024-12-03T08:01:05.466Z", |
| 18 | + "last_update_started_at": "2024-12-03T08:01:05.342Z", |
| 19 | + "last_successful_update_at": None, |
| 20 | + "enabled": True, |
| 21 | + "mirror_trigger_builds": False, |
| 22 | + "only_mirror_protected_branches": None, |
| 23 | + "mirror_overwrites_diverged_branches": None, |
| 24 | + "mirror_branch_regex": None, |
| 25 | + } |
| 26 | + |
| 27 | + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: |
| 28 | + rsps.add( |
| 29 | + method=responses.PUT, |
| 30 | + url="http://localhost/api/v4/projects/1/mirror/pull", |
| 31 | + json=content, |
| 32 | + content_type="application/json", |
| 33 | + status=200, |
| 34 | + ) |
| 35 | + |
| 36 | + rsps.add( |
| 37 | + method=responses.POST, |
| 38 | + url="http://localhost/api/v4/projects/1/mirror/pull", |
| 39 | + status=200, |
| 40 | + ) |
| 41 | + |
| 42 | + rsps.add( |
| 43 | + method=responses.GET, |
| 44 | + url="http://localhost/api/v4/projects/1/mirror/pull", |
| 45 | + json=content, |
| 46 | + content_type="application/json", |
| 47 | + status=200, |
| 48 | + ) |
| 49 | + |
| 50 | + yield rsps |
| 51 | + |
| 52 | + |
| 53 | +def test_create_project_pull_mirror(project, resp_pull_mirror): |
| 54 | + mirror = project.pull_mirror.create( |
| 55 | + {"url": "https://gitlab.example.com/root/mirror.git"} |
| 56 | + ) |
| 57 | + assert mirror.enabled |
| 58 | + |
| 59 | + |
| 60 | +def test_start_project_pull_mirror(project, resp_pull_mirror): |
| 61 | + project.pull_mirror.start() |
| 62 | + |
| 63 | + |
| 64 | +def test_get_project_pull_mirror(project, resp_pull_mirror): |
| 65 | + mirror = project.pull_mirror.get() |
| 66 | + assert isinstance(mirror, ProjectPullMirror) |
| 67 | + assert mirror.enabled |
0 commit comments