parent
667f378b74
commit
50e134ba91
@ -10,7 +10,7 @@ import datetime
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import Compensation
|
from compensation.models import Compensation
|
||||||
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
|
from konova.settings import ETS_GROUP, ZB_GROUP
|
||||||
from konova.tests.test_views import BaseWorkflowTestCase
|
from konova.tests.test_views import BaseWorkflowTestCase
|
||||||
from user.models import UserAction
|
from user.models import UserAction
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
cls.intervention.compensations.set([cls.compensation])
|
cls.intervention.compensations.set([cls.compensation])
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
# Delete all existing compensations, which might be created by tests
|
# Delete all existing compensations, which might be created by tests
|
||||||
Compensation.objects.all().delete()
|
Compensation.objects.all().delete()
|
||||||
|
|
||||||
@ -133,3 +134,61 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
# Expect the user action to be in the log
|
# Expect the user action to be in the log
|
||||||
self.assertIn(recorded, self.compensation.log.all())
|
self.assertIn(recorded, self.compensation.log.all())
|
||||||
|
|
||||||
|
|
||||||
|
class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
# Add user to conservation office group and give shared access to the account
|
||||||
|
cls.superuser.groups.add(cls.groups.get(name=ETS_GROUP))
|
||||||
|
cls.eco_account.users.set([cls.superuser])
|
||||||
|
|
||||||
|
def test_deductability(self):
|
||||||
|
"""
|
||||||
|
This tests the deductability of an eco account.
|
||||||
|
|
||||||
|
An eco account should only be deductible if it is recorded.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Give user shared access to the dummy intervention, which will be needed here
|
||||||
|
self.intervention.users.add(self.superuser)
|
||||||
|
|
||||||
|
# Prepare data for deduction creation
|
||||||
|
deduct_url = reverse("compensation:acc-new-deduction", args=(self.eco_account.id,))
|
||||||
|
test_surface = 10.00
|
||||||
|
post_data = {
|
||||||
|
"surface": test_surface,
|
||||||
|
"account": self.id,
|
||||||
|
"intervention": self.intervention.id,
|
||||||
|
}
|
||||||
|
# Perform request --> expect to fail
|
||||||
|
self.client_user.post(deduct_url, post_data)
|
||||||
|
|
||||||
|
# Expect that no deduction has been created
|
||||||
|
self.assertEqual(0, self.eco_account.deductions.count())
|
||||||
|
self.assertEqual(0, self.intervention.deductions.count())
|
||||||
|
|
||||||
|
# Now mock the eco account as it would be recorded (with invalid data)
|
||||||
|
# Make sure the deductible surface is high enough for the request
|
||||||
|
self.eco_account.toggle_recorded(self.superuser)
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
self.eco_account.deductable_surface = test_surface + 1.00
|
||||||
|
self.eco_account.save()
|
||||||
|
self.assertIsNotNone(self.eco_account.recorded)
|
||||||
|
self.assertGreater(self.eco_account.deductable_surface, test_surface)
|
||||||
|
|
||||||
|
# Rerun the request
|
||||||
|
self.client_user.post(deduct_url, post_data)
|
||||||
|
|
||||||
|
# Expect that the deduction has been created
|
||||||
|
self.assertEqual(1, self.eco_account.deductions.count())
|
||||||
|
self.assertEqual(1, self.intervention.deductions.count())
|
||||||
|
deduction = self.eco_account.deductions.first()
|
||||||
|
self.assertEqual(deduction.surface, test_surface)
|
||||||
|
self.assertEqual(deduction.account, self.eco_account)
|
||||||
|
self.assertEqual(deduction.intervention, self.intervention)
|
||||||
|
|
||||||
|
|
||||||
|
@ -431,11 +431,6 @@ class BaseWorkflowTestCase(BaseTestCase):
|
|||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
super().setUpTestData()
|
super().setUpTestData()
|
||||||
|
|
||||||
# Create logged in client and a non-logged in client (anon)
|
|
||||||
cls.client_user = Client()
|
|
||||||
cls.client_user.login(username=cls.superuser.username, password=cls.superuser_pw)
|
|
||||||
cls.client_anon = Client()
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
""" Setup data before each test run
|
""" Setup data before each test run
|
||||||
|
|
||||||
@ -446,6 +441,11 @@ class BaseWorkflowTestCase(BaseTestCase):
|
|||||||
default_group = self.groups.get(name=DEFAULT_GROUP)
|
default_group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
self.superuser.groups.set([default_group])
|
self.superuser.groups.set([default_group])
|
||||||
|
|
||||||
|
# Create fresh logged in client and a non-logged in client (anon) for each test
|
||||||
|
self.client_user = Client()
|
||||||
|
self.client_user.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.client_anon = Client()
|
||||||
|
|
||||||
def assert_object_is_deleted(self, obj):
|
def assert_object_is_deleted(self, obj):
|
||||||
""" Provides a quick check whether an object has been removed from the database or not
|
""" Provides a quick check whether an object has been removed from the database or not
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user