diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-07 00:55:33 +0200 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-07 00:55:33 +0200 |
commit | 4cfaa2fd44b64459f6fc268a91d4469284c0e768 (patch) | |
tree | c89e1641af92580c6e7435dd3847b58e7b9ce19e /gitlab/tests | |
parent | c161852b5a976d11f682c5af00ff3f4e8daa26ef (diff) | |
download | gitlab-4cfaa2fd44b64459f6fc268a91d4469284c0e768.tar.gz |
feat(api): add support for remote mirrors API (#1056)feat/project-remote-mirrors
Diffstat (limited to 'gitlab/tests')
-rw-r--r-- | gitlab/tests/objects/test_projects.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_projects.py b/gitlab/tests/objects/test_projects.py index 1c2347a..48347f9 100644 --- a/gitlab/tests/objects/test_projects.py +++ b/gitlab/tests/objects/test_projects.py @@ -90,6 +90,77 @@ def resp_import_github(url, request): return response(200, content, headers, None, 25, request) +@urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/1/remote_mirrors", + method="get", +) +def resp_get_remote_mirrors(url, request): + """Mock for Project Remote Mirrors GET response.""" + content = """[ + { + "enabled": true, + "id": 101486, + "last_error": null, + "last_successful_update_at": "2020-01-06T17:32:02.823Z", + "last_update_at": "2020-01-06T17:32:02.823Z", + "last_update_started_at": "2020-01-06T17:31:55.864Z", + "only_protected_branches": true, + "update_status": "finished", + "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git" + } + ]""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + +@urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/1/remote_mirrors", + method="post", +) +def resp_create_remote_mirror(url, request): + """Mock for Project Remote Mirrors POST response.""" + content = """{ + "enabled": false, + "id": 101486, + "last_error": null, + "last_successful_update_at": null, + "last_update_at": null, + "last_update_started_at": null, + "only_protected_branches": false, + "update_status": "none", + "url": "https://*****:*****@example.com/gitlab/example.git" + }""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + +@urlmatch( + scheme="http", + netloc="localhost", + path="/api/v4/projects/1/remote_mirrors/1", + method="put", +) +def resp_update_remote_mirror(url, request): + """Mock for Project Remote Mirrors PUT response.""" + content = """{ + "enabled": false, + "id": 101486, + "last_error": null, + "last_successful_update_at": "2020-01-06T17:32:02.823Z", + "last_update_at": "2020-01-06T17:32:02.823Z", + "last_update_started_at": "2020-01-06T17:31:55.864Z", + "only_protected_branches": true, + "update_status": "finished", + "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git" + }""" + content = content.encode("utf-8") + return response(200, content, headers, None, 5, request) + + class TestProject(unittest.TestCase): """Base class for GitLab Project tests.""" @@ -262,3 +333,26 @@ class TestProjectImport(TestProject): self.assertEqual(ret["name"], name) self.assertEqual(ret["full_path"], "/".join((base_path, name))) self.assertTrue(ret["full_name"].endswith(name)) + + +class TestProjectRemoteMirrors(TestProject): + @with_httmock(resp_get_remote_mirrors) + def test_list_project_remote_mirrors(self): + mirrors = self.project.remote_mirrors.list() + self.assertIsInstance(mirrors, list) + self.assertIsInstance(mirrors[0], ProjectRemoteMirror) + self.assertTrue(mirrors[0].enabled) + + @with_httmock(resp_create_remote_mirror) + def test_create_project_remote_mirror(self): + mirror = self.project.remote_mirrors.create({"url": "https://example.com"}) + self.assertIsInstance(mirror, ProjectRemoteMirror) + self.assertEqual(mirror.update_status, "none") + + @with_httmock(resp_create_remote_mirror, resp_update_remote_mirror) + def test_update_project_remote_mirror(self): + mirror = self.project.remote_mirrors.create({"url": "https://example.com"}) + mirror.only_protected_branches = True + mirror.save() + self.assertEqual(mirror.update_status, "finished") + self.assertTrue(mirror.only_protected_branches) |