def _delete_working_dir(self): path = working_dir.get_working_directory() perms = stat.S_IRWXU + stat.S_IRWXG + stat.S_IRWXO if os.path.exists(path): os.chmod(path, perms) shutil.rmtree(path) self.assertFalse(os.path.exists(path)) working_dir.WORKING_DIRECTORY = None
def _delete_working_dir(self): path = working_dir.get_working_directory() perms = stat.S_IRWXU + stat.S_IRWXG + stat.S_IRWXO if os.path.exists(path): os.chmod(path, perms) shutil.rmtree(path) self.assertFalse(os.path.exists(path)) working_dir.WORKING_DIRECTORY = None
def test_get_plugin_directory_parent_locked(self): temp_path = os.path.realpath(os.tempnam()) CONF.set_override('working_directory', temp_path) # Create the directory and lock it down. working_dir.get_working_directory() self.assertTrue(os.path.exists(CONF.working_directory)) os.chmod(CONF.working_directory, PERM_READ_ONLY) plugin_name = 'my_test_plugin' plugin_path = os.path.join(CONF.working_directory, 'plugin', plugin_name) self.assertFalse(os.path.exists(plugin_path)) self.assertRaises(IOError, working_dir.get_plugin_directory, plugin_name) # Reset permissions and clean up os.chmod(CONF.working_directory, PERM_ALL) shutil.rmtree(CONF.working_directory) CONF.clear_override('working_directory') working_dir.WORKING_DIRECTORY = None
def setUp(self): super(WorkingDirTestCase, self).setUp() # First register the teardown. self.addCleanup(self._delete_working_dir) workdir = fixtures.TempDir() self.useFixture(workdir) temp_path = workdir.path CONF.set_override('working_directory', temp_path) # Create the directory path = working_dir.get_working_directory() self.assertTrue(os.path.exists(path))
def setUp(self): super(WorkingDirTestCase, self).setUp() # First register the teardown. self.addCleanup(self._delete_working_dir) workdir = fixtures.TempDir() self.useFixture(workdir) temp_path = workdir.path CONF.set_override('working_directory', temp_path) # Create the directory path = working_dir.get_working_directory() self.assertTrue(os.path.exists(path))
def test_get_plugin_directory_parent_locked(self): temp_path = os.path.realpath(os.tempnam()) CONF.set_override('working_directory', temp_path) # Create the directory and lock it down. working_dir.get_working_directory() self.assertTrue(os.path.exists(CONF.working_directory)) os.chmod(CONF.working_directory, PERM_READ_ONLY) plugin_name = 'my_test_plugin' plugin_path = os.path.join(CONF.working_directory, 'plugin', plugin_name) self.assertFalse(os.path.exists(plugin_path)) self.assertRaises(IOError, working_dir.get_plugin_directory, plugin_name) # Reset permissions and clean up os.chmod(CONF.working_directory, PERM_ALL) shutil.rmtree(CONF.working_directory) CONF.clear_override('working_directory') working_dir.WORKING_DIRECTORY = None
def test_get_working_directory(self): '''Assert that the get_working_directory() method makes use of the configured path if it has the permissions to manage it. ''' # Set a temporary directory CONF.set_override('working_directory', os.path.realpath(os.tempnam())) self.assertFalse(os.path.exists(CONF.working_directory)) working_dir_path = working_dir.get_working_directory() self.assertEqual(CONF.working_directory, working_dir_path) self.assertTrue(os.path.exists(CONF.working_directory)) self.assertTrue(os.access(CONF.working_directory, os.W_OK)) # Clean up after ourselves. shutil.rmtree(CONF.working_directory) CONF.clear_override('working_directory') working_dir.WORKING_DIRECTORY = None
def test_get_working_directory(self): '''Assert that the get_working_directory() method makes use of the configured path if it has the permissions to manage it. ''' # Set a temporary directory CONF.set_override('working_directory', os.path.realpath(os.tempnam())) self.assertFalse(os.path.exists(CONF.working_directory)) working_dir_path = working_dir.get_working_directory() self.assertEqual(CONF.working_directory, working_dir_path) self.assertTrue(os.path.exists(CONF.working_directory)) self.assertTrue(os.access(CONF.working_directory, os.W_OK)) # Clean up after ourselves. shutil.rmtree(CONF.working_directory) CONF.clear_override('working_directory') working_dir.WORKING_DIRECTORY = None