#19 Tests
* adds tests for compensations (WIP) * refactors some dummy data generating into base test class * fixes bugs detected by testing * adds important requirements.txt change for itsdangerous package (<1.0.0 for compatibility to django-simple-sso)
This commit is contained in:
@@ -149,7 +149,7 @@ class BaseObject(BaseResource):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if hasattr(self, "users"):
|
||||
if isinstance(self, ShareableObject):
|
||||
return self.users.filter(id=user.id)
|
||||
else:
|
||||
return User.objects.none()
|
||||
|
||||
@@ -11,7 +11,11 @@ from django.contrib.auth.models import User, Group
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
|
||||
from compensation.models import Compensation
|
||||
from intervention.models import LegalData, ResponsibilityData, Intervention
|
||||
from konova.management.commands.setup_data import GROUPS_DATA
|
||||
from konova.models import Geometry
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
@@ -63,10 +67,14 @@ class BaseViewTestCase(BaseTestCase):
|
||||
|
||||
"""
|
||||
login_url = None
|
||||
intervention = None
|
||||
compensation = None
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.create_users()
|
||||
self.create_groups()
|
||||
self.create_dummy_intervention()
|
||||
self.create_dummy_compensation()
|
||||
self.login_url = reverse("simple-sso-login")
|
||||
|
||||
def assert_url_success(self, client: Client, urls: list):
|
||||
@@ -114,6 +122,61 @@ class BaseViewTestCase(BaseTestCase):
|
||||
response = client.get(url)
|
||||
self.assertEqual(response.status_code, 302, msg=f"Failed for {url}")
|
||||
|
||||
def create_dummy_intervention(self):
|
||||
""" Creates an intervention which can be used for tests
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Create dummy data
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.superuser,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
# Create legal data object (without M2M laws first)
|
||||
legal_data = LegalData.objects.create()
|
||||
# Create responsible data object
|
||||
responsibility_data = ResponsibilityData.objects.create()
|
||||
geometry = Geometry.objects.create()
|
||||
# Finally create main object, holding the other objects
|
||||
self.intervention = Intervention.objects.create(
|
||||
identifier="TEST",
|
||||
title="Test_title",
|
||||
responsible=responsibility_data,
|
||||
legal=legal_data,
|
||||
created=action,
|
||||
geometry=geometry,
|
||||
comment="Test",
|
||||
)
|
||||
self.intervention.generate_access_token(make_unique=True)
|
||||
|
||||
def create_dummy_compensation(self):
|
||||
""" Creates an intervention which can be used for tests
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if self.intervention is None:
|
||||
self.create_dummy_intervention()
|
||||
# Create dummy data
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.superuser,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
geometry = Geometry.objects.create()
|
||||
# Finally create main object, holding the other objects
|
||||
self.compensation = Compensation.objects.create(
|
||||
identifier="TEST",
|
||||
title="Test_title",
|
||||
intervention=self.intervention,
|
||||
created=action,
|
||||
geometry=geometry,
|
||||
comment="Test",
|
||||
)
|
||||
self.intervention.generate_access_token(make_unique=True)
|
||||
|
||||
|
||||
class KonovaViewTestCase(BaseViewTestCase):
|
||||
""" Holds tests for all regular views, which are not app specific
|
||||
|
||||
Reference in New Issue
Block a user