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)
def test_path_root_invalid_folder_path(self): """"Tests absolute paths cannot be created with wrong parameters. Checks behavior if FolderPath is invalid.""" corpus = CdmCorpusDefinition() function_was_called = False function_parameter1 = CdmStatusLevel.INFO function_parameter2 = None def callback(status_level: CdmStatusLevel, message1: str): nonlocal function_was_called, function_parameter1, function_parameter2 function_was_called = True function_parameter1 = status_level function_parameter2 = message1 corpus.set_event_callback(callback) manifest = CdmManifestDefinition(None, None) manifest.namespace = 'cdm' manifest.folder_path = './Mnp' corpus.storage.create_absolute_corpus_path('Abc', manifest) self.assertTrue(function_was_called) self.assertEqual(CdmStatusLevel.ERROR, function_parameter1) self.assertTrue(function_parameter2.find('The path should not start with ./') != -1) function_was_called = False manifest.namespace = 'cdm' manifest.folder_path = '/./Mnp' corpus.storage.create_absolute_corpus_path('Abc', manifest) self.assertTrue(function_was_called) self.assertEqual(CdmStatusLevel.ERROR, function_parameter1) self.assertTrue(function_parameter2.find('The path should not contain /./') != -1) function_was_called = False manifest.namespace = 'cdm' manifest.folder_path = '../Mnp' corpus.storage.create_absolute_corpus_path('Abc', manifest) function_parameter2 = function_parameter2.split('|')[1].strip() self.assertTrue(function_was_called) self.assertEqual(CdmStatusLevel.ERROR, function_parameter1) self.assertTrue(function_parameter2.find('The path should not contain ../') != -1) function_was_called = False manifest.namespace = 'cdm' manifest.folder_path = 'Mnp/./Qrs' corpus.storage.create_absolute_corpus_path('Abc', manifest) function_parameter2 = function_parameter2.split('|')[1].strip() self.assertTrue(function_was_called) self.assertEqual(CdmStatusLevel.ERROR, function_parameter1) self.assertTrue(function_parameter2.find('The path should not contain /./') != -1) function_was_called = False manifest.namespace = 'cdm' manifest.folder_path = 'Mnp/../Qrs' corpus.storage.create_absolute_corpus_path('Abc', manifest) function_parameter2 = function_parameter2.split('|')[1].strip() self.assertTrue(function_was_called) self.assertEqual(CdmStatusLevel.ERROR, function_parameter1) self.assertTrue(function_parameter2.find('The path should not contain ../') != -1)
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)""" corpus = CdmCorpusDefinition() function_was_called = False function_parameter1 = CdmStatusLevel.INFO function_parameter2 = None def callback(status_level: CdmStatusLevel, message1: str): nonlocal function_was_called, function_parameter1, function_parameter2 function_was_called = True function_parameter1 = status_level function_parameter2 = message1 corpus.set_event_callback(callback) 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) self.assertEqual(function_was_called, True) self.assertEqual(function_parameter1, CdmStatusLevel.WARNING) self.assertTrue(function_parameter2.find('Expected path prefix to end in /, but it didn\'t. Appended the /') != -1)
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)
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