def test_is_path_creatable(self): """ Test if the path is creatable for the user Does the user has the permission to use this path ? """ # set up the context dir_path = "/tmp/kalliope/tests/" file_name = "test_FileManager_filePathCreatable" file_path = os.path.join(dir_path, file_name) if os.path.exists(file_path): os.remove(file_path) if not os.path.exists(dir_path): os.makedirs(dir_path) # test not allowed : return False not_allowed_root_path = "/root/" not_allowed_path = os.path.join(not_allowed_root_path, file_name) self.assertFalse(FileManager.is_path_creatable(not_allowed_path), "Fail to assert not accessing this path ") # test allowed : return True self.assertTrue(FileManager.is_path_creatable(file_path))
def test_is_path_exists_or_creatable(self): """ Test the _is_path_exists_or_creatable 4 scenarii : - the file exists and is creatable : return True - the file does not exist but is creatable : return True - the file exists but is not allowed : return True --> need a review ! - the file does not exist and is not allowed : return False """ # set up the context dir_path = "/tmp/kalliope/tests/" file_name = "test_FileManager_fileIsPathExistsOrCreatable" file_path = os.path.join(dir_path, file_name) if os.path.exists(file_path): os.remove(file_path) if not os.path.exists(dir_path): os.makedirs(dir_path) # Test the file exist and creatable : return True with open(file_path, "wb") as file_open: file_open.write( b"[Kalliope] Test Running the test_is_path_exists_or_creatable method" ) file_open.close() self.assertTrue(FileManager.is_path_exists_or_creatable(file_path), "Fail to assert the file exist ") # test the file not exist but creatable : return True os.remove(file_path) self.assertTrue(FileManager.is_path_exists_or_creatable(file_path), "Fail asserting the file does not exist ") # test the file exist but not creatable : return True # file_exist_not_allowed = "/root/.ssh/known_hosts" # self.assertTrue(FileManager.is_path_creatable(file_exist_not_allowed)) # test the file not exist and not allowed : return False not_allowed_root_path = "/root/" not_allowed_path = os.path.join(not_allowed_root_path, file_name) self.assertFalse(FileManager.is_path_creatable(not_allowed_path), "Fail to assert not accessing this path ")
def test_is_path_exists_or_creatable(self): """ Test the _is_path_exists_or_creatable 4 scenarii : - the file exists and is creatable : return True - the file does not exist but is creatable : return True - the file exists but is not allowed : return True --> need a review ! - the file does not exist and is not allowed : return False """ # set up the context dir_path = "/tmp/kalliope/tests/" file_name = "test_FileManager_fileIsPathExistsOrCreatable" file_path = os.path.join(dir_path, file_name) if os.path.exists(file_path): os.remove(file_path) if not os.path.exists(dir_path): os.makedirs(dir_path) # Test the file exist and creatable : return True with open(file_path, "wb") as file_open: file_open.write(b"[Kalliope] Test Running the test_is_path_exists_or_creatable method") file_open.close() self.assertTrue(FileManager.is_path_exists_or_creatable(file_path), "Fail to assert the file exist ") # test the file not exist but creatable : return True os.remove(file_path) self.assertTrue(FileManager.is_path_exists_or_creatable(file_path), "Fail asserting the file does not exist ") # test the file exist but not creatable : return True # file_exist_not_allowed = "/root/.ssh/known_hosts" # self.assertTrue(FileManager.is_path_creatable(file_exist_not_allowed)) # test the file not exist and not allowed : return False not_allowed_root_path = "/root/" not_allowed_path = os.path.join(not_allowed_root_path, file_name) self.assertFalse(FileManager.is_path_creatable(not_allowed_path), "Fail to assert not accessing this path ")