summaryrefslogtreecommitdiff
path: root/tests/functional/api/test_packages.py
blob: 64b57b827b3170439103caf0034974304d82ffd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
GitLab API:
https://docs.gitlab.com/ce/api/packages.html
https://docs.gitlab.com/ee/user/packages/generic_packages
"""
from gitlab.v4.objects import GenericPackage

package_name = "hello-world"
package_version = "v1.0.0"
file_name = "hello.tar.gz"
file_content = "package content"


def test_list_project_packages(project):
    packages = project.packages.list()
    assert isinstance(packages, list)


def test_list_group_packages(group):
    packages = group.packages.list()
    assert isinstance(packages, list)


def test_upload_generic_package(tmp_path, project):
    path = tmp_path / file_name
    path.write_text(file_content)
    package = project.generic_packages.upload(
        package_name=package_name,
        package_version=package_version,
        file_name=file_name,
        path=path,
    )

    assert isinstance(package, GenericPackage)
    assert package.message == "201 Created"


def test_download_generic_package(project):
    package = project.generic_packages.download(
        package_name=package_name,
        package_version=package_version,
        file_name=file_name,
    )

    assert isinstance(package, bytes)
    assert package.decode("utf-8") == file_content


def test_download_generic_package_to_file(tmp_path, project):
    path = tmp_path / file_name

    with open(path, "wb") as f:
        project.generic_packages.download(
            package_name=package_name,
            package_version=package_version,
            file_name=file_name,
            streamed=True,
            action=f.write,
        )

    with open(path, "r") as f:
        assert f.read() == file_content