revised testing critera
Some checks failed
Build and Deploy Demo App / test (push) Successful in 12s
Build and Deploy Demo App / build (push) Successful in 7m51s
Build and Deploy Demo App / scan (push) Failing after 6m24s
Build and Deploy Demo App / deploy (push) Has been skipped

This commit is contained in:
2025-11-26 11:30:52 +03:30
parent 44926969ce
commit 78da8a061f
2 changed files with 47 additions and 21 deletions

View File

@@ -2,17 +2,30 @@ from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy() db = SQLAlchemy()
class Feature(db.Model): class Feature(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False) title = db.Column(db.String(100), nullable=False)
description = db.Column(db.String(200), nullable=False) description = db.Column(db.String(200), nullable=False)
def seed_db(): @staticmethod
if Feature.query.count() == 0: # Seed only if empty def seed_db():
features = [ # Seed only if empty
Feature(title="Responsive Design", description="Adapts seamlessly to mobile, tablet, and desktop devices."), if Feature.query.count() == 0:
Feature(title="Modern UI", description="Uses Bootstrap 5 for clean, professional styling."), features = [
Feature(title="Easy Deployment", description="Containerized with Docker for quick setup on any server.") Feature(
] title="Responsive Design",
db.session.bulk_save_objects(features) description="Adapts seamlessly to mobile, tablet, and desktop devices.",
db.session.commit() ),
Feature(
title="Modern UI",
description="Uses Bootstrap 5 for clean, professional styling.",
),
Feature(
title="Easy Deployment",
description="Containerized with Docker for quick setup on any server.",
),
]
db.session.bulk_save_objects(features)
db.session.commit()

View File

@@ -1,27 +1,40 @@
import pytest
import os 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 app import app
from models import db, Feature from models import db, Feature
@pytest.fixture @pytest.fixture
def client(): def client():
app.config['TESTING'] = True app.config["TESTING"] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' # app was already initialised with SQLite because DB_USER is now unset
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app) # Re-init DB with test config # Fresh DB per test
with app.app_context():
db.drop_all()
db.create_all()
with app.test_client() as client: with app.test_client() as client:
with app.app_context(): yield client
db.create_all()
yield client # Clean up after test
db.drop_all() with app.app_context():
db.drop_all()
def test_index(client): def test_index(client):
response = client.get('/') response = client.get("/")
assert response.status_code == 200 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(): with app.app_context():
Feature.seed_db() Feature.seed_db()
assert Feature.query.count() == 3 assert Feature.query.count() == 3