fix: collect enabled sources weekly including Checko
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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.checko_collection import claim_weekly_collection, finish_collection
|
||||
from apps.parsers.models import CheckoCollectionAttempt
|
||||
from django.test import TestCase
|
||||
|
||||
@@ -18,24 +18,24 @@ class CheckoCollectionClaimTest(TestCase):
|
||||
mn_okpo="12345678",
|
||||
)
|
||||
|
||||
def test_claim_is_unique_per_organization_source_and_calendar_month(self):
|
||||
first = claim_monthly_collection(
|
||||
def test_claim_is_unique_per_organization_source_and_calendar_week(self):
|
||||
first = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 7, 1),
|
||||
at=date(2026, 7, 25),
|
||||
)
|
||||
|
||||
duplicate = claim_monthly_collection(
|
||||
duplicate = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 7, 31),
|
||||
)
|
||||
other_source = claim_monthly_collection(
|
||||
other_source = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.INSPECTIONS,
|
||||
at=date(2026, 7, 31),
|
||||
)
|
||||
next_month = claim_monthly_collection(
|
||||
next_month = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.ARBITRATION,
|
||||
at=date(2026, 8, 1),
|
||||
@@ -46,8 +46,8 @@ class CheckoCollectionClaimTest(TestCase):
|
||||
self.assertIsNotNone(other_source)
|
||||
self.assertIsNotNone(next_month)
|
||||
|
||||
def test_failed_attempt_keeps_monthly_claim(self):
|
||||
attempt = claim_monthly_collection(
|
||||
def test_failed_attempt_keeps_weekly_claim(self):
|
||||
attempt = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.CONTRACTS,
|
||||
at=date(2026, 7, 19),
|
||||
@@ -55,7 +55,7 @@ class CheckoCollectionClaimTest(TestCase):
|
||||
assert attempt is not None
|
||||
finish_collection(attempt, records_count=0, error="quota exhausted")
|
||||
|
||||
repeated = claim_monthly_collection(
|
||||
repeated = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.CONTRACTS,
|
||||
at=date(2026, 7, 20),
|
||||
@@ -78,7 +78,7 @@ class CheckoCollectionClaimTest(TestCase):
|
||||
)
|
||||
second.opk_registry_membership = True
|
||||
second.save(update_fields=["opk_registry_membership"])
|
||||
claimed = claim_monthly_collection(
|
||||
claimed = claim_weekly_collection(
|
||||
organization_id=str(self.organization.id),
|
||||
source=CheckoCollectionAttempt.Source.INSPECTIONS,
|
||||
)
|
||||
@@ -115,3 +115,15 @@ class CheckoCollectionClaimTest(TestCase):
|
||||
[target.organization_id for target in targets],
|
||||
[str(self.organization.id)],
|
||||
)
|
||||
|
||||
|
||||
def test_week_boundary_uses_moscow_saturday():
|
||||
from datetime import datetime, timezone
|
||||
from apps.parsers.checko_collection import collection_period_week
|
||||
|
||||
assert collection_period_week(
|
||||
datetime(2026, 10, 30, 20, 59, tzinfo=timezone.utc)
|
||||
) == date(2026, 10, 24)
|
||||
assert collection_period_week(
|
||||
datetime(2026, 10, 30, 21, 0, tzinfo=timezone.utc)
|
||||
) == date(2026, 10, 31)
|
||||
|
||||
Reference in New Issue
Block a user