/
test_integration.py
44 lines (34 loc) · 1.37 KB
/
test_integration.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
import os
import pytest
from jina import Document
from jina import Flow
from jina.helper import get_internal_ip
from tests import validate_callback
cur_dir = os.path.dirname(os.path.abspath(__file__))
compose_yml = os.path.join(cur_dir, 'docker-compose.yml')
flow_yml = os.path.join(cur_dir, 'flow.yml')
@pytest.mark.skip('jinad with docker-compose not supported for now')
@pytest.mark.parametrize('docker_compose', [compose_yml], indirect=['docker_compose'])
@pytest.mark.parametrize(
'encoder_needs, indexer_needs, indexer_method',
[('crafter', 'encoder', 'add'), ('gateway', '[encoder, crafter]', 'needs')],
)
def test_flow(
docker_compose, tmpdir, mocker, encoder_needs, indexer_needs, indexer_method
):
text = 'cats rules'
def validate_output(resp):
assert len(resp.data.docs) == 1
assert resp.data.docs[0].text == text
os.environ['JINA_INTERNAL_HOST'] = get_internal_ip()
os.environ['JINA_ENCODER_HOST'] = '172.28.1.1'
os.environ['JINA_WORKSPACE'] = str(tmpdir)
os.environ['JINA_ENCODER_NEEDS'] = encoder_needs
os.environ['JINA_INDEXER_NEEDS'] = indexer_needs
os.environ['JINA_INDEXER_METHOD'] = indexer_method
doc = Document(content=text)
mock = mocker.Mock()
with Flow.load_config(flow_yml) as f:
f.index([doc], on_done=mock)
mock.assert_called_once()
validate_callback(mock, validate_output)