Unit test analysis
* adds unit test for creating report * fixes bug where new (>2018) eco accounts have not been fetched correctly from the db * adds enhancements in the frontend * improves test data setuppull/347/head
parent
345b266422
commit
d9cf9669f0
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 15.08.23
|
||||||
|
|
||||||
|
"""
|
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 15.08.23
|
||||||
|
|
||||||
|
"""
|
@ -0,0 +1,47 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 15.08.23
|
||||||
|
|
||||||
|
"""
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from analysis.forms import TimespanReportForm
|
||||||
|
from konova.tests.test_views import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSpanReportFormTestCase(BaseTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
eiv = self.create_dummy_intervention()
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
form = TimespanReportForm()
|
||||||
|
self.assertEqual(form.form_title, str(_("Generate report")))
|
||||||
|
self.assertEqual(form.form_caption, str(_("Select a timespan and the desired conservation office") ))
|
||||||
|
self.assertEqual(form.action_url, reverse("analysis:reports"))
|
||||||
|
self.assertFalse(form.show_cancel_btn)
|
||||||
|
self.assertEqual(form.action_btn_label, str(_("Continue")))
|
||||||
|
|
||||||
|
def test_save(self):
|
||||||
|
date_from = now().date() - timedelta(days=365)
|
||||||
|
date_to = now().date()
|
||||||
|
office = self.get_conservation_office_code()
|
||||||
|
data = {
|
||||||
|
"date_from": date_from,
|
||||||
|
"date_to": date_to,
|
||||||
|
"conservation_office": office,
|
||||||
|
}
|
||||||
|
form = TimespanReportForm(data)
|
||||||
|
self.assertTrue(form.is_valid(), msg=f"{form.errors}")
|
||||||
|
|
||||||
|
detail_report_url = form.save()
|
||||||
|
self.assertEqual(
|
||||||
|
detail_report_url,
|
||||||
|
reverse("analysis:report-detail", args=(office.id,)) + f"?df={date_from}&dt={date_to}"
|
||||||
|
)
|
@ -0,0 +1,94 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 17.08.23
|
||||||
|
|
||||||
|
"""
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
from analysis.settings import LKOMPVZVO_PUBLISH_DATE
|
||||||
|
from analysis.utils.report import TimespanReport
|
||||||
|
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||||
|
from konova.tests.test_views import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSpanReportTestCase(BaseTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
today = now().date()
|
||||||
|
old_date = LKOMPVZVO_PUBLISH_DATE - timedelta(days=1)
|
||||||
|
|
||||||
|
self.conservation_office = self.get_conservation_office_code()
|
||||||
|
self.eiv_old = self.create_dummy_intervention()
|
||||||
|
self.kom_old = self.create_dummy_compensation(interv=self.eiv_old)
|
||||||
|
self.assertNotEqual(self.compensation.intervention, self.kom_old.intervention)
|
||||||
|
self.eiv = self.compensation.intervention
|
||||||
|
self.oek_old = self.create_dummy_eco_account()
|
||||||
|
|
||||||
|
self.eiv_old.responsible.conservation_office = self.conservation_office
|
||||||
|
self.eiv_old.legal.binding_date = old_date
|
||||||
|
self.eiv_old.legal.registration_date = old_date
|
||||||
|
|
||||||
|
self.eiv.responsible.conservation_office = self.conservation_office
|
||||||
|
self.eiv.legal.binding_date = today
|
||||||
|
self.eiv.legal.registration_date = today
|
||||||
|
|
||||||
|
self.eco_account.responsible.conservation_office = self.conservation_office
|
||||||
|
self.eco_account.legal.registration_date = today
|
||||||
|
self.eco_account.legal.binding_date = today
|
||||||
|
|
||||||
|
self.oek_old.responsible.conservation_office = self.conservation_office
|
||||||
|
self.oek_old.legal.registration_date = old_date
|
||||||
|
self.oek_old.legal.binding_date = old_date
|
||||||
|
|
||||||
|
self.eiv.legal.save()
|
||||||
|
self.eiv.responsible.save()
|
||||||
|
|
||||||
|
self.eiv_old.legal.save()
|
||||||
|
self.eiv_old.responsible.save()
|
||||||
|
|
||||||
|
self.eco_account.legal.save()
|
||||||
|
self.eco_account.responsible.save()
|
||||||
|
|
||||||
|
self.oek_old.legal.save()
|
||||||
|
self.oek_old.responsible.save()
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
date_from = now().date() - timedelta(days=365)
|
||||||
|
date_to = now().date()
|
||||||
|
report = TimespanReport(self.conservation_office.id, date_from, date_to)
|
||||||
|
|
||||||
|
self.assertEqual(report.office_id, self.conservation_office.id)
|
||||||
|
self.assertEqual(report.date_from, date_from)
|
||||||
|
self.assertEqual(report.date_to, date_to)
|
||||||
|
|
||||||
|
self.assertIsNotNone(report.intervention_report)
|
||||||
|
self.assertIsNotNone(report.compensation_report)
|
||||||
|
self.assertIsNotNone(report.eco_account_report)
|
||||||
|
self.assertIsNotNone(report.old_data_report)
|
||||||
|
|
||||||
|
self.assertEqual(report.excel_map["date_from"], date_from.strftime(DEFAULT_DATE_FORMAT))
|
||||||
|
self.assertEqual(report.excel_map["date_to"], date_to.strftime(DEFAULT_DATE_FORMAT))
|
||||||
|
|
||||||
|
self.assertEqual(report.old_data_report.queryset_intervention_count, 1)
|
||||||
|
self.assertEqual(report.old_data_report.queryset_intervention_recorded_count, 0)
|
||||||
|
self.assertEqual(report.old_data_report.queryset_comps_count, 1)
|
||||||
|
self.assertEqual(report.old_data_report.queryset_acc_count, 1)
|
||||||
|
self.assertEqual(report.old_data_report.queryset_acc_recorded_count, 0)
|
||||||
|
|
||||||
|
self.assertEqual(report.intervention_report.queryset_count, 1)
|
||||||
|
self.assertEqual(report.intervention_report.queryset_checked_count, 0)
|
||||||
|
self.assertEqual(report.intervention_report.queryset_recorded_count, 0)
|
||||||
|
|
||||||
|
self.assertEqual(report.compensation_report.queryset_count, 1)
|
||||||
|
self.assertEqual(report.compensation_report.queryset_checked_count, 0)
|
||||||
|
self.assertEqual(report.compensation_report.queryset_recorded_count, 0)
|
||||||
|
|
||||||
|
self.assertEqual(report.eco_account_report.queryset_count, 1)
|
||||||
|
self.assertEqual(report.eco_account_report.queryset_recorded_count, 0)
|
||||||
|
self.assertEqual(report.eco_account_report.queryset_deductions_count, 1)
|
||||||
|
self.assertEqual(report.eco_account_report.queryset_deductions_recorded_count, 0)
|
Binary file not shown.
Loading…
Reference in New Issue