コード例 #1
0
    def test_load_local_entity_with_data_partition_pattern(self):
        content = TestHelper.get_input_file_content(
            self.test_subpath,
            "test_load_local_entity_with_data_partition_pattern",
            "entities.manifest.cdm.json")
        manifest_content = ManifestContent()
        manifest_content.decode(content)

        cdmManifest = ManifestPersistence.from_object(
            CdmCorpusContext(CdmCorpusDefinition(), None), "entities",
            "testNamespace", "/", manifest_content)
        self.assertEqual(len(cdmManifest.entities), 1)
        self.assertEqual(cdmManifest.entities[0].object_type,
                         CdmObjectType.LOCAL_ENTITY_DECLARATION_DEF)
        entity = cdmManifest.entities[0]
        self.assertEqual(len(entity.data_partition_patterns), 1)
        pattern = entity.data_partition_patterns[0]
        self.assertEqual(pattern.name, "testPattern")
        self.assertEqual(pattern.explanation, "test explanation")
        self.assertEqual(pattern.root_location, "test location")
        self.assertEqual(pattern.regular_expression, "\\s*")
        self.assertEqual(len(pattern.parameters), 2)
        self.assertEqual(pattern.parameters[0], "testParam1")
        self.assertEqual(pattern.parameters[1], "testParam2")
        self.assertEqual(pattern.specialized_schema, "test special schema")
        self.assertEqual(len(pattern.exhibits_traits), 1)
コード例 #2
0
    def test_trait_to_unknown_data_format(self):
        """Test trait to data format when unknown data format trait is in an attribute."""
        cdm_attribute = CdmTypeAttributeDefinition(CdmCorpusContext(CdmCorpusDefinition(), None), 'SomeAttribute')
        cdm_attribute.applied_traits.append('is.data_format.someRandomDataFormat')
        trait_to_property_map = TraitToPropertyMap(cdm_attribute)

        data_format = trait_to_property_map._traits_to_data_format(False)

        self.assertEqual(CdmDataFormat.UNKNOWN, data_format)
コード例 #3
0
    def test_load_local_entity_with_data_partition_pattern(self):
        content = TestHelper.get_input_file_content(
            self.test_subpath,
            'test_load_local_entity_with_data_partition_pattern',
            'entities.manifest.cdm.json')
        manifest_content = ManifestContent()
        manifest_content.decode(content)

        cdm_manifest = ManifestPersistence.from_object(
            CdmCorpusContext(CdmCorpusDefinition(), None), 'entities',
            'testNamespace', '/', manifest_content)
        self.assertEqual(len(cdm_manifest.entities), 2)
        entity1 = cdm_manifest.entities[0]
        self.assertEqual(entity1.object_type,
                         CdmObjectType.LOCAL_ENTITY_DECLARATION_DEF)
        self.assertEqual(len(entity1.data_partition_patterns), 1)
        pattern1 = entity1.data_partition_patterns[0]
        self.assertEqual(pattern1.name, 'testPattern')
        self.assertEqual(pattern1.explanation, 'test explanation')
        self.assertEqual(pattern1.root_location, 'test location')
        self.assertEqual(pattern1.regular_expression, '\\s*')
        self.assertEqual(len(pattern1.parameters), 2)
        self.assertEqual(pattern1.parameters[0], 'testParam1')
        self.assertEqual(pattern1.parameters[1], 'testParam2')
        self.assertEqual(pattern1.specialized_schema, 'test special schema')
        self.assertEqual(len(pattern1.exhibits_traits), 1)

        entity2 = cdm_manifest.entities[1]
        self.assertEqual(entity2.object_type,
                         CdmObjectType.LOCAL_ENTITY_DECLARATION_DEF)
        self.assertEqual(len(entity2.data_partition_patterns), 1)
        pattern2 = entity2.data_partition_patterns[0]
        self.assertEqual(pattern2.name, 'testPattern2')
        self.assertEqual(pattern2.root_location, 'test location2')
        self.assertEqual(pattern2.glob_pattern, '/*.csv')

        manifest_data = ManifestPersistence.to_data(cdm_manifest, None, None)
        self.assertEqual(len(manifest_data.entities), 2)
        entity_data1 = manifest_data.entities[0]
        self.assertEqual(len(entity_data1.dataPartitionPatterns), 1)
        pattern_data1 = entity_data1.dataPartitionPatterns[0]
        self.assertEqual(pattern_data1.name, 'testPattern')
        self.assertEqual(pattern_data1.explanation, 'test explanation')
        self.assertEqual(pattern_data1.rootLocation, 'test location')
        self.assertEqual(pattern_data1.regularExpression, '\\s*')
        self.assertEqual(len(pattern_data1.parameters), 2)
        self.assertEqual(pattern_data1.parameters[0], 'testParam1')
        self.assertEqual(pattern_data1.parameters[1], 'testParam2')
        self.assertEqual(pattern_data1.specializedSchema,
                         'test special schema')
        self.assertEqual(len(pattern_data1.exhibitsTraits), 1)

        pattern_data2 = manifest_data.entities[1].dataPartitionPatterns[0]
        self.assertEqual(pattern_data2.name, 'testPattern2')
        self.assertEqual(pattern_data2.rootLocation, 'test location2')
        self.assertEqual(pattern_data2.globPattern, '/*.csv')
