Skip to content

Commit 815b378

Browse files
Implements Integration Tests (#54)
* implements first integration tests * pytest installation only locally * fix: COPY requirements statement in dev.Dockerfile --------- Co-authored-by: andhreljaKern <[email protected]>
1 parent 4f9f48e commit 815b378

File tree

8 files changed

+50
-4
lines changed

8 files changed

+50
-4
lines changed

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
from fastapi.testclient import TestClient
3+
from typing import Iterator
4+
from app import app
5+
6+
7+
@pytest.fixture
8+
def client() -> Iterator[TestClient]:
9+
with TestClient(app) as client:
10+
yield client

dev.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ WORKDIR /app
44

55
VOLUME ["/app"]
66

7-
COPY requirements.txt .
7+
COPY requirements*.txt .
88

9-
RUN pip3 install --no-cache-dir -r requirements.txt
9+
RUN pip3 install --no-cache-dir -r requirements-dev.txt
1010

1111
COPY / .
1212

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r requirements.txt
2+
pytest==8.1.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,4 @@ uvicorn==0.22.0
146146
# via -r requirements/common-requirements.txt
147147

148148
# The following packages are considered to be unsafe in a requirements file:
149-
# setuptools
149+
# setuptools

run-tests

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker exec -it refinery-neural-search bash -c "cd /app && python -m pytest -v"

tests/__init__.py

Whitespace-only changes.

tests/test_app.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from unittest.mock import patch
2+
3+
from fastapi.testclient import TestClient
4+
5+
6+
def test_get_collections(client: TestClient):
7+
response = client.get("/collections")
8+
assert response.status_code == 200
9+
response_data = response.json()
10+
assert isinstance(response_data, list)
11+
12+
13+
def test_healthcheck(client: TestClient):
14+
response = client.get("/healthcheck")
15+
assert response.status_code == 200
16+
assert response.text == "OK"
17+
18+
19+
def test_failed_healthcheck(client: TestClient):
20+
21+
with patch(
22+
"submodules.model.business_objects.general.test_database_connection"
23+
) as mock_execute:
24+
mock_execute.return_value = {
25+
"success": False,
26+
"error": "OperationalError",
27+
}
28+
response = client.get("/healthcheck")
29+
30+
assert response.status_code == 500
31+
assert response.text == "database_error:OperationalError:"

0 commit comments

Comments
 (0)