@@ -145,3 +145,72 @@ def resp_post(url, request):
145
145
self .assertIsInstance (fake_obj , FakeObject )
146
146
self .assertEqual (fake_obj .id , 1 )
147
147
self .assertEqual (fake_obj .name , "fake_name" )
148
+
149
+ def test_project_manager_owned (self ):
150
+ mgr = ProjectManager (self .gitlab )
151
+
152
+ @urlmatch (scheme = "http" , netloc = "localhost" ,
153
+ path = "/api/v3/projects/owned" , method = "get" )
154
+ def resp_get_all (url , request ):
155
+ headers = {'content-type' : 'application/json' }
156
+ content = ('[{"name": "name1", "id": 1}, '
157
+ '{"name": "name2", "id": 2}]' )
158
+ content = content .encode ("utf-8" )
159
+ return response (200 , content , headers , None , 5 , request )
160
+
161
+ with HTTMock (resp_get_all ):
162
+ data = mgr .owned ()
163
+ self .assertEqual (type (data ), list )
164
+ self .assertEqual (2 , len (data ))
165
+ self .assertEqual (type (data [0 ]), Project )
166
+ self .assertEqual (type (data [1 ]), Project )
167
+ self .assertEqual (data [0 ].name , "name1" )
168
+ self .assertEqual (data [1 ].name , "name2" )
169
+ self .assertEqual (data [0 ].id , 1 )
170
+ self .assertEqual (data [1 ].id , 2 )
171
+
172
+ def test_project_manager_all (self ):
173
+ mgr = ProjectManager (self .gitlab )
174
+
175
+ @urlmatch (scheme = "http" , netloc = "localhost" ,
176
+ path = "/api/v3/projects/all" , method = "get" )
177
+ def resp_get_all (url , request ):
178
+ headers = {'content-type' : 'application/json' }
179
+ content = ('[{"name": "name1", "id": 1}, '
180
+ '{"name": "name2", "id": 2}]' )
181
+ content = content .encode ("utf-8" )
182
+ return response (200 , content , headers , None , 5 , request )
183
+
184
+ with HTTMock (resp_get_all ):
185
+ data = mgr .all ()
186
+ self .assertEqual (type (data ), list )
187
+ self .assertEqual (2 , len (data ))
188
+ self .assertEqual (type (data [0 ]), Project )
189
+ self .assertEqual (type (data [1 ]), Project )
190
+ self .assertEqual (data [0 ].name , "name1" )
191
+ self .assertEqual (data [1 ].name , "name2" )
192
+ self .assertEqual (data [0 ].id , 1 )
193
+ self .assertEqual (data [1 ].id , 2 )
194
+
195
+ def test_project_manager_search (self ):
196
+ mgr = ProjectManager (self .gitlab )
197
+
198
+ @urlmatch (scheme = "http" , netloc = "localhost" ,
199
+ path = "/api/v3/projects/search/foo" , method = "get" )
200
+ def resp_get_all (url , request ):
201
+ headers = {'content-type' : 'application/json' }
202
+ content = ('[{"name": "foo1", "id": 1}, '
203
+ '{"name": "foo2", "id": 2}]' )
204
+ content = content .encode ("utf-8" )
205
+ return response (200 , content , headers , None , 5 , request )
206
+
207
+ with HTTMock (resp_get_all ):
208
+ data = mgr .search ('foo' )
209
+ self .assertEqual (type (data ), list )
210
+ self .assertEqual (2 , len (data ))
211
+ self .assertEqual (type (data [0 ]), Project )
212
+ self .assertEqual (type (data [1 ]), Project )
213
+ self .assertEqual (data [0 ].name , "foo1" )
214
+ self .assertEqual (data [1 ].name , "foo2" )
215
+ self .assertEqual (data [0 ].id , 1 )
216
+ self .assertEqual (data [1 ].id , 2 )
0 commit comments