Unit test user app
* adds unit test for User model and forms * refactors functions from user_checks.py into User class and drops user_checks.py
This commit is contained in:
@@ -640,12 +640,11 @@ class ShareableObjectMixin(models.Model):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
from konova.utils.user_checks import is_default_group_only
|
||||
users = self.shared_users
|
||||
cleaned_users = []
|
||||
default_users = []
|
||||
for user in users:
|
||||
if not is_default_group_only(user):
|
||||
if not user.is_default_group_only():
|
||||
cleaned_users.append(user)
|
||||
else:
|
||||
default_users.append(user)
|
||||
|
||||
@@ -6,12 +6,12 @@ Created on: 08.09.23
|
||||
|
||||
"""
|
||||
from django.test import RequestFactory
|
||||
from django.utils.timezone import now
|
||||
|
||||
from intervention.forms.modals.share import ShareModalForm
|
||||
from konova.models import DeadlineType
|
||||
from konova.models import DeadlineType, Resubmission
|
||||
from konova.settings import ZB_GROUP
|
||||
from konova.tests.test_views import BaseTestCase
|
||||
from konova.utils.user_checks import is_default_group_only
|
||||
from user.models import UserAction
|
||||
|
||||
|
||||
@@ -171,8 +171,8 @@ class ShareableObjectMixinTestCase(BaseTestCase):
|
||||
self.intervention.share_with_user(self.user)
|
||||
self.intervention.share_with_user(self.superuser)
|
||||
|
||||
self.assertTrue(is_default_group_only(self.user))
|
||||
self.assertFalse(is_default_group_only(self.superuser))
|
||||
self.assertTrue(self.user.is_default_group_only())
|
||||
self.assertFalse(self.superuser.is_default_group_only())
|
||||
|
||||
self.assertTrue(self.intervention.is_shared_with(self.user))
|
||||
self.assertTrue(self.intervention.is_shared_with(self.superuser))
|
||||
@@ -180,3 +180,22 @@ class ShareableObjectMixinTestCase(BaseTestCase):
|
||||
self.intervention.unshare_with_default_users()
|
||||
self.assertFalse(self.intervention.is_shared_with(self.user))
|
||||
self.assertTrue(self.intervention.is_shared_with(self.superuser))
|
||||
|
||||
|
||||
class ResubmissionTestCase(BaseTestCase):
|
||||
def test_send_resubmission_mail(self):
|
||||
resubmission = Resubmission.objects.create(
|
||||
user=self.user,
|
||||
resubmit_on=now().date(),
|
||||
comment="Test",
|
||||
)
|
||||
self.intervention.resubmissions.add(resubmission)
|
||||
|
||||
self.assertFalse(resubmission.resubmission_sent)
|
||||
resubmission.send_resubmission_mail(
|
||||
self.intervention.identifier,
|
||||
[
|
||||
"Test_municipal_1"
|
||||
],
|
||||
)
|
||||
self.assertTrue(resubmission.resubmission_sent)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 02.07.21
|
||||
|
||||
"""
|
||||
from user.models import User
|
||||
|
||||
from konova.settings import ETS_GROUP, ZB_GROUP
|
||||
|
||||
|
||||
def in_group(user: User, group: str) -> bool:
|
||||
""" Checks if the user is part of a group
|
||||
|
||||
Args:
|
||||
user (User): The user object
|
||||
group (str): The group's name
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
return user.groups.filter(
|
||||
name=group
|
||||
)
|
||||
|
||||
|
||||
def is_default_group_only(user: User) -> bool:
|
||||
""" Checks if the user is only part of the default group
|
||||
|
||||
Args:
|
||||
user (User): The user object
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
return not in_group(user, ZB_GROUP) and not in_group(user, ETS_GROUP)
|
||||
Reference in New Issue
Block a user