@@ -258,6 +258,32 @@ def resp_get_search(url, request):
258258 self .assertEqual (data [0 ].id , 1 )
259259 self .assertEqual (data [1 ].id , 2 )
260260
261+ def test_user_manager_get_by_username (self ):
262+ mgr = UserManager (self .gitlab )
263+
264+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v3/users" ,
265+ query = "username=foo" , method = "get" )
266+ def resp_get_username (url , request ):
267+ headers = {'content-type' : 'application/json' }
268+ content = '[{"name": "foo", "id": 1}]' .encode ("utf-8" )
269+ return response (200 , content , headers , None , 5 , request )
270+
271+ with HTTMock (resp_get_username ):
272+ data = mgr .get_by_username ('foo' )
273+ self .assertEqual (type (data ), User )
274+ self .assertEqual (data .name , "foo" )
275+ self .assertEqual (data .id , 1 )
276+
277+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v3/users" ,
278+ query = "username=foo" , method = "get" )
279+ def resp_get_username_nomatch (url , request ):
280+ headers = {'content-type' : 'application/json' }
281+ content = '[]' .encode ("utf-8" )
282+ return response (200 , content , headers , None , 5 , request )
283+
284+ with HTTMock (resp_get_username_nomatch ):
285+ self .assertRaises (GitlabGetError , mgr .get_by_username , 'foo' )
286+
261287 def test_group_manager_search (self ):
262288 mgr = GroupManager (self .gitlab )
263289
0 commit comments