diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 3dae155c8..169e2f40a 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -100,9 +100,10 @@ def get( GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request """ + clean_id = id if not isinstance(id, int): - id = utils.clean_str_id(id) - path = "%s/%s" % (self.path, id) + clean_id = utils.clean_str_id(id) + path = "%s/%s" % (self.path, clean_id) if TYPE_CHECKING: assert self._obj_cls is not None if lazy is True: diff --git a/tests/functional/api/test_branch.py b/tests/functional/api/test_branch.py new file mode 100644 index 000000000..615c4e98a --- /dev/null +++ b/tests/functional/api/test_branch.py @@ -0,0 +1,7 @@ +import gitlab +import pytest + +@pytest.mark.parametrize("lazy", [True, False]) +def test_delete_branch(gl, project, branch, lazy): + b = project.branches.get(branch.name, lazy=lazy) + b.delete() diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 23aa5830f..7cfbd9a89 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -227,6 +227,17 @@ def project(gl): except gitlab.exceptions.GitlabDeleteError as e: print(f"Project already deleted: {e}") +@pytest.fixture(scope="function") +def branch(project): + """Branch fixture for branch API resource tests.""" + branch = project.branches.create({"branch":f"test/branch", "ref":"master"}) + yield branch + + try: + branch.delete() + except gitlab.exceptions.GitlabDeleteError as e: + print(f"Project already deleted: {e}") + @pytest.fixture(scope="function") def merge_request(project, wait_for_sidekiq):