Unit test intervention forms
* adds unit test for new/edit intervention forms * improves code base for generating new identifiers
This commit is contained in:
@@ -143,6 +143,9 @@ class BaseObject(BaseResource, DeletableObjectMixin):
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
log = models.ManyToManyField("user.UserActionLogEntry", blank=True, help_text="Keeps all user actions of an object", editable=False)
|
||||
|
||||
identifier_length = 6 # Fallback - specified in inheriting classes
|
||||
identifier_template = "UNBEKANNT-{}" # Fallback - specified in inheriting classes
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@@ -193,32 +196,8 @@ class BaseObject(BaseResource, DeletableObjectMixin):
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from intervention.models import Intervention
|
||||
from ema.models import Ema
|
||||
|
||||
definitions = {
|
||||
Intervention: {
|
||||
"length": INTERVENTION_IDENTIFIER_LENGTH,
|
||||
"template": INTERVENTION_IDENTIFIER_TEMPLATE,
|
||||
},
|
||||
Compensation: {
|
||||
"length": COMPENSATION_IDENTIFIER_LENGTH,
|
||||
"template": COMPENSATION_IDENTIFIER_TEMPLATE,
|
||||
},
|
||||
EcoAccount: {
|
||||
"length": ECO_ACCOUNT_IDENTIFIER_LENGTH,
|
||||
"template": ECO_ACCOUNT_IDENTIFIER_TEMPLATE,
|
||||
},
|
||||
Ema: {
|
||||
"length": EMA_IDENTIFIER_LENGTH,
|
||||
"template": EMA_IDENTIFIER_TEMPLATE,
|
||||
},
|
||||
}
|
||||
|
||||
if self.__class__ not in definitions:
|
||||
# Not defined, yet. Create fallback identifier for this case
|
||||
return generate_random_string(10)
|
||||
id_len = self.identifier_length
|
||||
id_template = self.identifier_template
|
||||
|
||||
_now = now()
|
||||
curr_month = _now.month
|
||||
@@ -229,13 +208,13 @@ class BaseObject(BaseResource, DeletableObjectMixin):
|
||||
curr_month = str(curr_month)
|
||||
curr_year = str(_now.year)
|
||||
rand_str = generate_random_string(
|
||||
length=definitions[self.__class__]["length"],
|
||||
length=id_len,
|
||||
use_numbers=True,
|
||||
use_letters_lc=False,
|
||||
use_letters_uc=True,
|
||||
)
|
||||
_str = "{}{}-{}".format(curr_month, curr_year, rand_str)
|
||||
return definitions[self.__class__]["template"].format(_str)
|
||||
return id_template.format(_str)
|
||||
|
||||
@abstractmethod
|
||||
def get_detail_url(self):
|
||||
|
||||
Reference in New Issue
Block a user