Skip to content

Commit

Permalink
Setup server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Sep 20, 2024
1 parent 4c0b1d4 commit 8e74628
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 8 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,39 @@ jobs:
- name: Run tests
working-directory: app/resident_manager
run: flutter test

python:
name: Run Python tests
runs-on: ubuntu-latest
environment:
name: test

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: pip install -r dev-requirements.txt

- name: Run tests
run: coverage run -m pytest -v .

- name: Combine coverage reports
run: coverage combine

- name: Report coverage
run: coverage report -m

- name: Generate HTML coverage report
run: coverage html -d htmlcov

- name: Upload HTML coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-html
path: htmlcov
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.vscode/

run.bat
.coverage*
50 changes: 50 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
aioodbc==0.5.0
annotated-types==0.7.0
anyio==4.4.0
autopep8==2.3.1
certifi==2024.8.30
click==8.1.7
colorama==0.4.6
coverage==7.6.1
dnspython==2.6.1
email_validator==2.2.0
exceptiongroup==1.2.2
fastapi==0.115.0
fastapi-cli==0.0.5
flake8==7.1.1
h11==0.14.0
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.2
idna==3.10
iniconfig==2.0.0
Jinja2==3.1.4
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
mdurl==0.1.2
mypy==1.11.2
mypy-extensions==1.0.0
packaging==24.1
pluggy==1.5.0
pycodestyle==2.12.1
pydantic==2.9.2
pydantic_core==2.23.4
pyflakes==3.2.0
Pygments==2.18.0
pyodbc==5.1.0
pytest==8.3.3
python-dotenv==1.0.1
python-multipart==0.0.9
PyYAML==6.0.2
rich==13.8.1
shellingham==1.5.4
sniffio==1.3.1
starlette==0.38.5
tomli==2.0.1
typer==0.12.5
typing_extensions==4.12.2
uvicorn==0.30.6
uvloop==0.20.0
watchfiles==0.24.0
websockets==13.0.1
8 changes: 0 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
aioodbc==0.5.0
annotated-types==0.7.0
anyio==4.5.0
autopep8==2.3.1
certifi==2024.8.30
click==8.1.7
colorama==0.4.6
Expand All @@ -10,7 +9,6 @@ email_validator==2.2.0
exceptiongroup==1.2.2
fastapi==0.115.0
fastapi-cli==0.0.5
flake8==7.1.1
h11==0.14.0
httpcore==1.0.5
httptools==0.6.1
Expand All @@ -19,14 +17,9 @@ idna==3.10
Jinja2==3.1.4
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
mdurl==0.1.2
mypy==1.11.2
mypy-extensions==1.0.0
pycodestyle==2.12.1
pydantic==2.9.2
pydantic_core==2.23.4
pyflakes==3.2.0
Pygments==2.18.0
pyodbc==5.1.0
python-dotenv==1.0.1
Expand All @@ -36,7 +29,6 @@ rich==13.8.1
shellingham==1.5.4
sniffio==1.3.1
starlette==0.38.5
tomli==2.0.1
typer==0.12.5
typing_extensions==4.12.2
uvicorn==0.30.6
Expand Down
1 change: 1 addition & 0 deletions server/routes/api/admin/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
async def admin_login(headers: Annotated[Authorization, Header()]) -> None:
"""Verify administrator authorization data, return 204 on success, 403 on failure"""
print("Got request")
if await Database.instance.verify_admin(headers.username, headers.password):
return None

Expand Down
59 changes: 59 additions & 0 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from __future__ import annotations

from fastapi.testclient import TestClient

from main import app


def test_docs() -> None:
with TestClient(app) as client:
response = client.get("/docs")
assert response.status_code == 200


def test_admin_login_ok() -> None:
with TestClient(app) as client:
response = client.post(
"/api/admin/login",
headers={
"Username": "admin",
"Password": "NgaiLongGey",
},
)
assert response.status_code == 204


def test_admin_login_incorrect_password() -> None:
with TestClient(app) as client:
response = client.post(
"/api/admin/login",
headers={
"Username": "admin",
"Password": "password",
},
)
assert response.status_code == 403


def test_admin_login_incorrect_username() -> None:
with TestClient(app) as client:
response = client.post(
"/api/admin/login",
headers={
"Username": "user",
"Password": "NgaiLongGey",
},
)
assert response.status_code == 403


def test_admin_login_incorrect_username_password() -> None:
with TestClient(app) as client:
response = client.post(
"/api/admin/login",
headers={
"Username": "user",
"Password": "password",
},
)
assert response.status_code == 403

0 comments on commit 8e74628

Please sign in to comment.