Fix GitLab issue #250 "Empty optional lookup metadata trigger validation error". Thanks to LeVon Smoker for the find and for the proposed fix.
Reference: https://groups.google.com/forum/#!topic/mayan-edms/VUGRl4xX-1c
This commit is contained in:
@@ -126,7 +126,7 @@ class MetadataType(models.Model):
|
||||
|
||||
if self.lookup:
|
||||
lookup_options = self.get_lookup_values()
|
||||
if value not in lookup_options:
|
||||
if value and value not in lookup_options:
|
||||
raise ValidationError(
|
||||
_('Value is not one of the provided options.')
|
||||
)
|
||||
|
||||
@@ -63,8 +63,9 @@ class MetadataTestCase(TestCase):
|
||||
self.document.metadata_value_of.test, TEST_DEFAULT_VALUE
|
||||
)
|
||||
|
||||
def test_lookup(self):
|
||||
def test_lookup_with_incorrect_value(self):
|
||||
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
|
||||
self.metadata_type.save()
|
||||
|
||||
document_metadata = DocumentMetadata(
|
||||
document=self.document, metadata_type=self.metadata_type,
|
||||
@@ -76,8 +77,15 @@ class MetadataTestCase(TestCase):
|
||||
document_metadata.full_clean()
|
||||
document_metadata.save()
|
||||
|
||||
# Should not return error
|
||||
document_metadata.value = TEST_CORRECT_LOOKUP_VALUE
|
||||
def test_lookup_with_correct_value(self):
|
||||
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
|
||||
self.metadata_type.save()
|
||||
|
||||
document_metadata = DocumentMetadata(
|
||||
document=self.document, metadata_type=self.metadata_type,
|
||||
value=TEST_CORRECT_LOOKUP_VALUE
|
||||
)
|
||||
|
||||
document_metadata.full_clean()
|
||||
document_metadata.save()
|
||||
|
||||
@@ -85,6 +93,22 @@ class MetadataTestCase(TestCase):
|
||||
self.document.metadata_value_of.test, TEST_CORRECT_LOOKUP_VALUE
|
||||
)
|
||||
|
||||
def test_empty_optional_lookup(self):
|
||||
"""
|
||||
Checks for GitLab issue #250
|
||||
Empty optional lookup metadata trigger validation error
|
||||
"""
|
||||
|
||||
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
|
||||
self.metadata_type.save()
|
||||
|
||||
document_metadata = DocumentMetadata(
|
||||
document=self.document, metadata_type=self.metadata_type
|
||||
)
|
||||
|
||||
document_metadata.full_clean()
|
||||
document_metadata.save()
|
||||
|
||||
def test_validation(self):
|
||||
self.metadata_type.validation = TEST_DATE_VALIDATOR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user