Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions django-nonrel/ocl/mappings/custom_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def validate(self):
def pair_must_be_unique(self):
from mappings.models import Mapping

intersection = Mapping.objects.filter(parent=self.mapping.parent_source, from_concept=self.mapping.from_concept,
to_concept=self.mapping.to_concept, is_active=True, retired=False).count()
intersection = Mapping.objects\
.filter(parent=self.mapping.parent_source, from_concept=self.mapping.from_concept, to_concept=self.mapping.to_concept, is_active=True, retired=False)\
.exclude(id=self.mapping.id)\
.count()

if intersection:
raise ValidationError(OPENMRS_SINGLE_MAPPING_BETWEEN_TWO_CONCEPTS)
Expand Down
17 changes: 17 additions & 0 deletions django-nonrel/ocl/mappings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,3 +1087,20 @@ def test_update_different_from_and_to_pairs_to_same_from_and_to_pairs_should_thr

self.assertTrue(
OPENMRS_SINGLE_MAPPING_BETWEEN_TWO_CONCEPTS in errors["__all__"])

def test_edit_mapping_after_creation(self):
user = create_user()

source1 = create_source(user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
source2 = create_source(user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

(concept1, _) = create_concept(user, source1)
(concept2, _) = create_concept(user, source2)

mapping = create_mapping(user, source1, concept1, concept2, "Same As")

mapping.map_type = "Different"

errors = Mapping.persist_changes(mapping, user)

self.assertEqual(len(errors), 0)