start project
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""Shared pytest fixtures (Chapter 12)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
os.environ.setdefault("SECRET_KEY", "test-secret-key")
|
||||
os.environ.setdefault("ADMIN_EMAIL", "admin@example.com")
|
||||
|
||||
from app import create_app
|
||||
from app.extensions import db as _db
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
application = create_app("testing")
|
||||
with application.app_context():
|
||||
_db.create_all()
|
||||
yield application
|
||||
_db.session.remove()
|
||||
_db.drop_all()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def db(app):
|
||||
return _db
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def logged_in_client(client, db):
|
||||
from app.models.user import User
|
||||
|
||||
user = User(email="admin@example.com")
|
||||
user.set_password("correct-horse-battery-staple")
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
client.post(
|
||||
"/login",
|
||||
data={"email": "admin@example.com", "password": "correct-horse-battery-staple"},
|
||||
follow_redirects=True,
|
||||
)
|
||||
return client
|
||||
Reference in New Issue
Block a user