refactor(parsers): перенести тесты в ROOT_DIR/tests и синхронизировать контракты задач

- перенесены тесты parsers из src/apps/parsers/tests в tests/apps/parsers

- обновлены тесты задач под текущее поведение Celery (ошибки пробрасываются исключениями)

- убрана зависимость тестов от внешнего брокера через локальные eager-вызовы

- добавлены/уточнены фабрики и импорты для единой структуры тестов

- обновлены README и CHANGELOG с новым правилом размещения тестов и запуском
This commit is contained in:
2026-03-04 15:35:50 +01:00
parent 0738c53040
commit 052389d921
18 changed files with 657 additions and 284 deletions

View File

@@ -5,22 +5,23 @@ from __future__ import annotations
from datetime import timedelta
import factory
from faker import Faker
from apps.parsers.models import (
IndustrialCertificateRecord,
InspectionRecord,
ManufacturerRecord,
ParserLoadLog,
ProcurementRecord,
Proxy,
)
from django.utils import timezone
from faker import Faker
fake = Faker("ru_RU")
# === Хелперы для генерации реалистичных данных ===
def _digits(length: int) -> str:
return "".join(str(fake.random_int(0, 9)) for _ in range(length))
@@ -98,6 +99,41 @@ class ParserLoadLogFactory(factory.django.DjangoModelFactory):
error_message = ""
class ProcurementRecordFactory(factory.django.DjangoModelFactory):
"""Factory for ProcurementRecord model."""
class Meta:
model = ProcurementRecord
load_batch = factory.Sequence(lambda n: n + 1)
purchase_number = factory.LazyAttribute(
lambda _: str(fake.random_number(digits=19, fix_len=True))
)
purchase_name = factory.LazyAttribute(lambda _: fake.sentence(nb_words=6))
customer_inn = factory.LazyFunction(generate_inn_legal)
customer_kpp = factory.LazyAttribute(
lambda _: str(fake.random_number(digits=9, fix_len=True))
)
customer_ogrn = factory.LazyFunction(generate_ogrn)
customer_name = factory.LazyFunction(generate_company_name)
max_price = factory.LazyAttribute(
lambda _: str(fake.random_int(min=10000, max=10000000))
)
currency_code = "RUB"
placement_method = factory.LazyAttribute(lambda _: fake.word())
publish_date = factory.LazyAttribute(lambda _: str(fake.date()))
end_date = factory.LazyAttribute(lambda _: str(fake.date()))
status = factory.LazyAttribute(lambda _: fake.word())
law_type = factory.LazyAttribute(lambda _: fake.random_element(["44-FZ", "223-FZ"]))
purchase_object_info = factory.LazyAttribute(lambda _: fake.sentence(nb_words=8))
href = factory.LazyAttribute(lambda _: fake.url())
region_code = factory.LazyAttribute(
lambda _: str(fake.random_int(min=1, max=99)).zfill(2)
)
data_year = factory.LazyAttribute(lambda _: fake.random_int(min=2020, max=2026))
data_month = factory.LazyAttribute(lambda _: fake.random_int(min=1, max=12))
class IndustrialCertificateRecordFactory(factory.django.DjangoModelFactory):
"""Factory for IndustrialCertificateRecord model."""