Skip to content

Commit 2a76b74

Browse files
author
Gauvain Pocentek
committed
Rename the _created attribute _from_api
1 parent a636d5a commit 2a76b74

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

gitlab/__init__.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ def list(self, obj_class, **kwargs):
351351

352352
cls_kwargs = kwargs.copy()
353353

354-
# Add _created manually, because we are not creating objects
354+
# Add _from_api manually, because we are not creating objects
355355
# through normal path
356-
cls_kwargs['_created'] = True
356+
cls_kwargs['_from_api'] = True
357357

358358
get_all_results = params.get('all', False)
359359

@@ -536,7 +536,7 @@ def _list_projects(self, url, **kwargs):
536536
l = []
537537
for o in r.json():
538538
p = Project(self, o)
539-
p._created = True
539+
p._from_api = True
540540
l.append(p)
541541

542542
return l
@@ -737,7 +737,7 @@ def _create(self, **kwargs):
737737

738738
json = self.gitlab.create(self, **kwargs)
739739
self._set_from_dict(json)
740-
self._created = True
740+
self._from_api = True
741741

742742
def _update(self, **kwargs):
743743
if not self.canUpdate:
@@ -747,7 +747,7 @@ def _update(self, **kwargs):
747747
self._set_from_dict(json)
748748

749749
def save(self, **kwargs):
750-
if self._created:
750+
if self._from_api:
751751
self._update(**kwargs)
752752
else:
753753
self._create(**kwargs)
@@ -756,7 +756,7 @@ def delete(self, **kwargs):
756756
if not self.canDelete:
757757
raise NotImplementedError
758758

759-
if not self._created:
759+
if not self._from_api:
760760
raise GitlabDeleteError("Object not yet created")
761761

762762
return self.gitlab.delete(self, **kwargs)
@@ -772,16 +772,15 @@ def create(cls, gl, data, **kwargs):
772772
return obj
773773

774774
def __init__(self, gl, data=None, **kwargs):
775-
self._created = False
775+
self._from_api = False
776776
self.gitlab = gl
777777

778778
if (data is None or isinstance(data, six.integer_types) or
779779
isinstance(data, six.string_types)):
780780
if not self.canGet:
781781
raise NotImplementedError
782782
data = self.gitlab.get(self.__class__, data, **kwargs)
783-
# Object is created because we got it from api
784-
self._created = True
783+
self._from_api = True
785784

786785
self._set_from_dict(data)
787786

gitlab/tests/test_gitlab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def resp_delete_group(url, request):
337337

338338
def test_delete_unknown_path(self):
339339
obj = Project(self.gl, data={"name": "testname", "id": 1})
340-
obj._created = True
340+
obj._from_api = True
341341

342342
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
343343
method="delete")
@@ -398,7 +398,7 @@ def test_create_unknown_path(self):
398398
obj = User(self.gl, data={"email": "email", "password": "password",
399399
"username": "username", "name": "name",
400400
"can_create_group": True})
401-
obj._created = True
401+
obj._from_api = True
402402

403403
@urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1",
404404
method="delete")

gitlab/tests/test_gitlabobject.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_get_list_or_object_with_get(self):
182182

183183
def test_get_list_or_object_cant_get(self):
184184
with HTTMock(resp_get_issue):
185-
gl_object = Issue(self.gl, data={"name": "name"})
185+
gl_object = UserProject(self.gl, data={"name": "name"})
186186
self.assertRaises(NotImplementedError,
187187
gl_object._get_list_or_object,
188188
self.gl, id=1)
@@ -245,7 +245,7 @@ def test_save_with_id(self):
245245
"password": "password", "id": 1,
246246
"username": "username"})
247247
self.assertEqual(obj.name, "testname")
248-
obj._created = True
248+
obj._from_api = True
249249
obj.name = "newname"
250250
with HTTMock(resp_update_user):
251251
obj.save()
@@ -259,7 +259,7 @@ def test_save_without_id(self):
259259

260260
def test_delete(self):
261261
obj = Group(self.gl, data={"name": "testname", "id": 1})
262-
obj._created = True
262+
obj._from_api = True
263263
with HTTMock(resp_delete_group):
264264
data = obj.delete()
265265
self.assertIs(data, True)

0 commit comments

Comments
 (0)