"""Monthly workflow prices must affect estimates only with additive schema enabled.""" import asyncio from types import SimpleNamespace from app.fixed_price.frontend import views def run_report(monkeypatch,enabled,column_exists): queries=[] def query(sql,*args): queries.append(sql) return [{'available':1}] if 'information_schema.columns' in sql and column_exists else [] monkeypatch.setattr(views,'settings',SimpleNamespace(WORKFLOWS_ENABLED=enabled)) monkeypatch.setattr(views,'execute_query',query) monkeypatch.setattr(views.templates,'TemplateResponse',lambda *args,**kwargs: {}) asyncio.run(views.reports_dashboard(SimpleNamespace())) return queries def test_off_mode_preserves_original_dashboard_query(monkeypatch): queries=run_report(monkeypatch,False,False) assert not any('information_schema' in q for q in queries) assert 'hourly_rate - 300' in queries[0] def test_enabled_uses_configured_cost_and_monthly_price(monkeypatch): queries=run_report(monkeypatch,True,True) stats=next(q for q in queries if 'estimated_profit' in q) assert 'COALESCE(monthly_price, monthly_hours * hourly_rate)' in stats assert 'monthly_hours * internal_cost_rate' in stats assert 'hourly_rate - 300' not in stats def test_missing_migration_keeps_legacy_query(monkeypatch): queries=run_report(monkeypatch,True,False) stats=next(q for q in queries if 'estimated_profit' in q) assert 'hourly_rate - 300' in stats