Unit test EMA model
* adds unit test for EMA model
This commit is contained in:
parent
0f757a5de1
commit
21c7889551
@ -122,7 +122,7 @@ class EmaDocument(AbstractDocument):
|
|||||||
|
|
||||||
def delete(self, user=None, *args, **kwargs):
|
def delete(self, user=None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Custom delete functionality for EcoAccountDocuments.
|
Custom delete functionality for EmaDocuments.
|
||||||
Removes the folder from the file system if there are no further documents for this entry.
|
Removes the folder from the file system if there are no further documents for this entry.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -139,8 +139,11 @@ class EmaDocument(AbstractDocument):
|
|||||||
# The only file left for this EMA is the one which is currently processed and will be deleted
|
# The only file left for this EMA is the one which is currently processed and will be deleted
|
||||||
# Make sure that the compensation folder itself is deleted as well, not only the file
|
# Make sure that the compensation folder itself is deleted as well, not only the file
|
||||||
# Therefore take the folder path from the file path
|
# Therefore take the folder path from the file path
|
||||||
folder_path = self.file.path.split("/")[:-1]
|
try:
|
||||||
folder_path = "/".join(folder_path)
|
folder_path = self.file.path.split("/")[:-1]
|
||||||
|
folder_path = "/".join(folder_path)
|
||||||
|
except ValueError:
|
||||||
|
folder_path = None
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
||||||
|
@ -6,5 +6,5 @@ Created on: 19.08.21
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EMA_ACCOUNT_IDENTIFIER_LENGTH = 6
|
EMA_IDENTIFIER_LENGTH = 6
|
||||||
EMA_ACCOUNT_IDENTIFIER_TEMPLATE = "EMA-{}"
|
EMA_IDENTIFIER_TEMPLATE = "EMA-{}"
|
7
ema/tests/unit/__init__.py
Normal file
7
ema/tests/unit/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 24.08.23
|
||||||
|
|
||||||
|
"""
|
90
ema/tests/unit/test_models.py
Normal file
90
ema/tests/unit/test_models.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 24.08.23
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
from ema.models import Ema, EmaDocument
|
||||||
|
from ema.settings import EMA_IDENTIFIER_TEMPLATE
|
||||||
|
from konova.tests.test_views import BaseTestCase
|
||||||
|
from konova.utils.message_templates import DOCUMENT_REMOVED_TEMPLATE
|
||||||
|
from user.models import UserAction
|
||||||
|
|
||||||
|
|
||||||
|
class EmaModelTestCase(BaseTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_str(self):
|
||||||
|
self.assertEqual(str(self.ema), f"{self.ema.identifier}")
|
||||||
|
|
||||||
|
def test_save(self):
|
||||||
|
new_ema = Ema(
|
||||||
|
title="Test"
|
||||||
|
)
|
||||||
|
self.assertIsNone(new_ema.identifier)
|
||||||
|
|
||||||
|
new_ema.save()
|
||||||
|
new_ema.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertIsNotNone(new_ema.identifier)
|
||||||
|
self.assertIn("EMA-", new_ema.identifier)
|
||||||
|
|
||||||
|
def test_is_ready_for_publish(self):
|
||||||
|
self.assertIsNone(self.ema.recorded)
|
||||||
|
self.assertFalse(self.ema.is_ready_for_publish())
|
||||||
|
|
||||||
|
self.ema.set_recorded(self.superuser)
|
||||||
|
self.ema.refresh_from_db()
|
||||||
|
self.assertIsNotNone(self.ema.recorded)
|
||||||
|
self.assertTrue(self.ema.is_ready_for_publish())
|
||||||
|
|
||||||
|
def test_get_share_link(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.ema.get_share_link(),
|
||||||
|
reverse("ema:share-token", args=(self.ema.id, self.ema.access_token))
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_get_documents(self):
|
||||||
|
self.assertEqual(self.ema.get_documents().count(), 0)
|
||||||
|
|
||||||
|
doc = EmaDocument(
|
||||||
|
instance=self.ema,
|
||||||
|
date_of_creation=now().date(),
|
||||||
|
comment="Test",
|
||||||
|
)
|
||||||
|
doc.save()
|
||||||
|
docs = self.ema.get_documents()
|
||||||
|
self.assertEqual(docs.count(), 1)
|
||||||
|
self.assertEqual(docs.first(), doc)
|
||||||
|
|
||||||
|
|
||||||
|
class EmaDocumentModelTestCase(BaseTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
doc = EmaDocument.objects.create(
|
||||||
|
date_of_creation=now().date(),
|
||||||
|
instance=self.ema,
|
||||||
|
comment="TEST"
|
||||||
|
)
|
||||||
|
self.ema.refresh_from_db()
|
||||||
|
docs = self.ema.get_documents()
|
||||||
|
self.assertEqual(docs.count(), 1)
|
||||||
|
self.assertEqual(docs.first(), doc)
|
||||||
|
|
||||||
|
doc_title = doc.title
|
||||||
|
doc.delete(user=self.superuser)
|
||||||
|
last_log = self.ema.log.first()
|
||||||
|
self.assertEqual(last_log.action, UserAction.EDITED)
|
||||||
|
self.assertEqual(last_log.user, self.superuser)
|
||||||
|
self.assertEqual(last_log.comment, DOCUMENT_REMOVED_TEMPLATE.format(doc_title))
|
||||||
|
|
||||||
|
docs = self.ema.get_documents()
|
||||||
|
self.assertEqual(docs.count(), 0)
|
||||||
|
|
@ -25,7 +25,7 @@ from django.utils.timezone import now
|
|||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH, \
|
from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH, \
|
||||||
ECO_ACCOUNT_IDENTIFIER_TEMPLATE, ECO_ACCOUNT_IDENTIFIER_LENGTH
|
ECO_ACCOUNT_IDENTIFIER_TEMPLATE, ECO_ACCOUNT_IDENTIFIER_LENGTH
|
||||||
from ema.settings import EMA_ACCOUNT_IDENTIFIER_LENGTH, EMA_ACCOUNT_IDENTIFIER_TEMPLATE
|
from ema.settings import EMA_IDENTIFIER_LENGTH, EMA_IDENTIFIER_TEMPLATE
|
||||||
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
|
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
|
||||||
from konova.utils import generators
|
from konova.utils import generators
|
||||||
from konova.utils.generators import generate_random_string
|
from konova.utils.generators import generate_random_string
|
||||||
@ -211,8 +211,8 @@ class BaseObject(BaseResource, DeletableObjectMixin):
|
|||||||
"template": ECO_ACCOUNT_IDENTIFIER_TEMPLATE,
|
"template": ECO_ACCOUNT_IDENTIFIER_TEMPLATE,
|
||||||
},
|
},
|
||||||
Ema: {
|
Ema: {
|
||||||
"length": EMA_ACCOUNT_IDENTIFIER_LENGTH,
|
"length": EMA_IDENTIFIER_LENGTH,
|
||||||
"template": EMA_ACCOUNT_IDENTIFIER_TEMPLATE,
|
"template": EMA_IDENTIFIER_TEMPLATE,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user