|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ce/api/pull_mirror.html |
| 3 | +""" |
| 4 | + |
| 5 | +importpytest |
| 6 | +importresponses |
| 7 | + |
| 8 | +fromgitlab.v4.objectsimportProjectPullMirror |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +defresp_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 | +withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps: |
| 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 | +yieldrsps |
| 51 | + |
| 52 | + |
| 53 | +deftest_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 | +assertmirror.enabled |
| 58 | + |
| 59 | + |
| 60 | +deftest_start_project_pull_mirror(project,resp_pull_mirror): |
| 61 | +project.pull_mirror.start() |
| 62 | + |
| 63 | + |
| 64 | +deftest_get_project_pull_mirror(project,resp_pull_mirror): |
| 65 | +mirror=project.pull_mirror.get() |
| 66 | +assertisinstance(mirror,ProjectPullMirror) |
| 67 | +assertmirror.enabled |