|
| 1 | +"""Integration tests for the deterministic demo seed command.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import pytest |
| 6 | +from django.core.management import call_command |
| 7 | + |
| 8 | +from accounts.models import CustomerProfile, MerchantProfile |
| 9 | +from returns.models import ReturnCase |
| 10 | + |
| 11 | +pytestmark = pytest.mark.django_db |
| 12 | + |
| 13 | + |
| 14 | +def test_seed_returnhub_demo_is_idempotent(): |
| 15 | + """Running the seed command twice should keep stable totals.""" |
| 16 | + |
| 17 | + call_command("seed_returnhub_demo") |
| 18 | + first_case_count = ReturnCase.objects.count() |
| 19 | + first_customer_count = CustomerProfile.objects.count() |
| 20 | + first_merchant_count = MerchantProfile.objects.count() |
| 21 | + |
| 22 | + call_command("seed_returnhub_demo") |
| 23 | + |
| 24 | + assert first_case_count == 32 |
| 25 | + assert ReturnCase.objects.count() == 32 |
| 26 | + assert CustomerProfile.objects.count() == first_customer_count == 2 |
| 27 | + assert MerchantProfile.objects.count() == first_merchant_count == 2 |
| 28 | + |
| 29 | + |
| 30 | +def test_seed_returnhub_demo_creates_page_two_coverage(): |
| 31 | + """Seeded data should provide enough cases for page 2 in customer and merchant portals.""" |
| 32 | + |
| 33 | + call_command("seed_returnhub_demo") |
| 34 | + |
| 35 | + customer_one_cases = ReturnCase.objects.filter(customer__user__username="customer.one").count() |
| 36 | + merchant_one_cases = ReturnCase.objects.filter(merchant__user__username="merchant.one").count() |
| 37 | + |
| 38 | + assert customer_one_cases == 16 |
| 39 | + assert merchant_one_cases == 16 |
| 40 | + assert ReturnCase.objects.filter(customer__user__username="customer.two").count() == 16 |
| 41 | + assert ReturnCase.objects.filter(merchant__user__username="merchant.two").count() == 16 |
0 commit comments