Skip to content

Commit

Permalink
test: add regression for chatbot (#2218)
Browse files Browse the repository at this point in the history
* test: add regression for chatbot

* test: add chatbot regression test

* test: add chatbot regression test

* test: add chatbot regression test

* test: add chatbot regression test

* test: remove updates on jinahub

* test: fix dependency error

* test: remove unused imports
  • Loading branch information
bwanglzu committed Mar 25, 2021
1 parent ddc5af0 commit 3d1b954
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
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()


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

0 comments on commit 3d1b954

Please sign in to comment.