Files
Autoparts-DB/pos/tests/test_oem_block.py
2026-04-27 05:41:35 +00:00

50 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Test OEM catalog block."""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from tenant_db import get_master_conn, get_tenant_conn_by_dbname
from services.catalog_service import smart_search, get_part_detail
PASS = '\033[92mPASS\033[0m'
FAIL = '\033[91mFAIL\033[0m'
def ok(label, condition, detail=''):
if condition:
print(f" [{PASS}] {label}")
else:
print(f" [{FAIL}] {label} {detail}")
master = get_master_conn()
cur = master.cursor()
cur.execute("SELECT db_name FROM tenants WHERE is_active = true LIMIT 1")
row = cur.fetchone()
cur.close(); master.close()
db_name = row[0]
tenant = get_tenant_conn_by_dbname(db_name)
master = get_master_conn()
print("OEM Catalog Block Test")
print("=" * 40)
# smart_search should be blocked at blueprint level, but let's check the service
# The service itself still works; the blueprint blocks it.
# Let's verify the config flag is False
from config import CATALOG_OEM_ENABLED
ok("CATALOG_OEM_ENABLED is False", CATALOG_OEM_ENABLED is False, f"value={CATALOG_OEM_ENABLED}")
# Local mode endpoints should still work
from services.catalog_modes import normalize_mode
ok("normalize_mode local", normalize_mode('local') == 'local')
ok("normalize_mode oem", normalize_mode('oem') == 'oem')
# Check that get_parts_local is available
from services.catalog_service import get_parts_local
ok("get_parts_local exists", callable(get_parts_local))
master.close()
tenant.close()
print("Done.")