Skip to content

Commit

Permalink
feat(tests): coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
itayB committed May 4, 2024
1 parent b196db9 commit 24d7351
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[report]
skip_empty = True
precision = 2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
__pycache__
venv
.coverage
coverage.xml
result.xml
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ pip install -r requirements.txt # install dependencies
python -m backend # run the server
```

## Tests

### Unit Tests

Run the following command to execute the project unit-tests:

```bash
py.test -o junit_family=xunit2 --junitxml result.xml -xv --ff --cov=backend --cov-report=xml --cov-report=term-missing tests
```

### Contributing

Pull requests are welcome. For major changes, please open an issue first
Expand Down
9 changes: 7 additions & 2 deletions backend/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.sysconfig import get_python_lib
import sys
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
Expand Down Expand Up @@ -28,5 +29,9 @@ def main():
run(app, host="0.0.0.0", port=8080)


if __name__ == "__main__":
main()
def init():
if __name__ == "__main__":
sys.exit(main())


init()
6 changes: 6 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-r requirements.txt
pytest==8.2.0
pytest-asyncio==0.23.6
pytest-cov==5.0.0
pytest-mock==3.14.0
httpx==0.27.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fastapi==0.110.0
fastapi==0.110.2
uvicorn==0.29.0
vite-project==1.0.5
Empty file added tests/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from fastapi.testclient import TestClient
import pytest

from backend.__main__ import create_app

@pytest.fixture(scope="session")
def test_client():
with TestClient(create_app()) as test_client:
yield test_client
5 changes: 5 additions & 0 deletions tests/test_health_rounter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_liveness(test_client):
with test_client as client:
response = client.get("/v1/health-check/liveness")
assert response.status_code == 200
assert response.json() == {"status": "success"}
14 changes: 14 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from backend.__main__ import main


def test_main(mocker):
mocker.patch("backend.__main__.run")
ret = main()
assert ret is None


def test_serve_react_app(test_client):
with test_client as client:
response = client.get("/index.html")
assert response.status_code == 200
assert "Vite + React + TS".encode() in response.content

0 comments on commit 24d7351

Please sign in to comment.