Skip to content
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
4 changes: 4 additions & 0 deletions docarray/array/mixins/io/pushpull.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PushPullMixin:
_max_bytes = 4 * 1024 * 1024 * 1024

@staticmethod
@hubble.login_required
def cloud_list(show_table: bool = False) -> List[str]:
"""List all available arrays in the cloud.

Expand Down Expand Up @@ -73,6 +74,7 @@ def cloud_list(show_table: bool = False) -> List[str]:
return result

@staticmethod
@hubble.login_required
def cloud_delete(name: str) -> None:
"""
Delete a DocumentArray from the cloud.
Expand Down Expand Up @@ -148,6 +150,7 @@ def _get_raw_summary(self) -> List[Dict[str, Any]]:

return items

@hubble.login_required
def push(
self,
name: str,
Expand Down Expand Up @@ -250,6 +253,7 @@ def _get_chunk(_batch):
response.raise_for_status()

@classmethod
@hubble.login_required
def pull(
cls: Type['T'],
name: str,
Expand Down
27 changes: 21 additions & 6 deletions tests/unit/array/mixins/test_pushpull.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
import requests
from hubble import Client

from docarray import DocumentArray, Document, dataclass
from docarray.helper import random_identity
Expand Down Expand Up @@ -64,6 +65,13 @@ def _mocker(url, data, headers=None):
monkeypatch.setattr(requests, 'post', _mocker)


def _mock_get_user_info(mock, monkeypatch):
def _get_user_info(obj):
return {}

monkeypatch.setattr(Client, 'get_user_info', _get_user_info)


def _mock_get(mock, monkeypatch, status_code=requests.codes.ok):
def _mocker(url, stream=False, headers=None):
mock(url=url, stream=stream, headers=headers)
Expand Down Expand Up @@ -135,26 +143,33 @@ def test_push_fail(mocker, monkeypatch):
assert mock.call_count == 1


def test_api_url_change(mocker, monkeypatch):
test_api_url = 'http://localhost:8080'
os.environ['JINA_HUBBLE_REGISTRY'] = test_api_url
@pytest.fixture()
def set_hubble_registry():
os.environ['JINA_HUBBLE_REGISTRY'] = 'http://localhost:8080'
yield
del os.environ['JINA_HUBBLE_REGISTRY']


def test_api_url_change(mocker, monkeypatch, set_hubble_registry):

mock = mocker.Mock()
_mock_post(mock, monkeypatch)
_mock_get(mock, monkeypatch)
_mock_get_user_info(mock, monkeypatch)

docs = random_docs(2)
name = random_identity()
docs.push(name)
docs.pull(name)

del os.environ['JINA_HUBBLE_REGISTRY']

assert mock.call_count == 3 # 1 for push, 1 for pull, 1 for download
assert (
mock.call_count >= 3
) # at least 1 for push, 1 for pull, 1 for download + extra for auth

_, push_kwargs = mock.call_args_list[0]
_, pull_kwargs = mock.call_args_list[1]

test_api_url = 'http://localhost:8080'
assert push_kwargs['url'].startswith(test_api_url)
assert pull_kwargs['url'].startswith(test_api_url)

Expand Down