Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1354 | retired mapping csv test
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Oct 4, 2022
1 parent fdd8bfc commit 764a579
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
36 changes: 36 additions & 0 deletions core/importers/tests.py
Expand Up @@ -519,6 +519,42 @@ def test_csv_import_with_retired_concepts(self, batch_index_resources_mock):
map_type="Parent-child-retired", parent__mnemonic='MyDemoSource', is_latest_version=True, retired=True
).count(), 1)

@patch('core.importers.models.batch_index_resources')
def test_csv_import_with_retired_concepts_and_mappings(self, batch_index_resources_mock):
file_content = open(
os.path.join(os.path.dirname(__file__), '..', 'samples/ocl_csv_import_example_test_retired.csv'), 'r').read()
data = OclStandardCsvToJsonConverter(
input_list=csv_file_data_to_input_list(file_content), allow_special_characters=True).process()
importer = BulkImportInline(data, 'ocladmin', True)
importer.run()

self.assertEqual(importer.processed, 12)
self.assertEqual(len(importer.created), 12)
self.assertEqual(len(importer.failed), 0)
self.assertEqual(len(importer.exists), 0)
self.assertEqual(len(importer.updated), 0)
self.assertEqual(len(importer.invalid), 0)
self.assertEqual(len(importer.others), 0)
self.assertEqual(len(importer.permission_denied), 0)
batch_index_resources_mock.apply_async.assert_called()

self.assertTrue(
Concept.objects.filter(mnemonic='Act', is_latest_version=True, retired=False).exists())
self.assertTrue(
Concept.objects.filter(mnemonic='Child', is_latest_version=True, retired=False).exists())
self.assertTrue(
Concept.objects.filter(mnemonic='Child_of_child', is_latest_version=True, retired=False).exists())
self.assertTrue(
Concept.objects.filter(mnemonic='Ret', is_latest_version=True, retired=True).exists())
self.assertTrue(
Concept.objects.filter(mnemonic='Ret-with-mappings', is_latest_version=True, retired=True).exists())
self.assertTrue(
Mapping.objects.filter(map_type='Child-Parent', is_latest_version=True, retired=False).exists())
self.assertTrue(
Mapping.objects.filter(map_type='SAME-AS', is_latest_version=True, retired=True).exists())
self.assertTrue(
Mapping.objects.filter(map_type='Parent-child', is_latest_version=True, retired=False).exists())

