Skip to content

Commit d7ee6f8

Browse files
committed
test(packages): add tests for streaming downloads
Tests for the functionality implemented in 4f9807f
1 parent 63fa05b commit d7ee6f8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/functional/api/test_packages.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
https://docs.gitlab.com/ce/api/packages.html
44
https://docs.gitlab.com/ee/user/packages/generic_packages
55
"""
6+
from collections.abc import Iterator
7+
68
from gitlab.v4.objects import GenericPackage
79

810
package_name = "hello-world"
@@ -46,6 +48,25 @@ def test_download_generic_package(project):
4648
assert package.decode("utf-8") == file_content
4749

4850

51+
def test_stream_generic_package(project):
52+
bytes_iterator = project.generic_packages.download(
53+
package_name=package_name,
54+
package_version=package_version,
55+
file_name=file_name,
56+
streamed=True,
57+
action="iterator",
58+
)
59+
60+
assert isinstance(bytes_iterator, Iterator)
61+
62+
package = bytes()
63+
for chunk in bytes_iterator:
64+
package += chunk
65+
66+
assert isinstance(package, bytes)
67+
assert package.decode("utf-8") == file_content
68+
69+
4970
def test_download_generic_package_to_file(tmp_path, project):
5071
path = tmp_path / file_name
5172

@@ -60,3 +81,22 @@ def test_download_generic_package_to_file(tmp_path, project):
6081

6182
with open(path, "r") as f:
6283
assert f.read() == file_content
84+
85+
86+
def test_stream_generic_package_to_file(tmp_path, project):
87+
path = tmp_path / file_name
88+
89+
bytes_iterator = project.generic_packages.download(
90+
package_name=package_name,
91+
package_version=package_version,
92+
file_name=file_name,
93+
streamed=True,
94+
action="iterator",
95+
)
96+
97+
with open(path, "wb") as f:
98+
for chunk in bytes_iterator:
99+
f.write(chunk)
100+
101+
with open(path, "r") as f:
102+
assert f.read() == file_content

0 commit comments

Comments
 (0)