Skip to content

Commit 451c174

Browse files
author
Gauvain Pocentek
committed
Remove _get_list_or_object() and its tests
1 parent a8f6fdd commit 451c174

File tree

3 files changed

+0
-75
lines changed

3 files changed

+0
-75
lines changed

gitlab/objects.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class GitlabObject(object):
168168
_id_in_update_url = True
169169
_constructorTypes = None
170170

171-
#: Whether _get_list_or_object should return list or object when id is None
172-
getListWhenNoId = True
173171
#: Tells if GitLab-api allows retrieving single objects.
174172
canGet = True
175173
#: Tells if GitLab-api allows listing of objects.
@@ -282,13 +280,6 @@ def get(cls, gl, id, **kwargs):
282280

283281
raise GitlabGetError("Object not found")
284282

285-
@classmethod
286-
def _get_list_or_object(cls, gl, id, **kwargs):
287-
if id is None and cls.getListWhenNoId:
288-
return cls.list(gl, **kwargs)
289-
else:
290-
return cls.get(gl, id, **kwargs)
291-
292283
def _get_object(self, k, v):
293284
if self._constructorTypes and k in self._constructorTypes:
294285
return globals()[self._constructorTypes[k]](self.gitlab, v)
@@ -1604,7 +1595,6 @@ class ProjectFile(GitlabObject):
16041595
'commit_message']
16051596
optionalCreateAttrs = ['encoding']
16061597
requiredDeleteAttrs = ['branch_name', 'commit_message', 'file_path']
1607-
getListWhenNoId = False
16081598
shortPrintAttr = 'file_path'
16091599
getRequiresId = False
16101600

gitlab/tests/test_gitlab.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -625,34 +625,6 @@ def resp_cont(url, request):
625625
self.assertEqual(self.gl.user.id, id_)
626626
self.assertEqual(type(self.gl.user), CurrentUser)
627627

628-
def test_get_list_or_object_without_id(self):
629-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects",
630-
method="get")
631-
def resp_cont(url, request):
632-
headers = {'content-type': 'application/json'}
633-
content = '[{"name": "testproject", "id": 1}]'.encode("utf-8")
634-
return response(200, content, headers, None, 5, request)
635-
636-
with HTTMock(resp_cont):
637-
projs = Project._get_list_or_object(self.gl, None)
638-
self.assertEqual(len(projs), 1)
639-
proj = projs[0]
640-
self.assertEqual(proj.id, 1)
641-
self.assertEqual(proj.name, "testproject")
642-
643-
def test_get_list_or_object_with_id(self):
644-
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
645-
method="get")
646-
def resp_cont(url, request):
647-
headers = {'content-type': 'application/json'}
648-
content = '{"name": "testproject", "id": 1}'.encode("utf-8")
649-
return response(200, content, headers, None, 5, request)
650-
651-
with HTTMock(resp_cont):
652-
proj = Project._get_list_or_object(self.gl, 1)
653-
self.assertEqual(proj.id, 1)
654-
self.assertEqual(proj.name, "testproject")
655-
656628
def test_hooks(self):
657629
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/hooks/1",
658630
method="get")

gitlab/tests/test_gitlabobject.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -210,43 +210,6 @@ def test_list(self):
210210
self.assertEqual(data[0].name, "name")
211211
self.assertEqual(data[0].id, 1)
212212

213-
def test_get_list_or_object_with_list(self):
214-
with HTTMock(resp_list_project):
215-
gl_object = Project(self.gl, data={"name": "name"})
216-
data = gl_object._get_list_or_object(self.gl, id=None)
217-
self.assertEqual(type(data), list)
218-
self.assertEqual(len(data), 1)
219-
self.assertEqual(type(data[0]), Project)
220-
self.assertEqual(data[0].name, "name")
221-
self.assertEqual(data[0].id, 1)
222-
223-
def test_get_list_or_object_with_get(self):
224-
with HTTMock(resp_get_project):
225-
gl_object = Project(self.gl, data={"name": "name"})
226-
data = gl_object._get_list_or_object(self.gl, id=1)
227-
self.assertEqual(type(data), Project)
228-
self.assertEqual(data.name, "name")
229-
self.assertEqual(data.id, 1)
230-
231-
def test_get_list_or_object_cant_get(self):
232-
with HTTMock(resp_get_issue):
233-
gl_object = UserProject(self.gl, data={"name": "name"})
234-
self.assertRaises(NotImplementedError,
235-
gl_object._get_list_or_object,
236-
self.gl, id=1)
237-
238-
def test_get_list_or_object_cantlist(self):
239-
gl_object = CurrentUser(self.gl, data={"name": "name"})
240-
self.assertRaises(NotImplementedError, gl_object._get_list_or_object,
241-
self.gl, id=None)
242-
243-
def test_get_list_or_object_create(self):
244-
data = {"name": "name"}
245-
gl_object = Project(self.gl, data=data)
246-
data = gl_object._get_list_or_object(Project, id=data)
247-
self.assertEqual(type(data), Project)
248-
self.assertEqual(data.name, "name")
249-
250213
def test_create_cantcreate(self):
251214
gl_object = CurrentUser(self.gl, data={"username": "testname"})
252215
self.assertRaises(NotImplementedError, gl_object._create)

0 commit comments

Comments
 (0)