Skip to content

feat: package file delete on package file object #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/gl_objects/packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Delete a package file in a project::

package = project.packages.get(1)
file = package.package_files.list()[0]
package.package_files.delete(file.id)
file.delete()


Generic Packages
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get(
return cast(ProjectPackage, super().get(id=id, lazy=lazy, **kwargs))


class ProjectPackageFile(RESTObject):
class ProjectPackageFile(ObjectDeleteMixin, RESTObject):
pass


Expand Down
35 changes: 34 additions & 1 deletion tests/unit/objects/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ def resp_delete_package_file(no_content):
yield rsps


@pytest.fixture
def resp_delete_package_file_list(no_content):
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url=re.compile(
r"http://localhost/api/v4/projects/1/packages/1/package_files"
),
json=package_file_content,
content_type="application/json",
status=200,
)
for pkg_file_id in range(25, 28):
rsps.add(
method=responses.DELETE,
url=f"http://localhost/api/v4/projects/1/packages/1/package_files/{pkg_file_id}",
json=no_content,
content_type="application/json",
status=204,
)
yield rsps


@pytest.fixture
def resp_list_package_files():
with responses.RequestsMock() as rsps:
Expand Down Expand Up @@ -242,11 +265,21 @@ def test_list_project_package_files(project, resp_list_package_files):
assert package_files[0].id == 25


def test_delete_project_package_file(project, resp_delete_package_file):
def test_delete_project_package_file_from_package_object(
project, resp_delete_package_file
):
package = project.packages.get(1, lazy=True)
package.package_files.delete(1)


def test_delete_project_package_file_from_package_file_object(
project, resp_delete_package_file_list
):
package = project.packages.get(1, lazy=True)
for package_file in package.package_files.list():
package_file.delete()


def test_upload_generic_package(tmp_path, project, resp_upload_generic_package):
path = tmp_path / file_name
path.write_text(file_content)
Expand Down