Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add regression for chatbot #2218

Merged
merged 8 commits into from
Mar 25, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions extra-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pytest-mock: test
pytest-cov: test
pytest-repeat: test
pytest-asyncio: test
pytest-xprocess: test
flaky: test
mock: test
requests: http, devel, cicd, daemon
Expand Down
Empty file.
47 changes: 47 additions & 0 deletions tests/system/chatbot/test_chatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest
import requests
from xprocess import ProcessStarter

from jina.helloworld.chatbot import hello_world
from jina.parsers.helloworld import set_hw_chatbot_parser


@pytest.fixture
def chatbot_args(tmpdir):
return set_hw_chatbot_parser().parse_args(
['--workdir', str(tmpdir), '--port-expose', '8080']
)


@pytest.fixture
def payload():
return {'top_k': 1, 'data': ['text:Is my dog safe from virus']}


@pytest.fixture
def post_uri():
return 'http://localhost:8080/api/search'


@pytest.fixture
def expected_result():
return '''There’s no evidence from the outbreak that eating garlic, sipping water every 15 minutes or taking vitamin C will protect people from the new coronavirus.'''


@pytest.fixture(autouse=True)
def start_server(xprocess, chatbot_args):
class Starter(ProcessStarter):
pattern = "You should see a demo page opened in your browser"
args = ["jina", "hello", "chatbot"]
max_read_lines = 10000

xprocess.ensure("server", Starter)
yield
xprocess.getinfo("server").terminate()
nan-wang marked this conversation as resolved.
Show resolved Hide resolved


def test_chatbot(payload, post_uri, expected_result):
"""Regression test for chatbot example."""
resp = requests.post(post_uri, json=payload)
assert resp.status_code == 200
assert expected_result in resp.text