Esempio n. 1
0
    def test_specifier_should_initialize_openmrs_validator_with_reference_values(
            self):
        source = OrganizationSourceFactory(
            custom_validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS,
            version=HEAD)
        expected_reference_values = {
            'DescriptionTypes': ['None', 'FULLY_SPECIFIED', 'Definition'],
            'Datatypes': ['None', 'N/A', 'Numeric', 'Coded', 'Text'],
            'Classes': ['Diagnosis', 'Drug', 'Test', 'Procedure'],
            'Locales': ['en', 'es', 'fr', 'tr', 'Abkhazian', 'English'],
            'NameTypes': [
                'FULLY_SPECIFIED', 'Fully Specified', 'Short', 'SHORT',
                'INDEX_TERM', 'Index Term', 'None'
            ]
        }

        validator = ValidatorSpecifier().with_validation_schema(
            CUSTOM_VALIDATION_SCHEMA_OPENMRS).with_repo(
                source).with_reference_values().get()

        actual_reference_values = validator.reference_values

        self.assertEqual(sorted(expected_reference_values['Datatypes']),
                         sorted(actual_reference_values['Datatypes']))
        self.assertEqual(sorted(expected_reference_values['Classes']),
                         sorted(actual_reference_values['Classes']))
        self.assertEqual(sorted(expected_reference_values['Locales']),
                         sorted(actual_reference_values['Locales']))
        self.assertEqual(sorted(expected_reference_values['NameTypes']),
                         sorted(actual_reference_values['NameTypes']))
        self.assertEqual(sorted(expected_reference_values['DescriptionTypes']),
                         sorted(actual_reference_values['DescriptionTypes']))
Esempio n. 2
0
    def validate_child_concepts(self):
        # If source is being configured to have a validation schema
        # we need to validate all concepts
        # according to the new schema
        from core.concepts.validators import ValidatorSpecifier

        concepts = self.get_active_concepts()
        failed_concept_validations = []

        validator = ValidatorSpecifier().with_validation_schema(
            self.custom_validation_schema
        ).with_repo(self).with_reference_values().get()

        for concept in concepts:
            try:
                validator.validate(concept)
            except ValidationError as validation_error:
                concept_validation_error = dict(
                    mnemonic=concept.mnemonic, url=concept.url, errors=validation_error.message_dict
                )
                failed_concept_validations.append(concept_validation_error)

        return failed_concept_validations
Esempio n. 3
0
    def clean(self):
        if settings.DISABLE_VALIDATION:
            return  # pragma: no cover

        validators = [BasicConceptValidator()]

        schema = self.parent.custom_validation_schema
        if schema:
            custom_validator = ValidatorSpecifier().with_validation_schema(
                schema).with_repo(self.parent).with_reference_values().get()
            validators.append(custom_validator)

        for validator in validators:
            validator.validate(self)