Chemical-Curation / chemcurator_django

Backend services for chemical curation
https://api.chemreg.epa.gov
MIT License
1 stars 0 forks source link

148: Add synonym regex validation and tests #216

Closed michael-barbour closed 4 years ago

michael-barbour commented 4 years ago

closes #148

This is the synonym portion of validating SynonymType.validation_regular_expression. Any new Synonym should first check the associated SynonymType.

This ticket is not responsible for checking if updated SynonymType's children are valid.

Tests: validation_regular_expression="^[0-9]*$" only allows the creation of synonyms with numeric strings. "123" is valid; "123a" is not. Below is a simple test that could be run in manage.py shell

synonym_type = SynonymTypeFactory(validation_regular_expression="^[0-9]*$").instance
synonym = SynonymFactory.build(identifier="123", synonym_type={"type": "synonymType", "id": synonym_type.pk})
assert synonym.is_valid()
synonym = SynonymFactory.build(identifier="Foobar", synonym_type={"type": "synonymType", "id": synonym_type.pk})
assert not synonym.is_valid()