def test_create_dir(self):
        """
        Verify that the create_dir utility method creates directories as we expect.
        :return:
        """
        temp_dir = tempfile.TemporaryDirectory()

        # A directory that does not exist yet
        new_dir = os.path.join(temp_dir.name, "new_dir")
        res = utils.create_dir(new_dir)
        self.assertTrue(os.path.exists(new_dir))
        # There was a change, so the result should be True
        self.assertTrue(res)

        # Create another directory
        existing_dir = os.path.join(temp_dir.name, "existing")
        os.mkdir(existing_dir, 0o644)
        res = utils.create_dir(existing_dir)
        # Should have been no change, so the result should be false
        self.assertFalse(res)

        # Create one more directory that does not have the right permissions
        bad_perm_dir = os.path.join(temp_dir.name, "bad_perm_dir")
        os.mkdir(bad_perm_dir, 0o400)

        impossible_sub_dir = os.path.join(bad_perm_dir, "any_sub_dir")

        utils.create_dir(impossible_sub_dir)
        self.assertFalse(os.path.exists(impossible_sub_dir))
Beispiel #2
0
 def create(self):
     """
     Create the files necessary for this store
     :return: True if changes were made, false otherwise
     """
     return (create_dir(os.path.dirname(self.path)) or self.read_file()
             or create_file(self.path, self.contents))
 def create(self):
     """
     Create the files necessary for this store
     :return: True if changes were made, false otherwise
     """
     return create_dir(os.path.dirname(self.path)) or \
         self.read_file() or \
         create_file(self.path, self.contents)