From 8e21d436215e35aa0c485a160b8eb7ef747dabf1 Mon Sep 17 00:00:00 2001 From: Alexandre Henrique Afonso Campos Date: Sun, 11 Aug 2024 01:04:01 -0300 Subject: [PATCH] Add instruction for integration tests --- CONTRIBUTING.md | 22 +++++++++++++++++++++- docker-compose-test.yaml | 12 ++++++++++++ test-server/__init__.py | 0 tests/agents/test_openai.py | 3 ++- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 docker-compose-test.yaml delete mode 100644 test-server/__init__.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8242d437..0498b06d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -79,4 +79,24 @@ We use pre-commit hooks to maintain code quality. To set up pre-commit: pytest ``` -For more detailed information on code quality, documentation, and testing, please refer to the full contributing guidelines in the repository. \ No newline at end of file +For more detailed information on code quality, documentation, and testing, please refer to the full contributing guidelines in the repository. + +### Integration Testing + +- To run the integration tests, you should first start the test-server. + +```bash +$ docker-compose -f docker-compose-test.yaml up -d +``` + +If you do not want to use docker, you can navigate to `test-server` and follow the instruction there. It simply runs a FastAPI simple Rest API. + +- Make sure your virtual environment is active. Execute the test (currently, there is only one test using it) + +```bash +python -m pytest tests/agents/test_openai.py -o log_cli=true +``` + +#### Extending integration tests + +Make sure the testing server is running. If you want to extend tests, first you need to select your agent. Probably, this agent has an API exposed so an SDK or a client can interact with it. Most agents are configurable, including the API URL. Modify that URL to `http://localhost:8000` and run the workflow you want to test. The testing server is configured to log requests that it does not handle. So, take that log (it includes the path and method), get a valid response and extend the server. To get a valid response, you can either go to the SDK docs or by running it locally with debug and finding your own valid response. Try to follow the examples available. diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml new file mode 100644 index 00000000..ff51e993 --- /dev/null +++ b/docker-compose-test.yaml @@ -0,0 +1,12 @@ +version: "3.8" + +services: + app: + image: python:3.10.14-slim-bullseye + working_dir: /app + volumes: + - ./test-server:/app + ports: + - "8000:8000" + command: > + sh -c "pip install -r requirements.txt && python main.py" diff --git a/test-server/__init__.py b/test-server/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/agents/test_openai.py b/tests/agents/test_openai.py index de5d2cf2..5e1e0ed6 100644 --- a/tests/agents/test_openai.py +++ b/tests/agents/test_openai.py @@ -6,9 +6,10 @@ from swarms.prompts.finance_agent_sys_prompt import ( ) # This tests uses the same code as the example.py file, with 1 different line +# This is actually an integration test. -def test_openai_no_quota(): +def test_openai_happy_path(): # Get the OpenAI API key from the environment variable api_key = os.getenv("OPENAI_API_KEY")