summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-08 21:42:47 +0100
committerGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-08 21:50:59 +0100
commit2bf9794c81487883c346850a79d6b7db1295fd95 (patch)
treec46f607aa1748253402e6474014d39f62bd33a48
parentdc0099d7901bd381fabadb8be77b93e7258454b3 (diff)
downloadgitlab-2bf9794c81487883c346850a79d6b7db1295fd95.tar.gz
Deprecate the "old" Gitlab methods
Update the associated unit tests.
-rw-r--r--gitlab/__init__.py15
-rw-r--r--gitlab/tests/test_gitlab.py42
2 files changed, 44 insertions, 13 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index b2d8cb6..64d45e5 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -421,6 +421,8 @@ class Gitlab(object):
object is NOT saved on the server. Use the save() method on the object
to write it on the server.
"""
+ warnings.warn("`Hook` is deprecated, use `hooks` instead",
+ DeprecationWarning)
return Hook._get_list_or_object(self, id, **kwargs)
def Project(self, id=None, **kwargs):
@@ -435,6 +437,8 @@ class Gitlab(object):
object is NOT saved on the server. Use the save() method on the object
to write it on the server.
"""
+ warnings.warn("`Project` is deprecated, use `projects` instead",
+ DeprecationWarning)
return Project._get_list_or_object(self, id, **kwargs)
def UserProject(self, id=None, **kwargs):
@@ -442,6 +446,9 @@ class Gitlab(object):
id must be a dict.
"""
+ warnings.warn("`UserProject` is deprecated, "
+ "use `user_projects` instead",
+ DeprecationWarning)
return UserProject._get_list_or_object(self, id, **kwargs)
def _list_projects(self, url, **kwargs):
@@ -484,6 +491,8 @@ class Gitlab(object):
save() method on the object to write it on the server.
kwargs: Arbitrary keyword arguments
"""
+ warnings.warn("`Group` is deprecated, use `groups` instead",
+ DeprecationWarning)
return Group._get_list_or_object(self, id, **kwargs)
def Issue(self, id=None, **kwargs):
@@ -492,6 +501,8 @@ class Gitlab(object):
Does not support creation or getting a single issue unlike other
methods in this class yet.
"""
+ warnings.warn("`Issue` is deprecated, use `issues` instead",
+ DeprecationWarning)
return Issue._get_list_or_object(self, id, **kwargs)
def User(self, id=None, **kwargs):
@@ -506,6 +517,8 @@ class Gitlab(object):
object is NOT saved on the server. Use the save() method on the object
to write it on the server.
"""
+ warnings.warn("`User` is deprecated, use `users` instead",
+ DeprecationWarning)
return User._get_list_or_object(self, id, **kwargs)
def Team(self, id=None, **kwargs):
@@ -520,4 +533,6 @@ class Gitlab(object):
object is NOT saved on the server. Use the save() method on the object
to write it on the server.
"""
+ warnings.warn("`Team` is deprecated, use `teams` instead",
+ DeprecationWarning)
return Team._get_list_or_object(self, id, **kwargs)
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py
index 0fe73e1..dc31875 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -620,7 +620,7 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(proj.id, 1)
self.assertEqual(proj.name, "testproject")
- def test_Hook(self):
+ def test_hooks(self):
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/hooks/1",
method="get")
def resp_get_hook(url, request):
@@ -629,12 +629,12 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_hook):
- data = self.gl.Hook(id=1)
+ data = self.gl.hooks.get(1)
self.assertEqual(type(data), Hook)
self.assertEqual(data.url, "testurl")
self.assertEqual(data.id, 1)
- def test_Project(self):
+ def test_projects(self):
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
method="get")
def resp_get_project(url, request):
@@ -643,12 +643,12 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_project):
- data = self.gl.Project(id=1)
+ data = self.gl.projects.get(1)
self.assertEqual(type(data), Project)
self.assertEqual(data.name, "name")
self.assertEqual(data.id, 1)
- def test_UserProject(self):
+ def test_userprojects(self):
@urlmatch(scheme="http", netloc="localhost",
path="/api/v3/projects/user/2", method="get")
def resp_get_userproject(url, request):
@@ -657,10 +657,10 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_userproject):
- self.assertRaises(NotImplementedError, self.gl.UserProject, id=1,
- user_id=2)
+ self.assertRaises(NotImplementedError, self.gl.user_projects.get,
+ 1, user_id=2)
- def test_Group(self):
+ def test_groups(self):
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/1",
method="get")
def resp_get_group(url, request):
@@ -670,13 +670,13 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_group):
- data = self.gl.Group(id=1)
+ data = self.gl.groups.get(1)
self.assertEqual(type(data), Group)
self.assertEqual(data.name, "name")
self.assertEqual(data.path, "path")
self.assertEqual(data.id, 1)
- def test_Issue(self):
+ def test_issues(self):
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/issues",
method="get")
def resp_get_issue(url, request):
@@ -687,11 +687,11 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_issue):
- data = self.gl.Issue(id=2)
+ data = self.gl.issues.get(2)
self.assertEqual(data.id, 2)
self.assertEqual(data.name, 'other_name')
- def test_User(self):
+ def test_users(self):
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/users/1",
method="get")
def resp_get_user(url, request):
@@ -702,7 +702,23 @@ class TestGitlab(unittest.TestCase):
return response(200, content, headers, None, 5, request)
with HTTMock(resp_get_user):
- user = self.gl.User(id=1)
+ user = self.gl.users.get(1)
self.assertEqual(type(user), User)
self.assertEqual(user.name, "name")
self.assertEqual(user.id, 1)
+
+ def test_teams(self):
+ @urlmatch(scheme="http", netloc="localhost",
+ path="/api/v3/user_teams/1", method="get")
+ def resp_get_group(url, request):
+ headers = {'content-type': 'application/json'}
+ content = '{"name": "name", "id": 1, "path": "path"}'
+ content = content.encode('utf-8')
+ return response(200, content, headers, None, 5, request)
+
+ with HTTMock(resp_get_group):
+ data = self.gl.teams.get(1)
+ self.assertEqual(type(data), Team)
+ self.assertEqual(data.name, "name")
+ self.assertEqual(data.path, "path")
+ self.assertEqual(data.id, 1)