/
test_hubapi.py
63 lines (46 loc) · 1.87 KB
/
test_hubapi.py
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
63
import os
from pathlib import Path
import pytest
from jina.hubble import HubExecutor, hubapi
from jina.hubble.hubapi import list_local
cur_dir = os.path.dirname(os.path.abspath(__file__))
@pytest.fixture
def executor_zip_file():
return Path(__file__).parent / 'dummy_executor.zip'
@pytest.fixture
def test_executor():
return HubExecutor(uuid='hello', name=None, commit_id='test_commit', tag='v0')
@pytest.mark.parametrize('install_deps', [True, False])
def test_install_local(executor_zip_file, test_executor, install_deps):
assert not hubapi.exist_local(test_executor.uuid, test_executor.tag)
hubapi.install_local(executor_zip_file, test_executor, install_deps=install_deps)
assert hubapi.exist_local(test_executor.uuid, test_executor.tag)
assert any(
str(path).endswith(
f'{os.path.join(test_executor.uuid, test_executor.tag)}.dist-info'
)
for path in list_local()
)
hubapi.uninstall_local(test_executor.uuid)
assert not hubapi.exist_local(test_executor.uuid, test_executor.tag)
def test_load_dump_secret():
import tempfile
uuid8 = 'hello'
secret = 'world'
with tempfile.TemporaryDirectory() as tmpdirname:
hubapi.dump_secret(Path(tmpdirname), uuid8, secret)
new_uuid8, new_secret = hubapi.load_secret(Path(tmpdirname))
assert new_uuid8 == uuid8
assert new_secret == secret
def test_load_dump_secret_existing_encryption_key():
import tempfile
uuid8 = 'hello'
secret = 'world'
with tempfile.TemporaryDirectory() as tmpdirname:
# creates an encryption key
hubapi.dump_secret(Path(tmpdirname), 'dummy', 'dummy')
# dump secret using existing encryption key
hubapi.dump_secret(Path(tmpdirname), uuid8, secret)
new_uuid8, new_secret = hubapi.load_secret(Path(tmpdirname))
assert new_uuid8 == uuid8
assert new_secret == secret