Skip to content

Commit 4caf4be

Browse files
author
Sebastien MICHEL
committed
fix: lazy id object
to align lazy id object and non-lazy id object and then make ObjectDeleteMixin works with lazy object Signed-off-by: Sebastien MICHEL <sebastien.t.michel@renault.com>
1 parent 85713bb commit 4caf4be

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎gitlab/mixins.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def get(
101101
GitlabGetError: If the server cannot perform the request
102102
"""
103103
if not isinstance(id, int):
104-
id = utils.clean_str_id(id)
105-
path = "%s/%s" % (self.path, id)
104+
clean_id = utils.clean_str_id(id)
105+
path = "%s/%s" % (self.path, clean_id)
106106
if TYPE_CHECKING:
107107
assert self._obj_cls is not None
108108
if lazy is True:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import gitlab
2+
import pytest
3+
4+
@pytest.mark.parametrize("lazy", [True, False])
5+
def test_delete_branch(gl, project, branch, lazy):
6+
b = project.branches.get(branch.name, lazy=lazy)
7+
b.delete()

‎tests/functional/conftest.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ def project(gl):
227227
except gitlab.exceptions.GitlabDeleteError as e:
228228
print(f"Project already deleted: {e}")
229229

230+
@pytest.fixture(scope="function")
231+
def branch(project):
232+
"""Branch fixture for branch API resource tests."""
233+
branch = project.branches.create({"branch":f"test/branch", "ref":"master"})
234+
yield branch
235+
236+
try:
237+
branch.delete()
238+
except gitlab.exceptions.GitlabDeleteError as e:
239+
print(f"Project already deleted: {e}")
240+
230241

231242
@pytest.fixture(scope="function")
232243
def merge_request(project, wait_for_sidekiq):

0 commit comments

Comments
 (0)