コード例 #1
0
    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')
コード例 #2
0
    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')
コード例 #3
0
    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")
コード例 #4
0
 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())
コード例 #5
0
 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())
コード例 #6
0
 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())
コード例 #7
0
 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)
コード例 #8
0
 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())
コード例 #9
0
    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()
        )
コード例 #10
0
 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)
コード例 #11
0
    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())
コード例 #12
0
ファイル: import_demo_data.py プロジェクト: ehebel/oclapi
    def handle(self, *args, **options):
        user = User.objects.filter(username='******').get()

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_20180601_concepts_2k.json', 'rb')
        importer = ConceptsImporter(source,
                                    demo_file,
                                    user,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr),
                                    save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_20180601_mappings_2k.json', 'rb')
        importer = MappingsImporter(source, demo_file,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)
コード例 #13
0
    def handle(self, *args, **options):
        user = self.create_admin_user()

        version = 'v2019-07-01'

        source_version = SourceVersion.objects.filter(mnemonic=version)
        if source_version.exists():
            return

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_' + version + '_c2k.json', 'rb')
        importer = ConceptsImporter(source,
                                    demo_file,
                                    user,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr),
                                    save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_' + version + '_m2k.json', 'rb')
        importer = MappingsImporter(source, demo_file,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)

        new_version = SourceVersion.for_base_object(source,
                                                    version,
                                                    released=True)
        SourceVersion.persist_new(new_version,
                                  versioned_object=source,
                                  force_insert=True)
        update_children_for_resource_version.delay(new_version.id, 'source')

        export_source.delay(new_version.id)
コード例 #14
0
 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)