Skip to content

Commit

Permalink
Remove _get_list_or_object() and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Aug 13, 2016
1 parent a8f6fdd commit 451c174
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 75 deletions.
10 changes: 0 additions & 10 deletions gitlab/objects.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
28 changes: 0 additions & 28 deletions gitlab/tests/test_gitlab.py
Expand Up @@ -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")
Expand Down
37 changes: 0 additions & 37 deletions gitlab/tests/test_gitlabobject.py
Expand Up @@ -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)
Expand Down

0 comments on commit 451c174

Please sign in to comment.