feat: address QA feedback and limit Checko collection
This commit is contained in:
92
tests/apps/parsers/test_checko_collection.py
Normal file
92
tests/apps/parsers/test_checko_collection.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from datetime import date
|
||||
|
||||
from apps.parsers import tasks as parser_tasks
|
||||
from apps.parsers.checko_collection import claim_monthly_collection, finish_collection
|
||||
from apps.parsers.models import CheckoCollectionAttempt
|
||||
from django.test import TestCase
|
||||
|
||||
from tests.apps.parsers.organization_helpers import create_directory_organization
|
||||
|
||||
|
||||
class CheckoCollectionClaimTest(TestCase):
|
||||
def setUp(self):
|
||||
self.organization = create_directory_organization(
|
||||
pn_name='ООО "Месячный лимит"',
|
||||
mn_ogrn=1027700000199,
|
||||
mn_inn=7701000199,
|
||||
in_kpp=770101001,
|
||||
mn_okpo="12345678",
|
||||
)
|
||||
|
||||
def test_claim_is_unique_per_organization_source_and_calendar_month(self):
|
||||
first = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 7, 1),
|
||||
)
|
||||
|
||||
duplicate = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 7, 31),
|
||||
)
|
||||
other_source = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.INSPECTIONS,
|
||||
at=date(2026, 7, 31),
|
||||
)
|
||||
next_month = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 8, 1),
|
||||
)
|
||||
|
||||
self.assertIsNotNone(first)
|
||||
self.assertIsNone(duplicate)
|
||||
self.assertIsNotNone(other_source)
|
||||
self.assertIsNotNone(next_month)
|
||||
|
||||
def test_failed_attempt_keeps_monthly_claim(self):
|
||||
attempt = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.CONTRACTS,
|
||||
at=date(2026, 7, 19),
|
||||
)
|
||||
assert attempt is not None
|
||||
finish_collection(attempt, records_count=0, error="quota exhausted")
|
||||
|
||||
repeated = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.CONTRACTS,
|
||||
at=date(2026, 7, 20),
|
||||
)
|
||||
|
||||
attempt.refresh_from_db()
|
||||
self.assertIsNone(repeated)
|
||||
self.assertEqual(attempt.status, CheckoCollectionAttempt.Status.FAILED)
|
||||
self.assertEqual(attempt.error_message, "quota exhausted")
|
||||
|
||||
def test_due_filter_is_applied_before_lookup_limit(self):
|
||||
self.organization.opk_registry_membership = True
|
||||
self.organization.save(update_fields=["opk_registry_membership"])
|
||||
second = create_directory_organization(
|
||||
pn_name='ООО "Следующая организация"',
|
||||
mn_ogrn=1027700000299,
|
||||
mn_inn=7701000299,
|
||||
in_kpp=770101001,
|
||||
mn_okpo="87654321",
|
||||
)
|
||||
second.opk_registry_membership = True
|
||||
second.save(update_fields=["opk_registry_membership"])
|
||||
claimed = claim_monthly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.INSPECTIONS,
|
||||
)
|
||||
self.assertIsNotNone(claimed)
|
||||
|
||||
targets = parser_tasks._active_registry_lookup_targets(
|
||||
limit=1,
|
||||
checko_source=CheckoCollectionAttempt.Source.INSPECTIONS,
|
||||
)
|
||||
|
||||
self.assertEqual([target.organization_id for target in targets], [str(second.id)])
|
||||
@@ -33,6 +33,7 @@ from apps.parsers.clients.minpromtorg.manufactures import (
|
||||
from apps.parsers.clients.proverki.client import ProverkiClientError
|
||||
from apps.parsers.clients.zakupki import ZakupkiClientError
|
||||
from apps.parsers.models import (
|
||||
CheckoCollectionAttempt,
|
||||
FinancialReport,
|
||||
ParserLoadLog,
|
||||
)
|
||||
@@ -316,6 +317,12 @@ class CheckoFedresursFallbackControlFlowTestCase(SimpleTestCase):
|
||||
return_value=targets,
|
||||
),
|
||||
patch.object(parser_tasks, "CheckoClient", _RateLimitedCheckoClient),
|
||||
patch.object(
|
||||
parser_tasks,
|
||||
"claim_monthly_collection",
|
||||
return_value=SimpleNamespace(),
|
||||
),
|
||||
patch.object(parser_tasks, "finish_collection"),
|
||||
):
|
||||
records = parser_tasks._fetch_checko_bankruptcy_records(proxies=None)
|
||||
|
||||
@@ -801,6 +808,15 @@ class GenericSourceFetchTestCase(TestCase):
|
||||
[request.inn for request in _CheckoClient.instances[0].requests],
|
||||
[str(organization.mn_inn)],
|
||||
)
|
||||
second_result = parser_tasks.parse_arbitration_cases(limit=10, proxies=[])
|
||||
self.assertEqual(second_result["status"], "skipped")
|
||||
self.assertEqual(len(_CheckoClient.instances), 1)
|
||||
attempt = CheckoCollectionAttempt.objects.get(
|
||||
organization_id=organization.id,
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
)
|
||||
self.assertEqual(attempt.status, CheckoCollectionAttempt.Status.SUCCESS)
|
||||
self.assertEqual(attempt.records_count, 1)
|
||||
|
||||
@override_settings(CHECKO_API_KEY="test-key")
|
||||
def test_arbitration_skips_when_no_active_registry_organizations(self):
|
||||
@@ -1842,11 +1858,13 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
"parse_procurements_44fz",
|
||||
"parse_procurements_223fz",
|
||||
"parse_contracts",
|
||||
"parse_registry_contracts",
|
||||
"parse_unfair_suppliers",
|
||||
"parse_fas_goz_evasion",
|
||||
"sync_fns_financial_reports",
|
||||
"parse_arbitration_cases",
|
||||
"parse_fedresurs_bankruptcy",
|
||||
"parse_registry_inspections",
|
||||
"parse_fstec_registers",
|
||||
"parse_trudvsem_vacancies",
|
||||
)
|
||||
@@ -1869,6 +1887,8 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
"sync_fns_financial_reports-id",
|
||||
)
|
||||
delays["sync_fns_financial_reports"].assert_called_once_with(proxies=[])
|
||||
delays["parse_registry_contracts"].assert_called_once_with(proxies=[])
|
||||
delays["parse_registry_inspections"].assert_called_once_with(proxies=[])
|
||||
|
||||
def test_parse_all_minpromtorg_without_adapter(self):
|
||||
with TestHTTPServer() as server:
|
||||
|
||||
Reference in New Issue
Block a user