Skip to content

Commit 2bf9794

Browse files
author
Gauvain Pocentek
committed
Deprecate the "old" Gitlab methods
Update the associated unit tests.
1 parent dc0099d commit 2bf9794

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

gitlab/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ def Hook(self, id=None, **kwargs):
421421
object is NOT saved on the server. Use the save() method on the object
422422
to write it on the server.
423423
"""
424+
warnings.warn("`Hook` is deprecated, use `hooks` instead",
425+
DeprecationWarning)
424426
return Hook._get_list_or_object(self, id, **kwargs)
425427

426428
def Project(self, id=None, **kwargs):
@@ -435,13 +437,18 @@ def Project(self, id=None, **kwargs):
435437
object is NOT saved on the server. Use the save() method on the object
436438
to write it on the server.
437439
"""
440+
warnings.warn("`Project` is deprecated, use `projects` instead",
441+
DeprecationWarning)
438442
return Project._get_list_or_object(self, id, **kwargs)
439443

440444
def UserProject(self, id=None, **kwargs):
441445
"""Creates a project for a user.
442446
443447
id must be a dict.
444448
"""
449+
warnings.warn("`UserProject` is deprecated, "
450+
"use `user_projects` instead",
451+
DeprecationWarning)
445452
return UserProject._get_list_or_object(self, id, **kwargs)
446453

447454
def _list_projects(self, url, **kwargs):
@@ -484,6 +491,8 @@ def Group(self, id=None, **kwargs):
484491
save() method on the object to write it on the server.
485492
kwargs: Arbitrary keyword arguments
486493
"""
494+
warnings.warn("`Group` is deprecated, use `groups` instead",
495+
DeprecationWarning)
487496
return Group._get_list_or_object(self, id, **kwargs)
488497

489498
def Issue(self, id=None, **kwargs):
@@ -492,6 +501,8 @@ def Issue(self, id=None, **kwargs):
492501
Does not support creation or getting a single issue unlike other
493502
methods in this class yet.
494503
"""
504+
warnings.warn("`Issue` is deprecated, use `issues` instead",
505+
DeprecationWarning)
495506
return Issue._get_list_or_object(self, id, **kwargs)
496507

497508
def User(self, id=None, **kwargs):
@@ -506,6 +517,8 @@ def User(self, id=None, **kwargs):
506517
object is NOT saved on the server. Use the save() method on the object
507518
to write it on the server.
508519
"""
520+
warnings.warn("`User` is deprecated, use `users` instead",
521+
DeprecationWarning)
509522
return User._get_list_or_object(self, id, **kwargs)
510523

511524
def Team(self, id=None, **kwargs):
@@ -520,4 +533,6 @@ def Team(self, id=None, **kwargs):
520533
object is NOT saved on the server. Use the save() method on the object
521534
to write it on the server.
522535
"""
536+
warnings.warn("`Team` is deprecated, use `teams` instead",
537+
DeprecationWarning)
523538
return Team._get_list_or_object(self, id, **kwargs)

gitlab/tests/test_gitlab.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def resp_cont(url, request):
620620
self.assertEqual(proj.id, 1)
621621
self.assertEqual(proj.name, "testproject")
622622

623-
def test_Hook(self):
623+
def test_hooks(self):
624624
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/hooks/1",
625625
method="get")
626626
def resp_get_hook(url, request):
@@ -629,12 +629,12 @@ def resp_get_hook(url, request):
629629
return response(200, content, headers, None, 5, request)
630630

631631
with HTTMock(resp_get_hook):
632-
data = self.gl.Hook(id=1)
632+
data = self.gl.hooks.get(1)
633633
self.assertEqual(type(data), Hook)
634634
self.assertEqual(data.url, "testurl")
635635
self.assertEqual(data.id, 1)
636636

637-
def test_Project(self):
637+
def test_projects(self):
638638
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
639639
method="get")
640640
def resp_get_project(url, request):
@@ -643,12 +643,12 @@ def resp_get_project(url, request):
643643
return response(200, content, headers, None, 5, request)
644644

645645
with HTTMock(resp_get_project):
646-
data = self.gl.Project(id=1)
646+
data = self.gl.projects.get(1)
647647
self.assertEqual(type(data), Project)
648648
self.assertEqual(data.name, "name")
649649
self.assertEqual(data.id, 1)
650650

651-
def test_UserProject(self):
651+
def test_userprojects(self):
652652
@urlmatch(scheme="http", netloc="localhost",
653653
path="/api/v3/projects/user/2", method="get")
654654
def resp_get_userproject(url, request):
@@ -657,10 +657,10 @@ def resp_get_userproject(url, request):
657657
return response(200, content, headers, None, 5, request)
658658

659659
with HTTMock(resp_get_userproject):
660-
self.assertRaises(NotImplementedError, self.gl.UserProject, id=1,
661-
user_id=2)
660+
self.assertRaises(NotImplementedError, self.gl.user_projects.get,
661+
1, user_id=2)
662662

663-
def test_Group(self):
663+
def test_groups(self):
664664
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/groups/1",
665665
method="get")
666666
def resp_get_group(url, request):
@@ -670,13 +670,13 @@ def resp_get_group(url, request):
670670
return response(200, content, headers, None, 5, request)
671671

672672
with HTTMock(resp_get_group):
673-
data = self.gl.Group(id=1)
673+
data = self.gl.groups.get(1)
674674
self.assertEqual(type(data), Group)
675675
self.assertEqual(data.name, "name")
676676
self.assertEqual(data.path, "path")
677677
self.assertEqual(data.id, 1)
678678

679-
def test_Issue(self):
679+
def test_issues(self):
680680
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/issues",
681681
method="get")
682682
def resp_get_issue(url, request):
@@ -687,11 +687,11 @@ def resp_get_issue(url, request):
687687
return response(200, content, headers, None, 5, request)
688688

689689
with HTTMock(resp_get_issue):
690-
data = self.gl.Issue(id=2)
690+
data = self.gl.issues.get(2)
691691
self.assertEqual(data.id, 2)
692692
self.assertEqual(data.name, 'other_name')
693693

694-
def test_User(self):
694+
def test_users(self):
695695
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/users/1",
696696
method="get")
697697
def resp_get_user(url, request):
@@ -702,7 +702,23 @@ def resp_get_user(url, request):
702702
return response(200, content, headers, None, 5, request)
703703

704704
with HTTMock(resp_get_user):
705-
user = self.gl.User(id=1)
705+
user = self.gl.users.get(1)
706706
self.assertEqual(type(user), User)
707707
self.assertEqual(user.name, "name")
708708
self.assertEqual(user.id, 1)
709+
710+
def test_teams(self):
711+
@urlmatch(scheme="http", netloc="localhost",
712+
path="/api/v3/user_teams/1", method="get")
713+
def resp_get_group(url, request):
714+
headers = {'content-type': 'application/json'}
715+
content = '{"name": "name", "id": 1, "path": "path"}'
716+
content = content.encode('utf-8')
717+
return response(200, content, headers, None, 5, request)
718+
719+
with HTTMock(resp_get_group):
720+
data = self.gl.teams.get(1)
721+
self.assertEqual(type(data), Team)
722+
self.assertEqual(data.name, "name")
723+
self.assertEqual(data.path, "path")
724+
self.assertEqual(data.id, 1)

0 commit comments

Comments
 (0)