You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB
Python

from unittest.mock import patch
1 year ago
import pytest
from flask_login.test_client import FlaskLoginClient
1 year ago
from htmx_contact import create_app
from htmx_contact.config import ContactSettings
from htmx_contact.models import Contact
from htmx_contact.models import User
1 year ago
@pytest.fixture()
def test_config():
return ContactSettings(SECRET_KEY=b"secrettestingvalue")
@pytest.fixture()
def test_user():
return User(id=1, primary_email="test", password="test", username="test")
@pytest.fixture()
def test_contacts(test_user):
return [
Contact(
id=1,
user_id=test_user.id,
first_name="Mark",
last_name="Zuckerberg",
email="zuck@facebook.com",
phone="555-777-1337",
),
Contact(
id=2,
user_id=test_user.id,
first_name="Shaan",
last_name="Puri",
email="shaan@twitter.com",
phone="666-777-1337",
),
Contact(
id=3,
user_id=test_user.id,
first_name="Sam",
last_name="Par",
email="sam@thesampar.com",
phone="587-343-1337",
),
]
@pytest.fixture()
def app(test_config):
app = create_app(config=test_config)
app.test_client_class = FlaskLoginClient
app.config.update(
{
"TESTING": True,
# disbale session protection or session "freshness" will cause failures.
"SESSION_PROTECTION": None,
}
)
# other setup can go here
yield app
# clean up / reset resources here
@pytest.fixture()
def anynomous_client(app):
1 year ago
return app.test_client()
@pytest.fixture()
def client(app, test_user):
with app.test_client(user=test_user) as client:
yield client
1 year ago
@pytest.fixture()
def runner(app):
return app.test_cli_runner()
@pytest.fixture()
def sqla_session():
with patch("htmx_contact.Session") as ms:
yield ms