def setUp(self): remove_recursive_silently(DB_PATH) config = get_config() self.api = FileAPI( account_id=config["accountId"], application_key=config["applicationKey"], bucket_id=config["bucketId"], db_file=DB_PATH, ) self.context = IntegrationTestingContext(api=self.api) self.filesystem = Filesystem(self.context.cache)
class AccessTest(OperationTest): """Covers the following operations: - access """ def setUp(self): self.api = MagicMock() self.context = IntegrationTestingContext(api=self.api) self.filesystem = Filesystem(self.context.cache) def test_access_local_file(self): # create a local file self.create_local_file() # make sure the access call succeeds self.filesystem.access(PATH, 0) # assert sure another access call fails with self.assertRaises(FuseOSError): self.filesystem.access(PATH, 7) def test_access_remote_file(self): # create a local file with default permissions path = self.create_local_file() # make file remote inode = self.context.inode_store.get_inode(path) self.context.worker._clean_inode(inode) self.context.cache.create_dummy(inode) # assert that a specific access call succeeds self.filesystem.access(path, 0) # assert sure another access call fails with self.assertRaises(FuseOSError): self.filesystem.access(path, 7)
class CreateWriteReadTest(OperationTest): """Covers the following operations: - create - write - flush - release - open - read """ def setUp(self): self.api = MagicMock() self.context = IntegrationTestingContext(api=self.api) self.filesystem = Filesystem(self.context.cache) def _create_file(self, path): file_handle = self.filesystem.create(PATH, 33204) assert type(file_handle) == int num_bytes_written = self.filesystem.write(path, FILE_CONTENT, 0, file_handle) self.filesystem.flush(path, file_handle) self.filesystem.release(path, file_handle) return num_bytes_written def _read_file(self, path): file_handle = self.filesystem.open(path, 0) response = self.filesystem.read(path, 100, 0, file_handle) return response def test_create_and_read_file(self): self._create_file(path=PATH) content = self._read_file(PATH) assert content == FILE_CONTENT def test_path_is_ignored_during_read(self): self._create_file(path=PATH) file_handle = self.filesystem.open(PATH, 0) content = self.filesystem.read("/wrong/path", 100, 0, file_handle) assert content == FILE_CONTENT
class DummyLifeCycleTest(TestCase): def setUp(self): remove_recursive_silently(DB_PATH) file_info_store = FileInfoStore(DB_PATH) config = get_config() self.api = FileAPI( file_info_store=file_info_store, account_id=config["accountId"], application_key=config["applicationKey"], bucket_id=config["bucketId"], ) self.context = IntegrationTestingContext(api=self.api) self.filesystem = Filesystem(self.context.cache) def test_stat_attributes_are_persistent(self): # Create a local file path = self.create_local_file() # By default, file is not executable stat_before_chmod = self.filesystem.getattr(path) # Make file executable self.filesystem.chmod( path, stat.S_IWOTH | stat.S_IROTH | stat.S_IWUSR | stat.S_IRUSR) # File should now have different permissions print(self.filesystem.getattr(path)) stat_after_chmod = self.filesystem.getattr(path) assert_stat_unequal(stat_after_chmod, stat_before_chmod) # make file remote inode = self.context.inode_store.get_inode(path) self.context.worker._clean_inode(inode) self.context.cache.create_dummy(inode) assert_stat_equal(stat_after_chmod, self.filesystem.getattr(path)) # make file local self.context.cache.replace_dummy(inode) assert_stat_equal(stat_after_chmod, self.filesystem.getattr(path)) def assertDictAlmostEqual(self, first, second): for key in first.keys(): self.assertAlmostEqual(first[key], second[key]) def create_local_file(self): return self.context.create_file(PATH, FILE_CONTENT)
def setUp(self): self.api = MagicMock() self.context = IntegrationTestingContext(api=self.api) self.filesystem = Filesystem(self.context.cache)