-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Describe Your Changes Add testing framework, GitHub Action, and baseline test. ## Relevant Information https://sqlmodel.tiangolo.com/tutorial/fastapi/tests/ ## Checklist Before Requesting a Review - [x] The code runs successfully. ```commandline (prijatelitree-py3.11) michaelp@MacBook-Air-18 PrijateliTree % make test docker-compose up -d [+] Building 0.0s (0/0) docker:desktop-linux [+] Running 2/0 ✔ Container prijatelitree-postgres-1 Running 0.0s ✔ Container prijatelitree-web-1 Running 0.0s ENV=testing docker-compose run --rm web pytest -vsx ./prijateli_tree/tests/; [+] Building 0.0s (0/0) docker:desktop-linux [+] Creating 1/0 ✔ Container prijatelitree-postgres-1 Running 0.0s [+] Building 0.0s (0/0) docker:desktop-linux DEBUG: Routers loaded and static files mounted. ============================================================================================= test session starts ============================================================================================== platform linux -- Python 3.11.4, pytest-7.4.3, pluggy-1.3.0 -- /usr/local/bin/python cachedir: .pytest_cache rootdir: /usr/src/app plugins: anyio-3.7.1 collected 1 item prijateli_tree/tests/test_home.py::test_home_page DEBUG: Using selector: EpollSelector INFO: HTTP Request: GET http://testserver/ "HTTP/1.1 200 OK" PASSED =============================================================================================== warnings summary =============================================================================================== ../../local/lib/python3.11/site-packages/passlib/utils/__init__.py:854 /usr/local/lib/python3.11/site-packages/passlib/utils/__init__.py:854: DeprecationWarning: 'crypt' is deprecated and slated for removal in Python 3.13 from crypt import crypt as _crypt prijateli_tree/app/database.py:34 /usr/src/app/prijateli_tree/app/database.py:34: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 2.0) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) Base = declarative_base() -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ======================================================================================== 1 passed, 2 warnings in 0.03s ========================================================================================= (prijatelitree-py3.11) michaelp@MacBook-Air-18 PrijateliTree % ... 2023-12-24 16:13:55 INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) 2023-12-24 16:13:55 INFO: Started reloader process [1] using WatchFiles 2023-12-24 16:13:56 DEBUG: Routers loaded and static files mounted. 2023-12-24 16:13:56 INFO: Started server process [8] 2023-12-24 16:13:56 INFO: Waiting for application startup. 2023-12-24 16:13:56 INFO: Application startup complete. 2023-12-24 16:14:08 INFO: 192.168.65.1:65143 - "GET / HTTP/1.1" 200 OK 2023-12-24 16:14:08 INFO: 192.168.65.1:65143 - "GET /css/bootstrap.min.css HTTP/1.1" 200 OK 2023-12-24 16:14:08 INFO: 192.168.65.1:65144 - "GET /js/bootstrap.bundle.min.js HTTP/1.1" 200 OK 2023-12-24 16:14:08 INFO: 192.168.65.1:65148 - "GET /js/dataTables.bootstrap5.min.js HTTP/1.1" 304 Not Modified 2023-12-24 16:14:08 INFO: 192.168.65.1:65146 - "GET /js/jquery.dataTables.min.js HTTP/1.1" 200 OK ```
- Loading branch information
1 parent
f6536f4
commit 4c3cea3
Showing
18 changed files
with
353 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:3.11-slim-buster | ||
|
||
WORKDIR /usr/src/app | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
ENV DATABASE_URL="" | ||
|
||
RUN apt-get update && apt-get -y install gcc libpq-dev python3-dev libsqlite3-0 && apt-get clean | ||
|
||
RUN pip install --upgrade pip | ||
COPY ./requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
COPY . . |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
<div class="container-sm general-container"> | ||
<div class="row"> | ||
<div class="col text-start"> | ||
{% if not completed_game %} | ||
<p style="margin-bottom: 5px;">{{ text.game_first_round.round }}: {{ round_progress }}</p> | ||
{% endif %} | ||
{% if not completed_game %}<p class="mb-4">{{ text.game_first_round.round }}: {{ round_progress }}</p>{% endif %} | ||
{% if practice_game %} | ||
<p style="margin-bottom: 5px;">{{ text.game_video.game }}: {{ practice_game_progress }}</p> | ||
<p class="mb-4">{{ text.game_video.game }}: {{ practice_game_progress }}</p> | ||
{% else %} | ||
<p style="margin-bottom: 5px;">Real Game: {{ real_game_progress }}</p> | ||
<p class="mb-4">Real Game: {{ real_game_progress }}</p> | ||
{% endif %} | ||
</div> | ||
<div class="col text-end"> | ||
<p style="margin-bottom: 5px;">{{ player_name }}</p> | ||
<p style="margin-bottom: 5px;">{{ text.game_video.score }}: {{ player_score }}</p> | ||
<p class="mb-4">{{ player_name }}</p> | ||
<p class="mb-4">{{ text.game_video.score }}: {{ player_score }}</p> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
from sqlmodel import Session, SQLModel, create_engine | ||
from sqlmodel.pool import StaticPool | ||
|
||
from prijateli_tree.app.main import app | ||
from prijateli_tree.app.utils.constants import KEY_DATABASE_URI | ||
|
||
|
||
@pytest.fixture(name="session") | ||
def session_fixture(): | ||
print(os.getenv(KEY_DATABASE_URI)) | ||
engine = create_engine( | ||
os.getenv(KEY_DATABASE_URI), | ||
connect_args={"check_same_thread": False}, | ||
poolclass=StaticPool, | ||
) | ||
SQLModel.metadata.create_all(engine) | ||
with Session(engine) as session: | ||
add_mockdata(session) | ||
yield session | ||
|
||
|
||
def add_mockdata(session: Session): | ||
# Add data you want to the test DB using the `session` object. | ||
pass | ||
|
||
|
||
@pytest.fixture(name="client") | ||
def client_fixture(session: Session): | ||
def get_session_override(): | ||
return session | ||
|
||
app.dependency_overrides["get_session"] = get_session_override | ||
|
||
client = TestClient(app) | ||
yield client | ||
app.dependency_overrides.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from http import HTTPStatus | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
|
||
def test_home_page(client: TestClient): | ||
"""Test home page functionality.""" | ||
response = client.get("/") | ||
|
||
assert "Welcome to the PrijateliTree application!" in response.text | ||
assert response.status_code == HTTPStatus.OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters