Skip to content

Commit a19aabd

Browse files
committed
feat(hubble): add public parameter to da.push
1 parent 117fd67 commit a19aabd

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

docarray/array/mixins/io/pushpull.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class PushPullMixin:
5757

5858
_max_bytes = 4 * 1024 * 1024 * 1024
5959

60-
def push(self, name: str, show_progress: bool = False) -> Dict:
60+
def push(
61+
self, name: str, *, public: bool = True, show_progress: bool = False
62+
) -> Dict:
6163
"""Push this DocumentArray object to Jina Cloud which can be later retrieved via :meth:`.push`
6264
6365
.. note::
@@ -68,6 +70,7 @@ def push(self, name: str, show_progress: bool = False) -> Dict:
6870
persistence. Only use this full temporary transmission/storage/clipboard.
6971
7072
:param name: a name that later can be used for retrieve this :class:`DocumentArray`.
73+
:param public: If True, the DocumentArray will be shared publicly. Otherwise, it will be private.
7174
:param show_progress: if to show a progress bar on pulling
7275
"""
7376
import requests
@@ -82,6 +85,7 @@ def push(self, name: str, show_progress: bool = False) -> Dict:
8285
),
8386
'name': name,
8487
'type': 'documentArray',
88+
'public': public,
8589
}
8690
)
8791

tests/unit/array/mixins/test_pushpull.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import cgi
12
import json
23
import os
34
import pytest
45
import requests
6+
from io import BytesIO
57

68
from docarray import DocumentArray
79
from docarray.array.mixins.io.pushpull import JINA_CLOUD_CONFIG
@@ -82,6 +84,27 @@ def test_push(mocker, monkeypatch):
8284
assert mock.call_count == 1
8385

8486

87+
@pytest.mark.parametrize('public', [True, False])
88+
def test_push_with_public(mocker, monkeypatch, public):
89+
mock = mocker.Mock()
90+
_mock_post(mock, monkeypatch)
91+
92+
docs = random_docs(2)
93+
docs.push(name='test_name', public=public)
94+
95+
_, mock_kwargs = mock.call_args_list[0]
96+
97+
c_type, c_data = cgi.parse_header(mock_kwargs['headers']['Content-Type'])
98+
assert c_type == 'multipart/form-data'
99+
100+
form_data = cgi.parse_multipart(
101+
BytesIO(b''.join(mock_kwargs['data'])),
102+
{'boundary': c_data['boundary'].encode()},
103+
)
104+
105+
assert form_data['public'] == [str(public)]
106+
107+
85108
def test_pull(mocker, monkeypatch):
86109
mock = mocker.Mock()
87110
_mock_get(mock, monkeypatch)
@@ -104,7 +127,7 @@ def test_push_fail(mocker, monkeypatch):
104127
_mock_post(mock, monkeypatch, status_code=requests.codes.forbidden)
105128

106129
docs = random_docs(2)
107-
with pytest.raises(Exception) as exc_info:
130+
with pytest.raises(Exception):
108131
docs.push('test_name')
109132

110133
assert mock.call_count == 1

0 commit comments

Comments
 (0)