feat: migrate parser data to source records
This commit is contained in:
@@ -6,7 +6,10 @@ from datetime import date
|
||||
from decimal import Decimal
|
||||
from unittest.mock import patch
|
||||
|
||||
from apps.parsers.models import ParserLoadLog
|
||||
from apps.parsers.clients.minpromtorg.schemas import IndustrialProduct
|
||||
from apps.parsers.clients.proverki.schemas import Inspection
|
||||
from apps.parsers.clients.zakupki.schemas import Procurement
|
||||
from apps.parsers.models import FinancialReport, ParserLoadLog
|
||||
from apps.parsers.services import (
|
||||
FNSReportService,
|
||||
IndustrialProductService,
|
||||
@@ -20,12 +23,7 @@ from apps.parsers.services import (
|
||||
from django.db import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
from tests.apps.parsers.factories import (
|
||||
IndustrialProductRecordFactory,
|
||||
InspectionRecordFactory,
|
||||
ParserLoadLogFactory,
|
||||
ProcurementRecordFactory,
|
||||
)
|
||||
from tests.apps.parsers.factories import ParserLoadLogFactory
|
||||
from tests.apps.registers.factories import OrganizationFactory
|
||||
|
||||
|
||||
@@ -144,15 +142,37 @@ class ParserLoadLogServiceRetryTest(TestCase):
|
||||
|
||||
class SmallParserServiceQueryTest(TestCase):
|
||||
def test_industrial_product_service_query_helpers(self):
|
||||
record = IndustrialProductRecordFactory(
|
||||
inn="7701001001",
|
||||
ogrn="1027700100001",
|
||||
load_batch=7,
|
||||
IndustrialProductService.save_products(
|
||||
[
|
||||
IndustrialProduct(
|
||||
full_organisation_name='ООО "Продукт 1"',
|
||||
ogrn="1027700100001",
|
||||
inn="7701001001",
|
||||
registry_number="PROD-1",
|
||||
product_name="Станок",
|
||||
product_model="MODEL-1",
|
||||
okpd2_code="28.41",
|
||||
tnved_code="8457109000",
|
||||
regulatory_document="ГОСТ",
|
||||
)
|
||||
],
|
||||
batch_id=7,
|
||||
)
|
||||
IndustrialProductRecordFactory(
|
||||
inn="7701001001",
|
||||
ogrn="1027700100002",
|
||||
load_batch=8,
|
||||
IndustrialProductService.save_products(
|
||||
[
|
||||
IndustrialProduct(
|
||||
full_organisation_name='ООО "Продукт 2"',
|
||||
ogrn="1027700100002",
|
||||
inn="7701001001",
|
||||
registry_number="PROD-2",
|
||||
product_name="Пресс",
|
||||
product_model="MODEL-2",
|
||||
okpd2_code="28.42",
|
||||
tnved_code="8457209000",
|
||||
regulatory_document="ТУ",
|
||||
)
|
||||
],
|
||||
batch_id=8,
|
||||
)
|
||||
|
||||
self.assertEqual(IndustrialProductService.find_by_inn("7701001001").count(), 2)
|
||||
@@ -161,26 +181,105 @@ class SmallParserServiceQueryTest(TestCase):
|
||||
1,
|
||||
)
|
||||
self.assertEqual(
|
||||
IndustrialProductService.find_by_ogrn("1027700100001").first().id,
|
||||
record.id,
|
||||
IndustrialProductService.find_by_ogrn("1027700100001").first().external_id,
|
||||
"PROD-1",
|
||||
)
|
||||
|
||||
def test_inspection_service_has_data_for_period(self):
|
||||
InspectionRecordFactory(data_year=2026, data_month=3, is_federal_law_248=False)
|
||||
InspectionRecordFactory(data_year=2026, data_month=4, is_federal_law_248=True)
|
||||
InspectionService.save_inspections(
|
||||
[
|
||||
Inspection(
|
||||
registration_number="INSP-1",
|
||||
inn="7701002001",
|
||||
ogrn="1027700200001",
|
||||
organisation_name='ООО "Проверка 1"',
|
||||
control_authority="Контроль",
|
||||
inspection_type="Плановая",
|
||||
inspection_form="Документарная",
|
||||
start_date="2026-03-01",
|
||||
end_date="2026-03-15",
|
||||
status="planned",
|
||||
legal_basis="ФЗ",
|
||||
result="",
|
||||
is_federal_law_248=False,
|
||||
),
|
||||
],
|
||||
batch_id=1,
|
||||
data_year=2026,
|
||||
data_month=3,
|
||||
)
|
||||
InspectionService.save_inspections(
|
||||
[
|
||||
Inspection(
|
||||
registration_number="INSP-2",
|
||||
inn="7701002002",
|
||||
ogrn="1027700200002",
|
||||
organisation_name='ООО "Проверка 2"',
|
||||
control_authority="Контроль",
|
||||
inspection_type="Плановая",
|
||||
inspection_form="Документарная",
|
||||
start_date="2026-04-01",
|
||||
end_date="2026-04-15",
|
||||
status="planned",
|
||||
legal_basis="ФЗ",
|
||||
result="",
|
||||
is_federal_law_248=True,
|
||||
),
|
||||
],
|
||||
batch_id=2,
|
||||
is_federal_law_248=True,
|
||||
data_year=2026,
|
||||
data_month=4,
|
||||
)
|
||||
|
||||
self.assertTrue(InspectionService.has_data_for_period(2026, 3))
|
||||
self.assertFalse(InspectionService.has_data_for_period(2026, 3, True))
|
||||
self.assertTrue(InspectionService.has_data_for_period(2026, 4, True))
|
||||
|
||||
def test_procurement_service_find_by_customer_name_with_batch(self):
|
||||
ProcurementRecordFactory(
|
||||
customer_name="АО Тестовый заказчик",
|
||||
load_batch=11,
|
||||
ProcurementService.save_procurements(
|
||||
[
|
||||
Procurement(
|
||||
purchase_number="PROC-1",
|
||||
purchase_name="Поставка 1",
|
||||
customer_inn="7701003001",
|
||||
customer_kpp="770101001",
|
||||
customer_ogrn="1027700300001",
|
||||
customer_name="АО Тестовый заказчик",
|
||||
max_price="1000",
|
||||
currency_code="RUB",
|
||||
placement_method="Аукцион",
|
||||
publish_date="2026-03-01",
|
||||
end_date="2026-03-15",
|
||||
status="published",
|
||||
law_type="44-FZ",
|
||||
purchase_object_info="Оборудование",
|
||||
href="https://example.test/proc-1",
|
||||
)
|
||||
],
|
||||
batch_id=11,
|
||||
)
|
||||
ProcurementRecordFactory(
|
||||
customer_name="АО Тестовый заказчик",
|
||||
load_batch=12,
|
||||
ProcurementService.save_procurements(
|
||||
[
|
||||
Procurement(
|
||||
purchase_number="PROC-2",
|
||||
purchase_name="Поставка 2",
|
||||
customer_inn="7701003002",
|
||||
customer_kpp="770101002",
|
||||
customer_ogrn="1027700300002",
|
||||
customer_name="АО Тестовый заказчик",
|
||||
max_price="2000",
|
||||
currency_code="RUB",
|
||||
placement_method="Аукцион",
|
||||
publish_date="2026-04-01",
|
||||
end_date="2026-04-15",
|
||||
status="published",
|
||||
law_type="44-FZ",
|
||||
purchase_object_info="Оборудование",
|
||||
href="https://example.test/proc-2",
|
||||
)
|
||||
],
|
||||
batch_id=12,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
@@ -210,13 +309,13 @@ class FNSReportServiceHelpersTest(TestCase):
|
||||
|
||||
FNSReportService.mark_processing(report)
|
||||
report.refresh_from_db()
|
||||
self.assertEqual(report.status, report.Status.PROCESSING)
|
||||
self.assertEqual(report.status, FinancialReport.Status.PROCESSING)
|
||||
|
||||
FNSReportService.mark_success(report)
|
||||
report.refresh_from_db()
|
||||
self.assertEqual(report.status, report.Status.SUCCESS)
|
||||
self.assertEqual(report.status, FinancialReport.Status.SUCCESS)
|
||||
|
||||
FNSReportService.mark_failed(report, "boom")
|
||||
report.refresh_from_db()
|
||||
self.assertEqual(report.status, report.Status.FAILED)
|
||||
self.assertEqual(report.error_message, "boom")
|
||||
self.assertEqual(report.status, FinancialReport.Status.FAILED)
|
||||
self.assertEqual(report.payload["error_message"], "boom")
|
||||
|
||||
Reference in New Issue
Block a user