78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
from app.core.config import settings
|
|
from app.db.session import SessionLocal
|
|
from app.models.comparison import ComparisonRecord
|
|
from app.models.user import User
|
|
from app.repositories import ops_marquee
|
|
|
|
|
|
def _clear_real_rows_cache() -> None:
|
|
ops_marquee._real_rows_cache.update(at=None, rows=None, test_phones=None)
|
|
|
|
|
|
def test_real_marquee_records_exclude_configured_test_account(monkeypatch) -> None:
|
|
legacy_test_phone = "19900009991"
|
|
listed_test_phone = "19900009992"
|
|
real_phone = "19900009993"
|
|
monkeypatch.setattr(settings, "TEST_ACCOUNT_PHONE", legacy_test_phone)
|
|
monkeypatch.setattr(settings, "TEST_ACCOUNT_PHONES", listed_test_phone)
|
|
_clear_real_rows_cache()
|
|
|
|
try:
|
|
with SessionLocal() as db:
|
|
legacy_test_user = User(
|
|
phone=legacy_test_phone,
|
|
username="29900009991",
|
|
register_channel="sms",
|
|
)
|
|
listed_test_user = User(
|
|
phone=listed_test_phone,
|
|
username="29900009992",
|
|
register_channel="sms",
|
|
)
|
|
real_user = User(
|
|
phone=real_phone,
|
|
username="29900009993",
|
|
register_channel="sms",
|
|
)
|
|
db.add_all([legacy_test_user, listed_test_user, real_user])
|
|
db.flush()
|
|
db.add_all([
|
|
ComparisonRecord(
|
|
user_id=legacy_test_user.id,
|
|
trace_id="marquee-legacy-test-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_991,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
ComparisonRecord(
|
|
user_id=listed_test_user.id,
|
|
trace_id="marquee-listed-test-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_992,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
ComparisonRecord(
|
|
user_id=real_user.id,
|
|
trace_id="marquee-real-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_993,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
])
|
|
db.flush()
|
|
|
|
app_rows = ops_marquee._recent_real_rows(db)
|
|
browse_rows, _ = ops_marquee.list_real_records(db, mode="real", limit=1_000)
|
|
finally:
|
|
_clear_real_rows_cache()
|
|
|
|
assert all(saved not in {29_991, 29_992} for _uid, saved, _nickname in app_rows)
|
|
assert any(saved == 29_993 for _uid, saved, _nickname in app_rows)
|
|
assert all(row["saved_amount_cents"] not in {29_991, 29_992} for row in browse_rows)
|
|
assert any(row["saved_amount_cents"] == 29_993 for row in browse_rows)
|