Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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, '../../../../') == '/'
Ejemplo n.º 5
0
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')