File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 2626
2727import six
2828
29+ import gitlab
2930from gitlab .exceptions import * # noqa
3031
3132
3233class jsonEncoder (json .JSONEncoder ):
3334 def default (self , obj ):
34- from gitlab import Gitlab
3535 if isinstance (obj , GitlabObject ):
36- return {k : v for k , v in obj .__dict__ .iteritems ()
37- if not isinstance (v , BaseManager )}
38- elif isinstance (obj , Gitlab ):
36+ return {k : v for k , v in six .iteritems (obj .__dict__ )
37+ if (not isinstance (v , BaseManager )
38+ and not k [0 ] == '_' )}
39+ elif isinstance (obj , gitlab .Gitlab ):
3940 return {'url' : obj ._url }
4041 return json .JSONEncoder .default (self , obj )
4142
Original file line number Diff line number Diff line change 2121from __future__ import division
2222from __future__ import absolute_import
2323
24+ import json
2425try :
2526 import unittest
2627except ImportError :
@@ -150,6 +151,14 @@ def setUp(self):
150151 email = "testuser@test.com" , password = "testpassword" ,
151152 ssl_verify = True )
152153
154+ def test_json (self ):
155+ gl_object = CurrentUser (self .gl , data = {"username" : "testname" })
156+ json_str = gl_object .json ()
157+ data = json .loads (json_str )
158+ self .assertIn ("id" , data )
159+ self .assertEqual (data ["username" ], "testname" )
160+ self .assertEqual (data ["gitlab" ]["url" ], "http://localhost/api/v3" )
161+
153162 def test_list_not_implemented (self ):
154163 self .assertRaises (NotImplementedError , CurrentUser .list , self .gl )
155164
You can’t perform that action at this time.
0 commit comments