def test_import_job_for_change_in_data(self): stdout_stub = TestStream() stderr_stub = TestStream() mapping = Mapping(parent=self.source1, map_type='SAME-AS', from_concept=self.concept3, to_source=self.source1, to_concept_code='413532003', external_id='junk') kwargs = { 'parent_resource': self.source1, } Mapping.persist_new(mapping, self.user1, **kwargs) source_version = SourceVersion.get_latest_version_of(self.source1) source_version.mappings = [mapping.id] source_version.save() importer = MappingsImporter(self.source1, self.testfile, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue('**** Processed 1 out of 1 mappings - 1 updated, ****' in stdout_stub.getvalue()) self.assertTrue(('Updated mapping with ID ' + mapping.id) in stdout_stub.getvalue()) updated_mapping = Mapping.objects.get(to_concept_code='413532003') self.assertTrue(updated_mapping.retired) self.assertEquals(updated_mapping.external_id, '70279ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
def test_import_job_for_change_in_data(self): stdout_stub = TestStream() stderr_stub = TestStream() mapping = Mapping( parent=self.source1, map_type='SAME-AS', from_concept=self.concept3, to_source=self.source1, to_concept_code='413532003', external_id='junk' ) kwargs = { 'parent_resource': self.source1, } Mapping.persist_new(mapping, self.user1, **kwargs) source_version = SourceVersion.get_latest_version_of(self.source1) source_version.mappings = [mapping.id] source_version.save() importer = MappingsImporter(self.source1, self.testfile, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue('mappings of 1 1 - 1 updated' in stdout_stub.getvalue()) self.assertTrue(('Updated mapping with ID ' + mapping.id) in stdout_stub.getvalue()) updated_mapping = Mapping.objects.get(to_concept_code='413532003') self.assertTrue(updated_mapping.retired) self.assertEquals(updated_mapping.external_id, '70279ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
def test_import_job_for_one_invalid_record(self): stdout_stub = TestStream() stderr_stub = TestStream() invalid_json_file = open('./integration_tests/fixtures/one_invalid_mapping.json', 'rb') importer = MappingsImporter(self.source1, invalid_json_file, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue('Cannot map concept to itself.' in stderr_stub.getvalue())
def test_import_job_for_change_in_data(self): stdout_stub = TestStream() stderr_stub = TestStream() mapping = Mapping( parent=self.source1, map_type="SAME-AS", from_concept=self.concept3, to_source=self.source1, to_concept_code="413532003", external_id="junk", ) kwargs = {"parent_resource": self.source1} Mapping.persist_new(mapping, self.user1, **kwargs) source_version = SourceVersion.get_latest_version_of(self.source1) source_version.mappings = [mapping.id] source_version.save() importer = MappingsImporter(self.source1, self.testfile, stdout_stub, stderr_stub, "test") importer.import_mappings(total=1) self.assertTrue("**** Processed 1 out of 1 mappings - 1 updated, ****" in stdout_stub.getvalue()) self.assertTrue(("Updated mapping with ID " + mapping.id) in stdout_stub.getvalue()) updated_mapping = Mapping.objects.get(to_concept_code="413532003") self.assertTrue(updated_mapping.retired) self.assertEquals(updated_mapping.external_id, "70279ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
def test_import_job_for_one_invalid_record(self): stdout_stub = TestStream() stderr_stub = TestStream() invalid_json_file = open( './integration_tests/fixtures/one_invalid_mapping.json', 'rb') importer = MappingsImporter(self.source1, invalid_json_file, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue( 'Cannot map concept to itself.' in stderr_stub.getvalue())
def test_import_valid_invalid_mappings(self): stdout_stub = TestStream() stderr_stub = TestStream() invalid_json_file = open('./integration_tests/fixtures/valid_invalid_mapping.json', 'rb') importer = MappingsImporter(self.source1, invalid_json_file, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=5) self.assertTrue('Cannot map concept to itself.' in stderr_stub.getvalue()) self.assertTrue("Must specify either 'to_concept' or 'to_source' & " in stderr_stub.getvalue()) self.assertEquals(3, Mapping.objects.count()) self.assertEquals(3, MappingVersion.objects.count())
def test_import_job_for_one_record(self): stdout_stub = TestStream() stderr_stub = TestStream() importer = MappingsImporter(self.source1, self.testfile, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue('Created new mapping:' in stdout_stub.getvalue()) self.assertTrue('/users/user1/sources/source1/:413532003' in stdout_stub.getvalue()) inserted_mapping = Mapping.objects.get(to_concept_code='413532003') self.assertEquals(inserted_mapping.to_source, self.source1) self.assertEquals(inserted_mapping.from_source, self.source2) mapping_ids = SourceVersion.get_latest_version_of(self.source1).mappings mapping_version = MappingVersion.objects.get(versioned_object_id=inserted_mapping.id, is_latest_version=True) self.assertEquals(mapping_ids[0], mapping_version.id)
def test_import_valid_invalid_mappings(self): stdout_stub = TestStream() stderr_stub = TestStream() invalid_json_file = open( './integration_tests/fixtures/valid_invalid_mapping.json', 'rb') importer = MappingsImporter(self.source1, invalid_json_file, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=5) self.assertTrue( 'Cannot map concept to itself.' in stderr_stub.getvalue()) self.assertTrue("Must specify either 'to_concept' or 'to_source' & " in stderr_stub.getvalue()) self.assertEquals(3, Mapping.objects.count()) self.assertEquals(3, MappingVersion.objects.count())
def test_update_mapping_with_invalid_record(self): mapping = Mapping(parent=self.source1, map_type="SAME-AS", from_concept=self.concept3, to_concept=self.concept1) kwargs = {"parent_resource": self.source1} Mapping.persist_new(mapping, self.user1, **kwargs) source_version = SourceVersion.get_latest_version_of(self.source1) source_version.mappings = [mapping.id] source_version.save() stderr_stub = TestStream() invalid_json_file = open("./integration_tests/fixtures/one_internal_invalid_mapping.json", "rb") importer = MappingsImporter(self.source1, invalid_json_file, TestStream(), stderr_stub, "test") importer.import_mappings(total=1) self.assertTrue( "Must specify either 'to_concept' or 'to_source' & 'to_concept_code'. Cannot specify both." in stderr_stub.getvalue() )
def test_import_job_for_one_record(self): stdout_stub = TestStream() stderr_stub = TestStream() importer = MappingsImporter(self.source1, self.testfile, stdout_stub, stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue('Created new mapping:' in stdout_stub.getvalue()) self.assertTrue('/users/user1/sources/source1/:413532003' in stdout_stub.getvalue()) inserted_mapping = Mapping.objects.get(to_concept_code='413532003') self.assertEquals(inserted_mapping.to_source, self.source1) self.assertEquals(inserted_mapping.from_source, self.source2) mapping_ids = SourceVersion.get_latest_version_of( self.source1).get_mapping_ids() mapping_version = MappingVersion.objects.get( versioned_object_id=inserted_mapping.id, is_latest_version=True) self.assertEquals(mapping_ids[0], mapping_version.id)
def test_update_mapping_with_invalid_record(self): mapping = Mapping(parent=self.source1, map_type='SAME-AS', from_concept=self.concept3, to_concept=self.concept1) kwargs = { 'parent_resource': self.source1, } Mapping.persist_new(mapping, self.user1, **kwargs) source_version = SourceVersion.get_latest_version_of(self.source1) source_version.mappings = [mapping.id] source_version.save() stderr_stub = TestStream() invalid_json_file = open( './integration_tests/fixtures/one_internal_invalid_mapping.json', 'rb') importer = MappingsImporter(self.source1, invalid_json_file, TestStream(), stderr_stub, 'test') importer.import_mappings(total=1) self.assertTrue( "Must specify either 'to_concept' or 'to_source' & 'to_concept_code'. Cannot specify both." in stderr_stub.getvalue())
def do_import(self, user, source, input_file, options): """ Perform the mapping import """ importer = MappingsImporter(source, input_file, self.stdout, self.stderr, user) importer.import_mappings(**options)