-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1266 from UUDigitalHumanitieslab/feature/corpus-m…
…odel-validation Feature/corpus model validation
- Loading branch information
Showing
7 changed files
with
372 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 4.1.9 on 2023-09-13 16:15 | ||
|
||
import addcorpus.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('addcorpus', '0004_alter_corpusconfiguration_category'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='corpusconfiguration', | ||
name='description_page', | ||
field=models.CharField(blank=True, help_text='filename of the markdown documentation file for this corpus', max_length=128, validators=[addcorpus.validators.validate_markdown_filename_extension]), | ||
), | ||
migrations.AlterField( | ||
model_name='corpusconfiguration', | ||
name='image', | ||
field=models.CharField(help_text='filename of the corpus image', max_length=126, validators=[addcorpus.validators.validate_image_filename_extension]), | ||
), | ||
migrations.AlterField( | ||
model_name='corpusconfiguration', | ||
name='scan_image_type', | ||
field=models.CharField(blank=True, help_text='MIME type of scan images', max_length=64, validators=[addcorpus.validators.validate_mimetype]), | ||
), | ||
migrations.AlterField( | ||
model_name='field', | ||
name='es_mapping', | ||
field=models.JSONField(help_text='specification of the elasticsearch mapping of this field', validators=[addcorpus.validators.validate_es_mapping]), | ||
), | ||
migrations.AlterField( | ||
model_name='field', | ||
name='name', | ||
field=models.SlugField(help_text='internal name for the field', max_length=126, validators=[addcorpus.validators.validate_name_is_not_a_route_parameter]), | ||
), | ||
migrations.AlterField( | ||
model_name='field', | ||
name='search_filter', | ||
field=models.JSONField(blank=True, help_text='specification of the search filter for this field (if any)', validators=[addcorpus.validators.validate_search_filter]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import pytest | ||
from addcorpus.es_mappings import int_mapping, text_mapping, keyword_mapping | ||
from addcorpus.validators import * | ||
|
||
def test_validate_mimetype(): | ||
validate_mimetype('image/jpeg') | ||
|
||
with pytest.raises(ValidationError): | ||
validate_mimetype('nonsense') | ||
|
||
def test_validate_es_mapping(): | ||
validate_es_mapping({'type': 'text'}) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_es_mapping({}) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_es_mapping({'type': 'perlocator'}) | ||
|
||
def test_validate_search_filter(): | ||
validate_search_filter({ | ||
'name': 'RangeFilter', | ||
'lower': 0, | ||
'upper': 100, | ||
'description': '...' | ||
}) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_search_filter({'name': 'UnkownFilter'}) | ||
|
||
def test_validate_search_filter_with_mapping(): | ||
filter = { | ||
'name': 'RangeFilter', | ||
'lower': 0, | ||
'upper': 100, | ||
'description': '...' | ||
} | ||
|
||
validate_search_filter_with_mapping(int_mapping(), filter) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_search_filter_with_mapping(keyword_mapping(), filter) | ||
|
||
def test_validate_visualizations_with_mapping(): | ||
validate_visualizations_with_mapping(text_mapping(), ['ngram']) | ||
validate_visualizations_with_mapping(keyword_mapping(), ['resultscount']) | ||
validate_visualizations_with_mapping(keyword_mapping(enable_full_text_search=True), ['ngram']) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_visualizations_with_mapping(keyword_mapping(), ['ngram']) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_visualizations_with_mapping(text_mapping(), ['resultscount']) | ||
|
||
def test_validate_searchable_fields_has_fts(): | ||
validate_searchable_field_has_full_text_search(text_mapping(), True) | ||
validate_searchable_field_has_full_text_search( | ||
keyword_mapping(enable_full_text_search=True), True | ||
) | ||
validate_searchable_field_has_full_text_search(int_mapping(), False) | ||
|
||
with pytest.raises(ValidationError): | ||
validate_searchable_field_has_full_text_search(int_mapping(), True) | ||
|
||
with pytest.warns(Warning): | ||
validate_searchable_field_has_full_text_search(keyword_mapping(), True) | ||
|
||
def test_filename_validation(): | ||
validate_image_filename_extension('image.jpg') | ||
|
||
with pytest.raises(ValidationError): | ||
validate_image_filename_extension('image.txt') | ||
|
Oops, something went wrong.