def test_validate_openmrs_schema_matching_name_locale(self): ch_locale = LocalizedTextFactory(locale_preferred=False, locale='ch') concept1 = ConceptFactory(names=[ch_locale]) collection = OrganizationCollectionFactory( custom_validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS) collection.concepts.add(concept1) concept1_reference = CollectionReference(expression=concept1.uri) concept1_reference.save() collection.references.add(concept1_reference) en_locale1 = LocalizedTextFactory(locale='en', locale_preferred=False, name='name') en_locale2 = LocalizedTextFactory(locale='en', locale_preferred=True, name='name') concept2 = ConceptFactory(names=[en_locale1, en_locale2]) concept2_reference = CollectionReference(expression=concept2.uri) with self.assertRaises(ValidationError) as ex: collection.validate(concept2_reference) self.assertEqual( ex.exception.message_dict, { 'names': [ 'Concept fully specified name must be unique for same collection and locale.' ] })
def test_validate_reference_already_exists(self): collection = OrganizationCollectionFactory() ch_locale = LocalizedTextFactory(locale_preferred=True, locale='ch') en_locale = LocalizedTextFactory(locale_preferred=True, locale='en') concept = ConceptFactory(names=[ch_locale, en_locale]) reference = CollectionReference(expression=concept.uri) reference.save() collection.references.add(reference) self.assertEqual(collection.references.count(), 1) with self.assertRaises(ValidationError) as ex: collection.validate(reference) self.assertEqual( ex.exception.message_dict, { concept.get_latest_version().uri: [ 'Concept or Mapping reference name must be unique in a collection.' ] })