From 451c17492e1399e2359c761f1fb27982e6596696 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 13 Aug 2016 16:50:14 +0200 Subject: [PATCH] Remove _get_list_or_object() and its tests --- gitlab/objects.py | 10 --------- gitlab/tests/test_gitlab.py | 28 ----------------------- gitlab/tests/test_gitlabobject.py | 37 ------------------------------- 3 files changed, 75 deletions(-) diff --git a/gitlab/objects.py b/gitlab/objects.py index cdef349c3..60d10edbc 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -168,8 +168,6 @@ class GitlabObject(object): _id_in_update_url = True _constructorTypes = None - #: Whether _get_list_or_object should return list or object when id is None - getListWhenNoId = True #: Tells if GitLab-api allows retrieving single objects. canGet = True #: Tells if GitLab-api allows listing of objects. @@ -282,13 +280,6 @@ def get(cls, gl, id, **kwargs): raise GitlabGetError("Object not found") - @classmethod - def _get_list_or_object(cls, gl, id, **kwargs): - if id is None and cls.getListWhenNoId: - return cls.list(gl, **kwargs) - else: - return cls.get(gl, id, **kwargs) - def _get_object(self, k, v): if self._constructorTypes and k in self._constructorTypes: return globals()[self._constructorTypes[k]](self.gitlab, v) @@ -1604,7 +1595,6 @@ class ProjectFile(GitlabObject): 'commit_message'] optionalCreateAttrs = ['encoding'] requiredDeleteAttrs = ['branch_name', 'commit_message', 'file_path'] - getListWhenNoId = False shortPrintAttr = 'file_path' getRequiresId = False diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index c32a56102..4adf07f5a 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -625,34 +625,6 @@ def resp_cont(url, request): self.assertEqual(self.gl.user.id, id_) self.assertEqual(type(self.gl.user), CurrentUser) - def test_get_list_or_object_without_id(self): - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects", - method="get") - def resp_cont(url, request): - headers = {'content-type': 'application/json'} - content = '[{"name": "testproject", "id": 1}]'.encode("utf-8") - return response(200, content, headers, None, 5, request) - - with HTTMock(resp_cont): - projs = Project._get_list_or_object(self.gl, None) - self.assertEqual(len(projs), 1) - proj = projs[0] - self.assertEqual(proj.id, 1) - self.assertEqual(proj.name, "testproject") - - def test_get_list_or_object_with_id(self): - @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1", - method="get") - def resp_cont(url, request): - headers = {'content-type': 'application/json'} - content = '{"name": "testproject", "id": 1}'.encode("utf-8") - return response(200, content, headers, None, 5, request) - - with HTTMock(resp_cont): - proj = Project._get_list_or_object(self.gl, 1) - self.assertEqual(proj.id, 1) - self.assertEqual(proj.name, "testproject") - def test_hooks(self): @urlmatch(scheme="http", netloc="localhost", path="/api/v3/hooks/1", method="get") diff --git a/gitlab/tests/test_gitlabobject.py b/gitlab/tests/test_gitlabobject.py index ca0149faf..cf06a2a9d 100644 --- a/gitlab/tests/test_gitlabobject.py +++ b/gitlab/tests/test_gitlabobject.py @@ -210,43 +210,6 @@ def test_list(self): self.assertEqual(data[0].name, "name") self.assertEqual(data[0].id, 1) - def test_get_list_or_object_with_list(self): - with HTTMock(resp_list_project): - gl_object = Project(self.gl, data={"name": "name"}) - data = gl_object._get_list_or_object(self.gl, id=None) - self.assertEqual(type(data), list) - self.assertEqual(len(data), 1) - self.assertEqual(type(data[0]), Project) - self.assertEqual(data[0].name, "name") - self.assertEqual(data[0].id, 1) - - def test_get_list_or_object_with_get(self): - with HTTMock(resp_get_project): - gl_object = Project(self.gl, data={"name": "name"}) - data = gl_object._get_list_or_object(self.gl, id=1) - self.assertEqual(type(data), Project) - self.assertEqual(data.name, "name") - self.assertEqual(data.id, 1) - - def test_get_list_or_object_cant_get(self): - with HTTMock(resp_get_issue): - gl_object = UserProject(self.gl, data={"name": "name"}) - self.assertRaises(NotImplementedError, - gl_object._get_list_or_object, - self.gl, id=1) - - def test_get_list_or_object_cantlist(self): - gl_object = CurrentUser(self.gl, data={"name": "name"}) - self.assertRaises(NotImplementedError, gl_object._get_list_or_object, - self.gl, id=None) - - def test_get_list_or_object_create(self): - data = {"name": "name"} - gl_object = Project(self.gl, data=data) - data = gl_object._get_list_or_object(Project, id=data) - self.assertEqual(type(data), Project) - self.assertEqual(data.name, "name") - def test_create_cantcreate(self): gl_object = CurrentUser(self.gl, data={"username": "testname"}) self.assertRaises(NotImplementedError, gl_object._create)