feat: add test finance history
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user