44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""menu badge: plan cert pending uses EXISTS count."""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
from sqlalchemy import true
|
|
|
|
from app.services.pl_menu_badge_service import count_plan_cert_pending
|
|
from test_pl_quota_usage import case
|
|
from test_pl_quota_business import business
|
|
|
|
|
|
def test_count_plan_cert_pending_uses_sql_count_not_python_scan():
|
|
db = MagicMock()
|
|
query = MagicMock()
|
|
db.query.return_value = query
|
|
query.filter.return_value = query
|
|
query.count.return_value = 4
|
|
query.exists.return_value = true()
|
|
|
|
user = MagicMock()
|
|
with patch("app.services.pl_menu_badge_service.apply_pl_scope", side_effect=lambda q, *a, **k: q):
|
|
total = count_plan_cert_pending(db, "shanxia2.0", user)
|
|
|
|
assert total == 4
|
|
query.count.assert_called_once()
|
|
query.all.assert_not_called()
|
|
|
|
|
|
def test_legal_document_badge_is_independent_and_includes_archived_plan(business):
|
|
from app.services.pl_menu_badge_service import count_legal_use_document_pending
|
|
c = business
|
|
product = c.db.get(c.models.PlPlanProduct, 'pp')
|
|
product.is_toxic = 0
|
|
product.is_explosive = 1
|
|
c.plan.archive_status = 'archived'
|
|
c.plan.hazard_cert_ready = 1
|
|
c.db.flush()
|
|
assert count_legal_use_document_pending(c.db, 't', c.user) == 1
|
|
assert count_plan_cert_pending(c.db, 't', c.user) == 0
|
|
assert count_legal_use_document_pending(c.db, 'foreign', c.user) == 0
|
|
product.legal_use_cert_url = 'existing-document'
|
|
c.db.flush()
|
|
assert count_legal_use_document_pending(c.db, 't', c.user) == 0
|