1515binary_content = b"binary content"
1616
1717
18+ @urlmatch (
19+ scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/export" , method = "post" ,
20+ )
21+ def resp_create_export (url , request ):
22+ """Common mock for Project Export tests."""
23+ content = """{
24+ "message": "202 Accepted"
25+ }"""
26+ content = content .encode ("utf-8" )
27+ return response (202 , content , headers , None , 25 , request )
28+
29+
30+ @urlmatch (
31+ scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/export" , method = "get" ,
32+ )
33+ def resp_export_status (url , request ):
34+ """Mock for Project Export GET response."""
35+ content = """{
36+ "id": 1,
37+ "description": "Itaque perspiciatis minima aspernatur",
38+ "name": "Gitlab Test",
39+ "name_with_namespace": "Gitlab Org / Gitlab Test",
40+ "path": "gitlab-test",
41+ "path_with_namespace": "gitlab-org/gitlab-test",
42+ "created_at": "2017-08-29T04:36:44.383Z",
43+ "export_status": "finished",
44+ "_links": {
45+ "api_url": "https://gitlab.test/api/v4/projects/1/export/download",
46+ "web_url": "https://gitlab.test/gitlab-test/download_export"
47+ }
48+ }
49+ """
50+ content = content .encode ("utf-8" )
51+ return response (200 , content , headers , None , 25 , request )
52+
53+
54+ @urlmatch (
55+ scheme = "http" ,
56+ netloc = "localhost" ,
57+ path = "/api/v4/projects/1/export/download" ,
58+ method = "get" ,
59+ )
60+ def resp_download_export (url , request ):
61+ """Mock for Project Export Download GET response."""
62+ headers = {"content-type" : "application/octet-stream" }
63+ content = binary_content
64+ return response (200 , content , headers , None , 25 , request )
65+
66+
67+ @urlmatch (
68+ scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/import" , method = "post" ,
69+ )
70+ def resp_import_project (url , request ):
71+ """Mock for Project Import POST response."""
72+ content = """{
73+ "id": 1,
74+ "description": null,
75+ "name": "api-project",
76+ "name_with_namespace": "Administrator / api-project",
77+ "path": "api-project",
78+ "path_with_namespace": "root/api-project",
79+ "created_at": "2018-02-13T09:05:58.023Z",
80+ "import_status": "scheduled"
81+ }"""
82+ content = content .encode ("utf-8" )
83+ return response (200 , content , headers , None , 25 , request )
84+
85+
86+ @urlmatch (
87+ scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/import" , method = "get" ,
88+ )
89+ def resp_import_status (url , request ):
90+ """Mock for Project Import GET response."""
91+ content = """{
92+ "id": 1,
93+ "description": "Itaque perspiciatis minima aspernatur corporis consequatur.",
94+ "name": "Gitlab Test",
95+ "name_with_namespace": "Gitlab Org / Gitlab Test",
96+ "path": "gitlab-test",
97+ "path_with_namespace": "gitlab-org/gitlab-test",
98+ "created_at": "2017-08-29T04:36:44.383Z",
99+ "import_status": "finished"
100+ }"""
101+ content = content .encode ("utf-8" )
102+ return response (200 , content , headers , None , 25 , request )
103+
104+
105+ @urlmatch (
106+ scheme = "http" , netloc = "localhost" , path = "/api/v4/import/github" , method = "post" ,
107+ )
108+ def resp_import_github (url , request ):
109+ """Mock for GitHub Project Import POST response."""
110+ content = """{
111+ "id": 27,
112+ "name": "my-repo",
113+ "full_path": "/root/my-repo",
114+ "full_name": "Administrator / my-repo"
115+ }"""
116+ content = content .encode ("utf-8" )
117+ return response (200 , content , headers , None , 25 , request )
118+
119+
18120class TestProject (unittest .TestCase ):
19121 """Base class for GitLab Project tests."""
20122
@@ -146,54 +248,6 @@ def resp_create_snippet(url, request):
146248 self .assertEqual (snippet .visibility , visibility )
147249
148250
149- @urlmatch (
150- scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/export" , method = "post" ,
151- )
152- def resp_create_export (url , request ):
153- """Common mock for Project Export tests."""
154- content = """{
155- "message": "202 Accepted"
156- }"""
157- content = content .encode ("utf-8" )
158- return response (202 , content , headers , None , 25 , request )
159-
160-
161- @urlmatch (
162- scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/export" , method = "get" ,
163- )
164- def resp_export_status (url , request ):
165- """Mock for Project Export GET response."""
166- content = """{
167- "id": 1,
168- "description": "Itaque perspiciatis minima aspernatur",
169- "name": "Gitlab Test",
170- "name_with_namespace": "Gitlab Org / Gitlab Test",
171- "path": "gitlab-test",
172- "path_with_namespace": "gitlab-org/gitlab-test",
173- "created_at": "2017-08-29T04:36:44.383Z",
174- "export_status": "finished",
175- "_links": {
176- "api_url": "https://gitlab.test/api/v4/projects/1/export/download",
177- "web_url": "https://gitlab.test/gitlab-test/download_export"
178- }
179- }
180- """
181- content = content .encode ("utf-8" )
182- return response (200 , content , headers , None , 25 , request )
183-
184-
185- @urlmatch (
186- scheme = "http" ,
187- netloc = "localhost" ,
188- path = "/api/v4/projects/1/export/download" ,
189- method = "get" ,
190- )
191- def resp_download_export (url , request ):
192- headers = {"content-type" : "application/octet-stream" }
193- content = binary_content
194- return response (200 , content , headers , None , 25 , request )
195-
196-
197251class TestProjectExport (TestProject ):
198252 @with_httmock (resp_create_export )
199253 def test_create_project_export (self ):
@@ -214,58 +268,6 @@ def test_download_project_export(self):
214268 self .assertEqual (download , binary_content )
215269
216270
217- @urlmatch (
218- scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/import" , method = "post" ,
219- )
220- def resp_import_project (url , request ):
221- """Mock for Project Import POST response."""
222- content = """{
223- "id": 1,
224- "description": null,
225- "name": "api-project",
226- "name_with_namespace": "Administrator / api-project",
227- "path": "api-project",
228- "path_with_namespace": "root/api-project",
229- "created_at": "2018-02-13T09:05:58.023Z",
230- "import_status": "scheduled"
231- }"""
232- content = content .encode ("utf-8" )
233- return response (200 , content , headers , None , 25 , request )
234-
235-
236- @urlmatch (
237- scheme = "http" , netloc = "localhost" , path = "/api/v4/projects/1/import" , method = "get" ,
238- )
239- def resp_import_status (url , request ):
240- """Mock for Project Import GET response."""
241- content = """{
242- "id": 1,
243- "description": "Itaque perspiciatis minima aspernatur corporis consequatur.",
244- "name": "Gitlab Test",
245- "name_with_namespace": "Gitlab Org / Gitlab Test",
246- "path": "gitlab-test",
247- "path_with_namespace": "gitlab-org/gitlab-test",
248- "created_at": "2017-08-29T04:36:44.383Z",
249- "import_status": "finished"
250- }"""
251- content = content .encode ("utf-8" )
252- return response (200 , content , headers , None , 25 , request )
253-
254-
255- @urlmatch (
256- scheme = "http" , netloc = "localhost" , path = "/api/v4/import/github" , method = "post" ,
257- )
258- def resp_import_github (url , request ):
259- content = """{
260- "id": 27,
261- "name": "my-repo",
262- "full_path": "/root/my-repo",
263- "full_name": "Administrator / my-repo"
264- }"""
265- content = content .encode ("utf-8" )
266- return response (200 , content , headers , None , 25 , request )
267-
268-
269271class TestProjectImport (TestProject ):
270272 @with_httmock (resp_import_project )
271273 def test_import_project (self ):
0 commit comments