@@ -90,6 +90,77 @@ def resp_import_github(url, request):
9090 return response (200 , content , headers , None , 25 , request )
9191
9292
93+ @urlmatch (
94+ scheme = "http" ,
95+ netloc = "localhost" ,
96+ path = "/api/v4/projects/1/remote_mirrors" ,
97+ method = "get" ,
98+ )
99+ def resp_get_remote_mirrors (url , request ):
100+ """Mock for Project Remote Mirrors GET response."""
101+ content = """[
102+ {
103+ "enabled": true,
104+ "id": 101486,
105+ "last_error": null,
106+ "last_successful_update_at": "2020-01-06T17:32:02.823Z",
107+ "last_update_at": "2020-01-06T17:32:02.823Z",
108+ "last_update_started_at": "2020-01-06T17:31:55.864Z",
109+ "only_protected_branches": true,
110+ "update_status": "finished",
111+ "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
112+ }
113+ ]"""
114+ content = content .encode ("utf-8" )
115+ return response (200 , content , headers , None , 5 , request )
116+
117+
118+ @urlmatch (
119+ scheme = "http" ,
120+ netloc = "localhost" ,
121+ path = "/api/v4/projects/1/remote_mirrors" ,
122+ method = "post" ,
123+ )
124+ def resp_create_remote_mirror (url , request ):
125+ """Mock for Project Remote Mirrors POST response."""
126+ content = """{
127+ "enabled": false,
128+ "id": 101486,
129+ "last_error": null,
130+ "last_successful_update_at": null,
131+ "last_update_at": null,
132+ "last_update_started_at": null,
133+ "only_protected_branches": false,
134+ "update_status": "none",
135+ "url": "https://*****:*****@example.com/gitlab/example.git"
136+ }"""
137+ content = content .encode ("utf-8" )
138+ return response (200 , content , headers , None , 5 , request )
139+
140+
141+ @urlmatch (
142+ scheme = "http" ,
143+ netloc = "localhost" ,
144+ path = "/api/v4/projects/1/remote_mirrors/1" ,
145+ method = "put" ,
146+ )
147+ def resp_update_remote_mirror (url , request ):
148+ """Mock for Project Remote Mirrors PUT response."""
149+ content = """{
150+ "enabled": false,
151+ "id": 101486,
152+ "last_error": null,
153+ "last_successful_update_at": "2020-01-06T17:32:02.823Z",
154+ "last_update_at": "2020-01-06T17:32:02.823Z",
155+ "last_update_started_at": "2020-01-06T17:31:55.864Z",
156+ "only_protected_branches": true,
157+ "update_status": "finished",
158+ "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
159+ }"""
160+ content = content .encode ("utf-8" )
161+ return response (200 , content , headers , None , 5 , request )
162+
163+
93164class TestProject (unittest .TestCase ):
94165 """Base class for GitLab Project tests."""
95166
@@ -262,3 +333,26 @@ def test_import_github(self):
262333 self .assertEqual (ret ["name" ], name )
263334 self .assertEqual (ret ["full_path" ], "/" .join ((base_path , name )))
264335 self .assertTrue (ret ["full_name" ].endswith (name ))
336+
337+
338+ class TestProjectRemoteMirrors (TestProject ):
339+ @with_httmock (resp_get_remote_mirrors )
340+ def test_list_project_remote_mirrors (self ):
341+ mirrors = self .project .remote_mirrors .list ()
342+ self .assertIsInstance (mirrors , list )
343+ self .assertIsInstance (mirrors [0 ], ProjectRemoteMirror )
344+ self .assertTrue (mirrors [0 ].enabled )
345+
346+ @with_httmock (resp_create_remote_mirror )
347+ def test_create_project_remote_mirror (self ):
348+ mirror = self .project .remote_mirrors .create ({"url" : "https://example.com" })
349+ self .assertIsInstance (mirror , ProjectRemoteMirror )
350+ self .assertEqual (mirror .update_status , "none" )
351+
352+ @with_httmock (resp_create_remote_mirror , resp_update_remote_mirror )
353+ def test_update_project_remote_mirror (self ):
354+ mirror = self .project .remote_mirrors .create ({"url" : "https://example.com" })
355+ mirror .only_protected_branches = True
356+ mirror .save ()
357+ self .assertEqual (mirror .update_status , "finished" )
358+ self .assertTrue (mirror .only_protected_branches )
0 commit comments