예제 #1
0
    def test_valid_root_path(self):
        """Checks Absolute corpus path can be created with valid input."""
        corpus = CdmCorpusDefinition()
        # checks with None object
        absolute_path = corpus.storage.create_absolute_corpus_path('Abc/Def')
        self.assertEqual('/Abc/Def', absolute_path)
        absolute_path = corpus.storage.create_absolute_corpus_path('/Abc/Def')
        self.assertEqual('/Abc/Def', absolute_path)
        absolute_path = corpus.storage.create_absolute_corpus_path(
            'cdm:/Abc/Def')
        self.assertEqual('cdm:/Abc/Def', absolute_path)
        manifest = CdmManifestDefinition(None, None)

        manifest._namespace = ''
        manifest._folder_path = 'Mnp/Qrs/'
        absolute_path = corpus.storage.create_absolute_corpus_path(
            'Abc/Def', manifest)
        self.assertEqual('Mnp/Qrs/Abc/Def', absolute_path)

        manifest._namespace = 'cdm'
        manifest._folder_path = 'Mnp/Qrs/'
        absolute_path = corpus.storage.create_absolute_corpus_path(
            '/Abc/Def', manifest)
        self.assertEqual('cdm:/Abc/Def', absolute_path)

        manifest._namespace = 'cdm'
        manifest._folder_path = 'Mnp/Qrs/'
        absolute_path = corpus.storage.create_absolute_corpus_path(
            'Abc/Def', manifest)
        self.assertEqual('cdm:Mnp/Qrs/Abc/Def', absolute_path)
예제 #2
0
    def test_manifest_cannot_add_entity_definition_without_creating_document(self):
        cdm_corpus = CdmCorpusDefinition()
        cdm_corpus.storage.default_namespace = 'local'
        function_was_called = False
        function_parameter1 = CdmStatusLevel.INFO
        function_parameter2 = ''

        def callback(status_level: 'CdmStatusLevel', message: str):
            nonlocal function_was_called, function_parameter1, function_parameter2
            function_was_called = True
            function_parameter1 = status_level
            function_parameter2 = message

        cdm_corpus.set_event_callback(callback)

        cdm_corpus.storage.mount('local', LocalAdapter('C:\\Root\\Path'))

        manifest = CdmManifestDefinition(cdm_corpus.ctx, 'manifest')
        manifest._folder_path = '/'
        manifest._namespace = 'local'
        entity = CdmEntityDefinition(manifest.ctx, 'entityName', None)

        manifest.entities.append(entity)
        self.assertTrue(function_was_called)
        self.assertEqual(CdmStatusLevel.ERROR, function_parameter1)
        self.assertTrue('Expected entity to have an \'Owner\' document set. Cannot create entity declaration to add to manifest.' in function_parameter2)
예제 #3
0
    def test_path_root_invalid_folder_path(self):
        """"Tests absolute paths cannot be created with wrong parameters.
        Checks behavior if FolderPath is invalid."""
        expected_log_codes = {CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT}
        corpus = TestHelper.get_local_corpus(
            self.tests_subpath,
            'test_path_root_invalid_folder_path',
            expected_codes=expected_log_codes,
            no_input_and_output_folder=True)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = './Mnp'
        corpus.storage.create_absolute_corpus_path('Abc', manifest)
        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT, True, self)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = '/./Mnp'
        corpus.storage.create_absolute_corpus_path('Abc', manifest)
        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT, True, self)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = '../Mnp'
        corpus.storage.create_absolute_corpus_path('Abc', manifest)
        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT, True, self)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = 'Mnp/./Qrs'
        corpus.storage.create_absolute_corpus_path('Abc', manifest)
        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT, True, self)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = 'Mnp/../Qrs'
        corpus.storage.create_absolute_corpus_path('Abc', manifest)
        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.ERR_STORAGE_INVALID_PATH_FORMAT, True, self)
def generate_manifest() -> 'CdmManifestDefinition':
    """
        Creates a manifest used for the tests.
    """
    cdmCorpus = TestHelper.get_local_corpus(None,
                                            generate_manifest.__name__,
                                            no_input_and_output_folder=True)

    manifest = CdmManifestDefinition(cdmCorpus.ctx, 'manifest')
    manifest._folder_path = '/'
    manifest._namespace = 'local'

    return manifest
def generate_manifest(local_root_path: str) -> 'CdmManifestDefinition':
    """
        Creates a manifest used for the tests.
    """
    cdmCorpus = CdmCorpusDefinition()
    cdmCorpus.storage.default_namespace = 'local'
    adapter = LocalAdapter(root=local_root_path)
    cdmCorpus.storage.mount('local', adapter)
    # add cdm namespace
    cdmCorpus.storage.mount('cdm', adapter)

    manifest = CdmManifestDefinition(cdmCorpus.ctx, 'manifest')
    manifest._folder_path = '/'
    manifest._namespace = 'local'

    return manifest
예제 #6
0
    def test_path_that_does_not_end_in_slash(self):
        """FolderPath should always end with a /
        This checks the behavior if FolderPath does not end with a /
        ('/' should be appended and a warning be sent through callback function)"""

        expected_log_codes = {CdmLogCode.WARN_STORAGE_EXPECTED_PATH_PREFIX}
        corpus = TestHelper.get_local_corpus(
            self.tests_subpath,
            'test_path_that_does_not_end_in_slash',
            expected_codes=expected_log_codes,
            no_input_and_output_folder=True)

        manifest = CdmManifestDefinition(None, None)
        manifest._namespace = 'cdm'
        manifest._folder_path = 'Mnp'
        absolute_path = corpus.storage.create_absolute_corpus_path(
            'Abc', manifest)
        self.assertEqual('cdm:Mnp/Abc', absolute_path)

        TestHelper.assert_cdm_log_code_equality(
            corpus, CdmLogCode.WARN_STORAGE_EXPECTED_PATH_PREFIX, True, self)