Files
mostovik-backend/tests/apps/registers/test_generate_test_data_command.py
Aleksandr Meshchriakov 0824733d1a
Some checks failed
CI/CD Pipeline / Run Tests (pull_request) Successful in 1m35s
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled
CI/CD Pipeline / Telegram Notify Success (pull_request) Has been cancelled
CI/CD Pipeline / Code Quality Checks (pull_request) Has been cancelled
feat(registers): add command to generate test data from factories
2026-03-20 10:42:17 +01:00

74 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Тесты команды generate_test_data."""
from apps.parsers.models import (
IndustrialCertificateRecord,
IndustrialProductRecord,
InspectionRecord,
ManufacturerRecord,
ParserLoadLog,
ProcurementRecord,
Proxy,
)
from apps.registers.models import (
Organization,
Register,
RegisterUpload,
RegistryMembershipPeriod,
)
from django.core.management import call_command
from django.test import TestCase
class GenerateTestDataCommandTest(TestCase):
"""Проверки management command generate_test_data."""
def test_command_creates_data_for_every_registry(self):
"""Команда создаёт данные по всем целевым реестрам."""
call_command(
"generate_test_data",
count=2,
registers_count=3,
silent=True,
verbosity=0,
)
self.assertEqual(Register.objects.count(), 3)
self.assertEqual(RegisterUpload.objects.count(), 6)
self.assertEqual(RegistryMembershipPeriod.objects.count(), 6)
self.assertEqual(Organization.objects.count(), 6)
self.assertEqual(IndustrialCertificateRecord.objects.count(), 2)
self.assertEqual(ManufacturerRecord.objects.count(), 2)
self.assertEqual(IndustrialProductRecord.objects.count(), 2)
self.assertEqual(InspectionRecord.objects.count(), 2)
self.assertEqual(ProcurementRecord.objects.count(), 2)
self.assertEqual(Proxy.objects.count(), 2)
self.assertEqual(
ParserLoadLog.objects.count(),
len(ParserLoadLog.Source.values) * 2,
)
def test_command_dry_run_rolls_back_everything(self):
"""В dry-run режиме все изменения откатываются."""
call_command(
"generate_test_data",
count=1,
registers_count=1,
dry_run=True,
silent=True,
verbosity=0,
)
self.assertEqual(Register.objects.count(), 0)
self.assertEqual(RegisterUpload.objects.count(), 0)
self.assertEqual(RegistryMembershipPeriod.objects.count(), 0)
self.assertEqual(Organization.objects.count(), 0)
self.assertEqual(IndustrialCertificateRecord.objects.count(), 0)
self.assertEqual(ManufacturerRecord.objects.count(), 0)
self.assertEqual(IndustrialProductRecord.objects.count(), 0)
self.assertEqual(InspectionRecord.objects.count(), 0)
self.assertEqual(ProcurementRecord.objects.count(), 0)
self.assertEqual(Proxy.objects.count(), 0)
self.assertEqual(ParserLoadLog.objects.count(), 0)