From a7dc99eb52eee7b02f997391e0eb5541dad19517 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 2 Oct 2023 14:00:44 +0200 Subject: [PATCH] fix: unit test folder name used checking --- core/base_models.py | 11 ++++++++++- core/migrations/0018_alter_evidence_options.py | 17 +++++++++++++++++ iam/models.py | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 core/migrations/0018_alter_evidence_options.py diff --git a/core/base_models.py b/core/base_models.py index 17e3423..b0e37e0 100644 --- a/core/base_models.py +++ b/core/base_models.py @@ -17,7 +17,16 @@ class Meta: def __str__(self) -> str: return self.name - + + def clean(self) -> None: + scope = self.get_scope() + field_errors = {} + _fields_to_check = self.fields_to_check if hasattr(self, 'fields_to_check') else ['name'] + if not self.is_unique_in_scope(scope=scope, fields_to_check=_fields_to_check): + field_errors['name'] = _('This name is already in use.') + super().clean() + if field_errors: + raise ValidationError(field_errors) class AbstractBaseModel(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) diff --git a/core/migrations/0018_alter_evidence_options.py b/core/migrations/0018_alter_evidence_options.py new file mode 100644 index 0000000..fb0fa01 --- /dev/null +++ b/core/migrations/0018_alter_evidence_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.5 on 2023-10-02 11:51 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0017_remove_evidence_ref_url'), + ] + + operations = [ + migrations.AlterModelOptions( + name='evidence', + options={'verbose_name': 'Evidence', 'verbose_name_plural': 'Evidences'}, + ), + ] diff --git a/iam/models.py b/iam/models.py index 178c421..3491b66 100644 --- a/iam/models.py +++ b/iam/models.py @@ -82,7 +82,7 @@ def _get_root_folder(): return None -class Folder(AbstractBaseModel, I18nMixin, NameDescriptionMixin): +class Folder(I18nMixin, NameDescriptionMixin, AbstractBaseModel): """ A folder is a container for other folders or any object Folders are organized in a tree structure, with a single root folder Folders are the base perimeter for role assignments