async def test_service_file_write_bytes(patch, story, line, file_io): patch.object(story.app, 'get_tmp_dir', return_value='/tmp/my.story') story.execution_id = 'super_super_tmp' resolved_args = { 'path': 'my_path', 'content': b'my_content' } await File.file_write(story, line, resolved_args) File.open.assert_called_with(f'{story.app.get_tmp_dir()}/my_path', 'wb') File.open().__enter__().write.assert_called_with(b'my_content')
async def test_service_file_read_bytes(story, line, file_io): story.execution_id = 'super_super_tmp' resolved_args = {'path': 'my_path', 'raw': True} result = await File.file_read(story, line, resolved_args) File.open.assert_called_with(f'{story.get_tmp_dir()}/my_path', 'rb') assert result == File.open().__enter__().read()
async def test_service_file_read(patch, story, line, file_io): patch.object(story.app, 'get_tmp_dir', return_value='/tmp/my.story') story.execution_id = 'super_super_tmp' resolved_args = { 'path': 'my_path' } result = await File.file_read(story, line, resolved_args) File.open.assert_called_with(f'{story.app.get_tmp_dir()}/my_path', 'r') assert result == File.open().__enter__().read()
def test_service_file_safe_path(patch, story): patch.object(story.app, 'get_tmp_dir', return_value='') assert File.safe_path(story, '../') == '/' assert File.safe_path(story, '/a') == '/a' assert File.safe_path(story, '../../../../') == '/'
async def test_service_file_write_bytes(story, line, file_io): story.execution_id = 'super_super_tmp' resolved_args = {'path': 'my_path', 'content': b'my_content'} await File.file_write(story, line, resolved_args) File.open.assert_called_with(f'{story.get_tmp_dir()}/my_path', 'wb') File.open().__enter__().write.assert_called_with(b'my_content')