generated from MinBZK/python-project-template
-
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.
- Loading branch information
1 parent
9f1b180
commit 90fbd94
Showing
12 changed files
with
201 additions
and
198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ __pypackages__/ | |
|
||
# tad tool | ||
tad.log* | ||
database.sqlite3 |
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
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
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,5 +1,10 @@ | ||
from sqlmodel import create_engine | ||
from sqlmodel import Session, create_engine, select | ||
|
||
from tad.core.config import settings | ||
|
||
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, echo=True) | ||
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI) | ||
|
||
|
||
async def check_db(): | ||
with Session(engine) as session: | ||
session.exec(select(1)) |
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,3 @@ | ||
from .hero import Hero | ||
|
||
__all__ = ["Hero"] |
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,23 +1,28 @@ | ||
import os | ||
from collections.abc import Generator | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
from sqlmodel import Session, SQLModel, create_engine | ||
from sqlmodel.pool import StaticPool | ||
from tad.main import app | ||
|
||
# needed to make sure create_all knows about the models | ||
from tad.models import * # noqa: F403 | ||
|
||
|
||
# todo(berry): add database fixtures | ||
@pytest.fixture(scope="module") | ||
def client() -> Generator[TestClient, None, None]: | ||
def client(db: Session) -> Generator[TestClient, None, None]: | ||
with TestClient(app, raise_server_exceptions=True) as c: | ||
c.timeout = 3 | ||
c.timeout = 5 | ||
yield c | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup_basic_environmental_variables(monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]: # noqa: PT004 | ||
original_environ = dict(os.environ) | ||
monkeypatch.setenv("APP_DATABASE_PASSWORD", "changethis") | ||
yield | ||
os.environ.clear() | ||
os.environ.update(original_environ) | ||
@pytest.fixture(scope="module") | ||
def db() -> Generator[Session, None, None]: | ||
engine = create_engine("sqlite://", poolclass=StaticPool) | ||
SQLModel.metadata.create_all(engine) | ||
|
||
with Session(engine) as session: | ||
yield session | ||
|
||
SQLModel.metadata.drop_all(engine) |
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 unittest.mock import Mock, patch | ||
|
||
import pytest | ||
from sqlmodel import Session, select | ||
from tad.core.db import check_db | ||
|
||
|
||
@pytest.mark.skip(reason="not working yet") | ||
async def test_check_dabase(): | ||
mock_session = Mock(spec=Session) | ||
|
||
with patch("sqlmodel.Session", return_value=mock_session): | ||
await check_db() | ||
|
||
assert mock_session.exec.assert_called_once_with(select(1)) |
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