Skip to content

Commit

Permalink
Expansion test for getting mappings from a concept
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Apr 4, 2022
1 parent 2423c7a commit fb985e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions core/collections/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,26 @@ def test_is_auto_generated(self):
self.assertTrue(
Expansion(mnemonic='autoexpand-HEAD', collection_version=Collection(version='HEAD')).is_auto_generated)

def test_get_mappings_for_concept(self):
concept1 = ConceptFactory()
concept2 = ConceptFactory(parent=concept1.parent)
mapping1 = MappingFactory(parent=concept1.parent, from_concept=concept1, to_concept=concept2)
collection = OrganizationCollectionFactory()
expansion = ExpansionFactory(collection_version=collection)
expansion.concepts.set([concept1, concept2])
expansion.mappings.set([mapping1])

mappings = expansion.get_mappings_for_concept(concept1)
self.assertEqual(mappings.count(), 1)
self.assertEqual(mappings.first().id, mapping1.id)

mappings = expansion.get_mappings_for_concept(concept2)
self.assertEqual(mappings.count(), 0)

mappings = expansion.get_mappings_for_concept(concept=concept2, include_indirect=True)
self.assertEqual(mappings.count(), 1)
self.assertEqual(mappings.first().id, mapping1.id)


class ExpansionParametersTest(OCLTestCase):
def test_apply(self):
Expand Down
6 changes: 4 additions & 2 deletions core/sources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ def index_children(self):
self.batch_index(self.concepts, ConceptDocument)
self.batch_index(self.mappings, MappingDocument)

def keep_concept_latest_versions_on_head(self):
# only for data correction for Source HEAD resources
def keep_concept_latest_versions_on_head(self): # pragma: no cover
self.concepts.set(
self.concepts.filter(models.Q(is_latest_version=True) | models.Q(id=F('versioned_object_id'))))

def keep_mapping_latest_versions_on_head(self):
# only for data correction for Source HEAD resources
def keep_mapping_latest_versions_on_head(self): # pragma: no cover
self.mappings.set(
self.mappings.filter(models.Q(is_latest_version=True) | models.Q(id=F('versioned_object_id'))))

0 comments on commit fb985e1

Please sign in to comment.