From 036c4b6c6c3944eae1d507f8d169d608df3df24d Mon Sep 17 00:00:00 2001 From: Jack Michaud Date: Sat, 31 Dec 2022 18:56:13 -0500 Subject: [PATCH] test: add contract test for discord bot --- discord-bot/requirements.dev.txt | 2 ++ discord-bot/tests/test_api_contract.py | 15 +++++++++++++++ scripts/backend-development/start-mock-server.sh | 6 +++++- scripts/discord-bot-development/test.sh | 10 ++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 discord-bot/requirements.dev.txt create mode 100644 discord-bot/tests/test_api_contract.py create mode 100755 scripts/discord-bot-development/test.sh diff --git a/discord-bot/requirements.dev.txt b/discord-bot/requirements.dev.txt new file mode 100644 index 00000000..ee4ba018 --- /dev/null +++ b/discord-bot/requirements.dev.txt @@ -0,0 +1,2 @@ +pytest +pytest-asyncio diff --git a/discord-bot/tests/test_api_contract.py b/discord-bot/tests/test_api_contract.py new file mode 100644 index 00000000..fe7be6cf --- /dev/null +++ b/discord-bot/tests/test_api_contract.py @@ -0,0 +1,15 @@ +import pytest +from bot.api_client import OasstApiClient + +from oasst_shared.schemas import protocol as protocol_schema + + +@pytest.fixture +def oasst_api_client_mocked(): + client = OasstApiClient(backend_url="http://localhost:8080", api_key="123") + yield client + + +@pytest.mark.asyncio +async def test_fetch_task(oasst_api_client_mocked: OasstApiClient): + assert await oasst_api_client_mocked.fetch_task(task_type=protocol_schema.TaskRequestType.random) is not None diff --git a/scripts/backend-development/start-mock-server.sh b/scripts/backend-development/start-mock-server.sh index a9bd0fbc..807230e8 100755 --- a/scripts/backend-development/start-mock-server.sh +++ b/scripts/backend-development/start-mock-server.sh @@ -10,7 +10,11 @@ python -m print_openapi_schema > oasst-openapi.json MOCK_SERVER_PORT=8080 -docker run --init --rm -d -p $MOCK_SERVER_PORT:4010 -v $(pwd):/tmp -P stoplight/prism:4 proxy -h 0.0.0.0 "/tmp/oasst-openapi.json" +docker run --init --rm -d \ + -p $MOCK_SERVER_PORT:4010 \ + -v $(pwd):/tmp \ + -P stoplight/prism:4 \ + mock -h 0.0.0.0 "/tmp/oasst-openapi.json" popd diff --git a/scripts/discord-bot-development/test.sh b/scripts/discord-bot-development/test.sh new file mode 100755 index 00000000..f863f74e --- /dev/null +++ b/scripts/discord-bot-development/test.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) + +# switch to backend directory +pushd "$parent_path/../../discord-bot" + +pytest . + +popd +