コード例 #4
0
    def test_trait_to_json_data_format(self):
        """Test trait to data format when calculated data format should be JSON."""
        cdm_attribute = CdmTypeAttributeDefinition(CdmCorpusContext(CdmCorpusDefinition(), None), 'SomeAttribute')
        cdm_attribute.applied_traits.append('is.dataFormat.array')
        cdm_attribute.applied_traits.append('means.content.text.JSON')
        trait_to_property_map = TraitToPropertyMap(cdm_attribute)

        data_format = trait_to_property_map._traits_to_data_format(False)

        self.assertEqual(CdmDataFormat.JSON, data_format)
コード例 #5
0
    async def test_pattern_with_non_existing_folder(self):
        corpus = TestHelper.get_local_corpus(self.test_subpath, "test_pattern_with_non_existing_folder")
        content = TestHelper.get_input_file_content(self.test_subpath, "test_pattern_with_non_existing_folder", "entities.manifest.cdm.json")
        manifest_content = ManifestContent()
        manifest_content.decode(content)

        cdmManifest = ManifestPersistence.from_object(CdmCorpusContext(corpus, None), "entities", "local", "/", manifest_content)
        await cdmManifest.file_status_check_async()
        self.assertEqual(len(cdmManifest.entities[0].data_partitions), 0)
        # make sure the last check time is still being set
        self.assertIsNotNone(cdmManifest.entities[0].data_partition_patterns[0].last_file_status_check_time)
コード例 #6
0
    def test_non_null_default_value_attribute(self):
        the_list = [{
            'languageTag': 'en',
            'displayText': 'Preferred Customer',
            'attributeValue': '1',
            'displayOrder': '0'
        },
        {
            'languageTag': 'en',
            'displayText': 'Standard',
            'attributeValue': '2',
            'displayOrder': '1'
        }]

        input = {'defaultValue': the_list}

        cdmTypeAttributeDefinition = PersistenceLayer.from_data(CdmCorpusContext(CdmCorpusDefinition(), None), JObject(input), CdmObjectType.TYPE_ATTRIBUTE_DEF, PersistenceLayer.CDM_FOLDER)

        result = PersistenceLayer.to_data(cdmTypeAttributeDefinition, None, None, PersistenceLayer.CDM_FOLDER)

        self.assertTrue(result)
        self.assertEqual(result.get('defaultValue'), input.get('defaultValue'))
コード例 #7
0
    async def test_load_local_entitiy_with_data_partition(self):
        content = TestHelper.get_input_file_content(
            self.test_subpath, 'test_load_local_entity_with_data_partition',
            'entities.manifest.cdm.json')
        manifest_content = ManifestContent()
        manifest_content.decode(content)

        cdm_manifest = await ManifestPersistence.from_data(
            CdmCorpusContext(CdmCorpusDefinition()), 'entities',
            'testNamespace', '/', manifest_content)
        self.assertEqual(len(cdm_manifest.entities), 1)
        self.assertEqual(cdm_manifest.entities[0].object_type,
                         CdmObjectType.LOCAL_ENTITY_DECLARATION_DEF)
        entity = cdm_manifest.entities[0]
        self.assertEqual(len(entity.data_partitions), 2)
        relative_partition = entity.data_partitions[0]
        self.assertEqual(relative_partition.name, 'Sample data partition')
        self.assertEqual(relative_partition.location, 'test/location')
        # self.assertEqual(TimeUtils.GetFormattedDateString(relative_partition.LastFileModifiedTime), '2008-09-15T23:53:23.000Z')
        self.assertEqual(len(relative_partition.exhibits_traits), 1)
        self.assertEqual(relative_partition.specialized_schema, 'teststring')

        test_list = relative_partition.arguments['test']
        self.assertEqual(len(test_list), 3)
        self.assertEqual(test_list[0], 'something')
        self.assertEqual(test_list[1], 'somethingelse')
        self.assertEqual(test_list[2], 'anotherthing')

        key_list = relative_partition.arguments['KEY']
        self.assertEqual(len(key_list), 1)
        self.assertEqual(key_list[0], 'VALUE')

        self.assertFalse('wrong' in relative_partition.arguments)

        absolute_partition = entity.data_partitions[1]
        self.assertEqual(absolute_partition.location,
                         "local:/some/test/location")
コード例 #8
0
                        for annotation in partition.get('annotations'):
                            kvprint(annotation.name, annotation.value, 3, 12)

            kvprint('---', '', 0, 4)

    if model.get('relationships'):
        kvprint('relationships', '', 6, 0)
        for relationship in model.get('relationships'):
            kvprint('type', relationship.type, 3, 4)
            kvprint('fromAttribute', relationship.fromAttribute, 3, 4)
            kvprint('toAttribute', relationship.toAttribute, 3, 4)

    if model.get('referenceModels'):
        kvprint('reference models', '', 6, 0)
        for refModel in model.get('referenceModels'):
            kvprint('id', refModel.id, 3, 4)
            kvprint('location', refModel.location, 3, 4)

# Now run the loaded model through PersistenceLayer

# TODO: Fails because CdmCorpusContext is abstract
# TODO: Fails because CdmObjectType is all capital SNAKE_CASE, but before it used to follow camelCase
manifest_def = from_data(CdmCorpusContext(), model, CdmObjectType.MANIFEST_DEF, 'CdmFolder')  # type: CdmManifestDefinition

assert manifest_def
assert manifest_def.name == 'OrdersProductsCustomersLinked'
assert manifest_def.version == '1.0'
assert manifest_def.description == 'Description of the model OrdersProductsCustomersLinked'
assert len(manifest_def.entities) == 2
# assert manifest_def.entities[1].entityName