summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-23 16:48:39 +0100
committerGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-23 16:48:39 +0100
commitd7271b12e91c90ad7216073354085ed2b0257f73 (patch)
tree726ea8f4ea571f7ca5e61bb651ddd9defe18f98f
parent982f54fb174f23e60ed40577af2d62f281d83c10 (diff)
downloadgitlab-d7271b12e91c90ad7216073354085ed2b0257f73.tar.gz
Fix the json() method for python 3
Also add unit tests and fix pep8 test
-rw-r--r--gitlab/objects.py9
-rw-r--r--gitlab/tests/test_gitlabobject.py9
2 files changed, 14 insertions, 4 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py
index 9f3a655..95e1e45 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -26,16 +26,17 @@ import warnings
import six
+import gitlab
from gitlab.exceptions import * # noqa
class jsonEncoder(json.JSONEncoder):
def default(self, obj):
- from gitlab import Gitlab
if isinstance(obj, GitlabObject):
- return {k: v for k, v in obj.__dict__.iteritems()
- if not isinstance(v, BaseManager)}
- elif isinstance(obj, Gitlab):
+ return {k: v for k, v in six.iteritems(obj.__dict__)
+ if (not isinstance(v, BaseManager)
+ and not k[0] == '_')}
+ elif isinstance(obj, gitlab.Gitlab):
return {'url': obj._url}
return json.JSONEncoder.default(self, obj)
diff --git a/gitlab/tests/test_gitlabobject.py b/gitlab/tests/test_gitlabobject.py
index 99a184b..2726854 100644
--- a/gitlab/tests/test_gitlabobject.py
+++ b/gitlab/tests/test_gitlabobject.py
@@ -21,6 +21,7 @@ from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
+import json
try:
import unittest
except ImportError:
@@ -150,6 +151,14 @@ class TestGitlabObject(unittest.TestCase):
email="testuser@test.com", password="testpassword",
ssl_verify=True)
+ def test_json(self):
+ gl_object = CurrentUser(self.gl, data={"username": "testname"})
+ json_str = gl_object.json()
+ data = json.loads(json_str)
+ self.assertIn("id", data)
+ self.assertEqual(data["username"], "testname")
+ self.assertEqual(data["gitlab"]["url"], "http://localhost/api/v3")
+
def test_list_not_implemented(self):
self.assertRaises(NotImplementedError, CurrentUser.list, self.gl)