-
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.
feat: configure pytest + Write first test
- Loading branch information
1 parent
c8245b7
commit 921e424
Showing
6 changed files
with
96 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest_plugins = ["src.tests.fixtures.service"] |
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
Empty file.
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,35 @@ | ||
from typing import Generator | ||
import pytest | ||
from flask import Flask | ||
from flask.testing import FlaskClient | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
from src import create_app | ||
from src import db as _db | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def app(): | ||
app = create_app("testing") | ||
return app | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def db(app): | ||
with app.app_context(): | ||
_db.create_all() | ||
yield _db | ||
_db.drop_all() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def db_session(db): | ||
yield db.session | ||
db.session.rollback() | ||
db.session.close() | ||
|
||
|
||
@pytest.fixture() | ||
def client(app: Flask, db: SQLAlchemy) -> Generator[FlaskClient, None, None]: | ||
with app.test_client() as client: | ||
yield client |
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 config import TestingConfig | ||
|
||
|
||
def test_testing_config(db_session): | ||
from flask import current_app as app | ||
|
||
assert app.config["DEBUG"] | ||
assert app.config["TESTING"] | ||
assert ( | ||
app.config["SQLALCHEMY_DATABASE_URI"] == TestingConfig.SQLALCHEMY_DATABASE_URI | ||
) |