Код: Выделить всё
@pytest.fixture()
def populate_cache() -> Callable[[CountryFactory], Household]:
"""
Fixture to populate the dashboard cache for a specific business area,
verify creation in the default DB, and ensure readability in the read_only DB.
"""
def _populate_cache(goodcountry: CountryFactory) -> Household:
# Create household and related records
household, individuals = create_household("business_area": afghanistan)
PaymentFactory.create_batch(5, household=household)
PaymentRecordFactory.create_batch(3, household=household)
# Verify data exists in the default DB
payment_count_default = Payment.objects.using("default").filter(household=household).count()
print(f"Payments in default DB: {payment_count_default}")
# Verify data accessibility in the read_only DB
payment_count_read_only = Payment.objects.using("read_only").filter(household=household).count()
print(f"Payments in read_only DB: {payment_count_read_only}")
# Assert that the data is accessible in the read_only DB
assert payment_count_read_only == payment_count_default, "Mismatch in Payment count between default and read_only DBs."
return household
return _populate_dashboard_cache
Платежи в базе данных по умолчанию: 5
Платежи в базе данных только для чтения: 0
Подробнее здесь: https://stackoverflow.com/questions/791 ... g-and-test
Мобильная версия