コード例 #1
0
    def test_add_invalid_resource(self):
        """Attempts to add a nonexistent file and an empty path to Dropbox"""
        # Set up environment
        TEST_FILENAME = "test.txt"
        test_filepath = os.path.join(self._TEST_DIRNAME, TEST_FILENAME)
        test_module = dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)

        self.assertRaises(ValueError, test_module.add_resource, test_filepath)
        self.assertRaises(ValueError, test_module.add_resource, "")
コード例 #2
0
    def test_delete_resources(self):
        """Tests deletion of resources"""
        # Set up environment
        TEST_FILENAME = "test.txt"
        test_filepath = os.path.join(self._TEST_DIRNAME, TEST_FILENAME)
        test_fp = open(test_filepath, "w")
        test_fp.write("This is test text!")
        test_fp.close()

        test_module = dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)
        test_module.add_resource(test_filepath)
        resource_dirname, _, _ = test_module.resource_info(TEST_FILENAME)
        resource_dirpath = os.path.join(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME, resource_dirname)

        # Test valid deletion
        test_module.delete_resource(TEST_FILENAME)
        self.assertFalse(TEST_FILENAME in test_module.resources_set())
        self.assertFalse(os.path.exists(resource_dirpath))

        # Test deleting the same file again without re-adding it
        self.assertRaises(ValueError, test_module.delete_resource, TEST_FILENAME)
コード例 #3
0
    def test_add_resources(self):
        """Adds two files normally, then adds a collision"""
        # Set up first file
        TEST_FILENAME = "test.txt"
        test_filepath = os.path.join(self._TEST_DIRNAME, TEST_FILENAME)
        test_fp = open(test_filepath, "w")
        test_fp.write("This is test text!")
        test_fp.close()

        # Set up second file
        TEST2_FILENAME = "test.txt2"
        test2_filepath = os.path.join(self._TEST_DIRNAME, TEST2_FILENAME)
        test2_fp = open(test2_filepath, "w")
        test2_fp.write("This is a different test text!")
        test2_fp.close()

        # Set up module
        test_module = dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)
        test_module.add_resource(test_filepath)
        test_module.add_resource(test2_filepath)

        # Test files exist in memory
        resources_set = test_module.resources_set()
        self.assertTrue(TEST_FILENAME in resources_set)
        self.assertTrue(TEST2_FILENAME in resources_set)

        # Test files exist in OS
        resource1_dirname, _, _ = test_module.resource_info(TEST_FILENAME)
        resource2_dirname, _, _ = test_module.resource_info(TEST2_FILENAME)
        resource1_dirpath = os.path.join(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME, resource1_dirname)
        resource2_dirpath = os.path.join(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME, resource2_dirname)

        self.assertTrue(os.path.isdir(resource1_dirpath))
        self.assertTrue(os.path.isdir(resource2_dirpath))
        self.assertTrue(os.path.exists(test_module.resource_path(TEST_FILENAME)))
        self.assertTrue(os.path.exists(test_module.resource_path(TEST2_FILENAME)))

        # Test a collision
        self.assertRaises(ValueError, test_module.add_resource, TEST_FILENAME)
コード例 #4
0
    def test_version_dependencies(self):
        """Adds and removes depedencies from a version"""
        # Set up environment
        TEST_FILENAME = "test.txt"
        TEST_FILEPATH = os.path.join(self._TEST_DIRNAME, TEST_FILENAME)
        test_fp = open(TEST_FILEPATH, "w")
        test_fp.write("This is test text!")
        test_fp.close()

        test_module = dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)
        TEST_VERSION = "2.3"
        test_module.add_resource(TEST_FILEPATH, version=TEST_VERSION)

        # Test adding and removing dependencies
        TEST_DEPENDENCY = "foo"
        test_module.add_version_dependency(TEST_FILENAME, TEST_VERSION, TEST_DEPENDENCY)
        dependencies = test_module.version_info(TEST_FILENAME, TEST_VERSION)
        self.assertTrue(TEST_DEPENDENCY in dependencies)
        self.assertRaises(ValueError, test_module.add_version_dependency, TEST_FILENAME, TEST_VERSION, "")
        test_module.delete_version_dependency(TEST_FILENAME, TEST_VERSION, TEST_DEPENDENCY)
        dependencies = test_module.version_info(TEST_FILENAME, TEST_VERSION)
        self.assertTrue(TEST_DEPENDENCY not in dependencies)
        self.assertRaises(ValueError, test_module.delete_version_dependency, TEST_FILENAME, TEST_VERSION, "")
コード例 #5
0
ファイル: unbox_filesystem.py プロジェクト: mieubrisse/Unbox
 def __init__(self, local_unbox_dirpath, dropbox_dirpath, dropbox_unbox_dirname):
     self._dropbox_module = dropbox_module.DropboxModule(dropbox_dirpath, unbox_dirname)
     self._local_module = local_module.LocalModule(local_unbox_dirpath)
コード例 #6
0
 def test_preexisting_unbox_init(self):
     """Tests an initialization with the Unbox directory already existing"""
     os.mkdir(os.path.join(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME))
     dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)
コード例 #7
0
 def test_clean_init(self):
     """Tests a clean initialization"""
     dropbox_module.DropboxModule(self._TEST_DROPBOX_DIRPATH, self._TEST_DROPBOX_UNBOX_DIRNAME)