Implement exchange imports and frontend reporting APIs
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 3m50s
CI/CD Pipeline / Run Tests (push) Successful in 3m57s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped

This commit is contained in:
2026-04-07 16:31:04 +02:00
parent 76a86d0b20
commit 697ecb7d1c
155 changed files with 5604 additions and 346 deletions

View File

@@ -0,0 +1 @@
"""Tests for external data app."""

View File

@@ -0,0 +1,70 @@
"""Factories for external data models."""
import factory
from faker import Faker
from apps.external_data.models import (
ArbitrationCase,
IndustrialProduct,
ProsecutorCheck,
PublicProcurement,
)
from tests.apps.organization.factories import OrganizationFactory
fake = Faker("ru_RU")
class IndustrialProductFactory(factory.django.DjangoModelFactory):
class Meta:
model = IndustrialProduct
organization = factory.SubFactory(OrganizationFactory)
product_name = factory.LazyAttribute(lambda _: fake.sentence(nb_words=3))
product_class = "electronics"
okpd2_code = "26.51.53"
tnved_code = "9015.10"
registry_number = factory.Sequence(lambda n: f"{1000 + n}/2026")
class ProsecutorCheckFactory(factory.django.DjangoModelFactory):
class Meta:
model = ProsecutorCheck
organization = factory.SubFactory(OrganizationFactory)
registration_number = factory.Sequence(lambda n: f"{2_900_000_000 + n}")
law_type = "294_fz"
control_authority = "Центральное управление Ростехнадзора"
prosecutor_office = "Московская городская прокуратура"
start_date = factory.LazyAttribute(lambda _: fake.date_this_decade())
status = "planned"
class PublicProcurementFactory(factory.django.DjangoModelFactory):
class Meta:
model = PublicProcurement
organization = factory.SubFactory(OrganizationFactory)
purchase_number = factory.Sequence(lambda n: f"{37_310_000_000_000_0000 + n:019d}")
law_type = "44_fz"
status = "signing"
contract_amount = factory.LazyAttribute(
lambda _: fake.pydecimal(left_digits=8, right_digits=2, positive=True)
)
contract_date = factory.LazyAttribute(lambda _: fake.date_this_year())
execution_start_date = factory.LazyAttribute(lambda _: fake.date_this_year())
execution_end_date = factory.LazyAttribute(
lambda _: fake.date_between(start_date="+30d", end_date="+365d")
)
purchase_name = factory.LazyAttribute(lambda _: fake.sentence(nb_words=6))
class ArbitrationCaseFactory(factory.django.DjangoModelFactory):
class Meta:
model = ArbitrationCase
organization = factory.SubFactory(OrganizationFactory)
case_number = factory.Sequence(lambda n: f"А40-{16_000 + n}/2026")
court_name = "Арбитражный суд города Москвы"
party_role = "defendant"
status = "hearing_scheduled"
decision_date = factory.LazyAttribute(lambda _: fake.date_this_year())

View File

@@ -0,0 +1,91 @@
"""Tests for external data endpoints."""
from __future__ import annotations
from datetime import date
from django.test import override_settings
from rest_framework import status
from rest_framework.test import APITestCase
from tests.apps.external_data.factories import (
ArbitrationCaseFactory,
IndustrialProductFactory,
ProsecutorCheckFactory,
PublicProcurementFactory,
)
from tests.apps.organization.factories import OrganizationFactory
from tests.apps.user.factories import UserFactory
@override_settings(ROOT_URLCONF="core.urls")
class ExternalDataApiTest(APITestCase):
def setUp(self):
self.user = UserFactory.create_user()
self.client.force_authenticate(self.user)
self.organization = OrganizationFactory.create()
self.other_organization = OrganizationFactory.create()
def test_industrial_products_endpoint_uses_classic_pagination(self):
IndustrialProductFactory.create(
organization=self.organization,
product_name="Лазерные датчики расстояния",
)
IndustrialProductFactory.create(organization=self.other_organization)
response = self.client.get(
f"/api/v1/industrial-products/?organization={self.organization.id}&search=датчики"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn("results", response.data)
self.assertEqual(response.data["count"], 1)
self.assertEqual(
response.data["results"][0]["organization"], str(self.organization.id)
)
def test_prosecutor_checks_support_date_range_filters(self):
ProsecutorCheckFactory.create(
organization=self.organization,
law_type="294_fz",
start_date=date(2025, 1, 15),
)
ProsecutorCheckFactory.create(
organization=self.organization,
law_type="294_fz",
start_date=date(2023, 1, 15),
)
response = self.client.get(
f"/api/v1/prosecutor-checks/?organization={self.organization.id}"
"&law_type=294_fz&start_date_from=2024-01-01&start_date_to=2025-12-31"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 1)
def test_public_procurements_and_arbitration_cases_filters(self):
PublicProcurementFactory.create(
organization=self.organization,
law_type="44_fz",
contract_date=date(2025, 1, 15),
)
ArbitrationCaseFactory.create(
organization=self.organization,
party_role="defendant",
decision_date=date(2026, 1, 27),
)
procurement_response = self.client.get(
f"/api/v1/public-procurements/?organization={self.organization.id}"
"&law_type=44_fz&contract_date_from=2024-01-01&contract_date_to=2025-12-31"
)
arbitration_response = self.client.get(
f"/api/v1/arbitration-cases/?organization={self.organization.id}"
"&party_role=defendant&decision_date_from=2025-01-01&decision_date_to=2026-12-31"
)
self.assertEqual(procurement_response.status_code, status.HTTP_200_OK)
self.assertEqual(procurement_response.data["count"], 1)
self.assertEqual(arbitration_response.status_code, status.HTTP_200_OK)
self.assertEqual(arbitration_response.data["count"], 1)