3
3
https://docs.gitlab.com/ce/api/packages.html
4
4
https://docs.gitlab.com/ee/user/packages/generic_packages
5
5
"""
6
+ from collections .abc import Iterator
7
+
6
8
from gitlab .v4 .objects import GenericPackage
7
9
8
10
package_name = "hello-world"
@@ -46,6 +48,25 @@ def test_download_generic_package(project):
46
48
assert package .decode ("utf-8" ) == file_content
47
49
48
50
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
+
49
70
def test_download_generic_package_to_file (tmp_path , project ):
50
71
path = tmp_path / file_name
51
72
@@ -60,3 +81,22 @@ def test_download_generic_package_to_file(tmp_path, project):
60
81
61
82
with open (path , "r" ) as f :
62
83
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