@unittest.skip('[Skipped] Gets hung sometimes')
@patch('core.importers.models.batch_index_resources')
def test_openmrs_schema_csv_import(self, batch_index_resources_mock):
Expand Down
1 change: 0 additions & 1 deletion core/importers/views.py
Expand Up @@ -331,7 +331,6 @@ def post(self, request, import_queue=None):
input_list=csv_file_data_to_input_list(file_content),
allow_special_characters=True
).process()
print("****", data)
except Exception as ex: # pylint: disable=broad-except
return Response(dict(exception=f'Bad CSV ({str(ex)})'), status=status.HTTP_400_BAD_REQUEST)
elif file:
Expand Down
14 changes: 14 additions & 0 deletions core/samples/ocl_csv_import_example_test_retired.csv
@@ -0,0 +1,14 @@
resource_type,id,name,company,website,location,public_access,logo_url,description,text,attr:Ex_Num,attr:ex_name,full_name,owner_id,owner_type,source_type,default_locale,supported_locales,custom_validation_schema,external_id,canonical_url,hierarchy_meaning,hierarchy_root_url,internal_reference_id,meta,collection_reference,publisher,purpose,copyright,revision_date,experimental,jurisdiction,content_type,case_sensitive,compositional,version_needed,external_id ,retired,datatype,concept_class,source,description[1],description[2],name[1],name_type[1],parent_concept_urls[0],map_type[0],map_from_concept_id[0],map_to_concept_id[0],map_type,to_concept_url,from_concept_url,attr:extra_names,collection_type,immutable,jurisdiction[1],jurisdiction[2],collection_url,data:expressions
Organization,DemoOrg,My Demo Organization,DemoLand Inc.,https://www.demoland.fake,DemoLand,View,https://thumbs.dreamstime.com/b/demo-icon-demo-147077326.jpg,Generic Demo description text,This organization is demo-tastic!,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Source,MyDemoSource,My Test Source,,https://www.demoland.fake/source,,Edit,https://thumbs.dreamstime.com/b/demo-icon-demo-147077326.jpg,Using this source just for testing purposes,,,Source Name,My Demonstrative Test Source,DemoOrg,Organization,Dictionary,en,"en,fk",None,164531246546-IDK,https://demo.fake/CodeSystem/Source,is-a,/orgs/DemoOrg/sources/MyDemoSource/concepts/Act/,askjdhbas,IDK,/orgs/DemoOrg/collections/MyDemoCollection/,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Source,MyFHIRSource,My FHIR Source,,https://www.demoland.fake/source,,Edit,,Using this source just for FHIR testing purposes,,,FHIR Source Name,My Demonstrative FHIR Test Source,DemoOrg,Organization,Dictionary,en,"en,fk",None,FHIR1641246546-IDK,https://demo.fake/CodeSystem/FHIRSource,,,,,,"DemoLand, Inc.",Only for testing,For testing only,7/27/2021,TRUE,[Record],example,TRUE,FALSE,TRUE,,,,,,,,,,,,,,,,,,,,,,,
Concept,Act,,,,,,,,,,,,DemoOrg,Organization,,,,,HSpL3hSBx6F,,,,,,,,,,,,,,,,,,FALSE,None,Misc,MyDemoSource,Just one description,,Active Demo Concept,Fully Specified,,,,,,,,,,,,,,
Concept,Ret,,,,,,,,,,,,DemoOrg,Organization,,,,,HSpL3hSBx6F,,,,,,,,,,,,,,,,,,TRUE,None,Misc,MyDemoSource,,,Retired Demo Concept,Fully Specified,,,,,,,,,,,,,,
Concept,Child,,,,,,,,,,,,DemoOrg,Organization,,,,,HSpL3hSBx6F,,,,,,,,,,,,,,,,,,FALSE,None,Misc,MyDemoSource,,,Child Demo Concept,Fully Specified,/orgs/DemoOrg/sources/MyDemoSource/concepts/Act/,,,,,,,,,,,,,
Concept,Child_of_child,,,,,,,,,,,,DemoOrg,Organization,,,,,asdkfjhasLKfjhsa,,,,,,,,,,,,,,,,,,FALSE,None,Misc,MyDemoSource,Main description,Secondary description,Child of the Child Demo Concept,Fully Specified,/orgs/DemoOrg/sources/MyDemoSource/concepts/Child/,Child-Parent,/orgs/DemoOrg/sources/MyDemoSource/concepts/Child_of_child/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Child/,,,,,,,,,,
Concept,Ret-with-mappings,,,,,,,,,,,,DemoOrg,Organization,,,,,,,,,,,,,,,,,,,,,,,TRUE,None,Misc,MyDemoSource,A description,Another description,Another retired concept,Fully Specified,,SAME-AS,/orgs/DemoOrg/sources/MyDemoSource/concepts/Ret-with-mappings/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Ret/,,,,,,,,,,
Mapping,,,,,,,,,,,,,DemoOrg,Organization,,,,,,,,,,,,,,,,,,,,,,,,,,MyDemoSource,,,,,,,,,Parent-child,/orgs/DemoOrg/sources/MyDemoSource/concepts/Child/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Act/,,,,,,,
Collection,MyDemoCollection,My Test Collection,,https://www.demoland.fake/source,,Edit,https://thumbs.dreamstime.com/b/demo-icon-demo-147077326.jpg,Using this collection just for testing purposes,Generic About entry,,Collection Name,My Demonstrative Test Collection,DemoOrg,Organization,,en,"en,fk",None,654246546-IDK,https://demo.fake/ValueSet/Collection,,,,,,"DemoLand, Inc.",To demonstrate,Please don't use this for anything but test importing.,44386,TRUE,,,,,,,,,,,,,,,,,,,,,,,Value Set,FALSE,DZA,EGY,,
Reference,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,/orgs/DemoOrg/collections/MyDemoCollection/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Act/
Reference,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,/orgs/DemoOrg/collections/MyDemoCollection/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Ret/
Reference,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,/orgs/DemoOrg/collections/MyDemoCollection/,/orgs/DemoOrg/sources/MyDemoSource/concepts/Unresolved/

0 comments on commit 764a579

Please sign in to comment.