revised testing critera
This commit is contained in:
37
test_app.py
37
test_app.py
@@ -1,27 +1,40 @@
|
||||
import pytest
|
||||
import os
|
||||
import pytest
|
||||
|
||||
# Ensure tests always use the in-memory SQLite DB, even if CI sets DB_* secrets
|
||||
for var in ("DB_USER", "DB_PASS", "DB_NAME"):
|
||||
os.environ.pop(var, None)
|
||||
|
||||
from app import app
|
||||
from models import db, Feature
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
db.init_app(app) # Re-init DB with test config
|
||||
app.config["TESTING"] = True
|
||||
# app was already initialised with SQLite because DB_USER is now unset
|
||||
|
||||
# Fresh DB per test
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
|
||||
with app.test_client() as client:
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
yield client
|
||||
db.drop_all()
|
||||
yield client
|
||||
|
||||
# Clean up after test
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
|
||||
|
||||
def test_index(client):
|
||||
response = client.get('/')
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
assert b'Professional Demo Site' in response.data
|
||||
assert b"Professional Demo Site" in response.data
|
||||
|
||||
def test_seed_db(client): # Add fixture here
|
||||
|
||||
def test_seed_db(client):
|
||||
with app.app_context():
|
||||
Feature.seed_db()
|
||||
assert Feature.query.count() == 3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user