feat: add test finance history
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 32s
CI/CD Pipeline / Build and Push Images (push) Successful in 21s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 34s

This commit is contained in:
2026-08-09 13:47:25 +02:00
parent 661e857f53
commit 27768edcea
2 changed files with 132 additions and 38 deletions

View File

@@ -24,7 +24,10 @@ from organizations.models import (
OrganizationSourceRecord,
SourceGroup,
)
from organizations.test_companies import TEST_RECORD_PREFIX
from organizations.test_companies import (
TEST_FINANCIAL_HISTORY_YEARS,
TEST_RECORD_PREFIX,
)
TEST_EXCHANGE_TOKEN = "test-exchange-token" # noqa: S105
@@ -89,7 +92,14 @@ class TestCompaniesCommandsTest(TestCase):
OrganizationSourceFinancialLine.objects.filter(
source_record__extension__organization__in=companies
).count(),
20 * 4,
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
)
current_year = timezone.localdate().year
expected_financial_years = set(
range(
current_year - TEST_FINANCIAL_HISTORY_YEARS + 1,
current_year + 1,
)
)
self.assertEqual(
set(
@@ -97,7 +107,7 @@ class TestCompaniesCommandsTest(TestCase):
source_record__extension__organization__in=companies
).values_list("year", flat=True)
),
{timezone.localdate().year},
expected_financial_years,
)
self.assertEqual(IndustrialCertificateRecord.objects.count(), 20)
self.assertEqual(IndustrialProductRecord.objects.count(), 20)
@@ -112,10 +122,13 @@ class TestCompaniesCommandsTest(TestCase):
for index in range(1, 21)
},
)
self.assertEqual(FinancialReportLine.objects.count(), 20 * 4)
self.assertEqual(
FinancialReportLine.objects.count(),
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
)
self.assertEqual(
set(FinancialReportLine.objects.values_list("year", flat=True)),
{timezone.localdate().year},
expected_financial_years,
)
self.assertEqual(GenericParserRecord.objects.count(), 20 * 9)
@@ -142,6 +155,29 @@ class TestCompaniesCommandsTest(TestCase):
)
financial_report.external_id = "test-company-01"
financial_report.save(update_fields=["external_id"])
fns_record = OrganizationSourceRecord.objects.get(
extension__organization=first_company,
source=ParserLoadLog.Source.FNS_REPORTS,
)
stale_year = timezone.localdate().year - TEST_FINANCIAL_HISTORY_YEARS
OrganizationSourceFinancialLine.objects.create(
source_record=fns_record,
form_code="1",
line_code="1600",
line_name="Устаревший баланс",
year=stale_year,
period_start=1,
period_end=2,
)
FinancialReportLine.objects.create(
report=financial_report,
form_code="1",
line_code="1600",
line_name="Устаревший баланс",
year=stale_year,
period_start=1,
period_end=2,
)
call_command("create_test_companies", stdout=StringIO())
@@ -163,6 +199,18 @@ class TestCompaniesCommandsTest(TestCase):
financial_report.external_id,
f"{TEST_RECORD_PREFIX}:01:{ParserLoadLog.Source.FNS_REPORTS}",
)
self.assertFalse(
OrganizationSourceFinancialLine.objects.filter(
source_record=fns_record,
year=stale_year,
).exists()
)
self.assertFalse(
FinancialReportLine.objects.filter(
report=financial_report,
year=stale_year,
).exists()
)
self.assertEqual(OrganizationSourceRecord.objects.count(), 20 * 15)
@override_settings(STATE_CORP_EXCHANGE_TOKEN=TEST_EXCHANGE_TOKEN)
@@ -200,14 +248,22 @@ class TestCompaniesCommandsTest(TestCase):
},
)
self.assertEqual(len(reports), 20)
self.assertEqual(sum(len(report["lines"]) for report in reports), 80)
self.assertEqual(
sum(len(report["lines"]) for report in reports),
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
)
self.assertEqual(
{
line["year"]
for report in reports
for line in report["lines"]
},
{timezone.localdate().year},
set(
range(
timezone.localdate().year - TEST_FINANCIAL_HISTORY_YEARS + 1,
timezone.localdate().year + 1,
)
),
)
def test_delete_removes_only_the_fixed_twenty_companies(self):