예제 #1
0
async def test_story_run_prepare(patch, app, logger, async_mock):
    patch.object(Story, 'execute', new=async_mock())
    patch.object(Story, 'story')
    await Story.run(app, logger, 'story_name', context='context')
    Story.story().prepare.assert_called_with('context')
    Story.execute.mock \
        .assert_called_with(logger, Story.story())
예제 #2
0
async def test_story_run_metrics_exc(patch, app, logger, async_mock, magic):
    patch.object(time, 'time')
    assert Metrics.story_run_total is not None
    assert Metrics.story_run_failure is not None
    Metrics.story_run_total = magic()
    Metrics.story_run_failure = magic()

    def exc():
        raise Exception()

    patch.object(Story, 'execute', new=async_mock(side_effect=exc))
    patch.object(Story, 'story')
    with pytest.raises(Exception):
        await Story.run(app, logger, 'story_name')
    Story.story.assert_called_with(app, logger, 'story_name')
    Story.story.return_value.prepare.assert_called_with(None)
    Story.execute.mock.assert_called_with(logger, Story.story())

    Metrics.story_run_total.labels.assert_called_with(app_id=app.app_id,
                                                      story_name='story_name')
    Metrics.story_run_total.labels.return_value.observe.assert_called_once()

    Metrics.story_run_failure.labels\
        .assert_called_with(app_id=app.app_id, story_name='story_name')
    Metrics.story_run_failure.labels.return_value.observe.assert_called_once()
예제 #3
0
def test_format_command_no_args(logger, app, echo_service, echo_line):
    story = Story.story(app, logger, 'echo.story')
    app.services = echo_service

    echo_service['alpine'][
        ServiceConstants.config]['actions']['echo']['arguments'] = None

    cmd = Containers.format_command(story, echo_line, 'alpine', 'echo')
    assert ['echo'] == cmd
예제 #4
0
def test_format_command_no_format(logger, app, echo_service, echo_line):
    story = Story.story(app, logger, 'echo.story')
    app.services = echo_service

    config = app.services['alpine'][ServiceConstants.config]
    config['actions']['echo']['format'] = None

    cmd = Containers.format_command(story, echo_line, 'alpine', 'echo')
    assert ['echo', '{"msg":"foo"}'] == cmd
예제 #5
0
async def test_story_run_prepare_block(patch, app, logger, async_mock):
    patch.object(Story, 'execute_block', new=async_mock())
    patch.object(Story, 'story')
    block = '1'
    await Story.run(app, logger, 'story_name', context='context', block=block)
    Story.story().prepare.assert_called_with('context')
    Story.story().line.assert_called_with(block)
    Story.story().new_frame.assert_called_with(block)
    Story.execute_block.mock \
        .assert_called_with(logger, Story.story(),
                            Story.story().line())
예제 #6
0
def test_format_command_with_format(patch, logger, app, echo_service,
                                    echo_line):
    story = Story.story(app, logger, 'echo.story')
    patch.object(story, 'argument_by_name', return_value='asyncy')
    app.services = echo_service

    config = app.services['alpine'][ServiceConstants.config]
    config['actions']['echo']['format'] = 'echo {msg}'

    cmd = Containers.format_command(story, echo_line, 'alpine', 'echo')
    assert ['echo', 'asyncy'] == cmd
예제 #7
0
async def test_story_run_prepare_function(patch, app, logger, async_mock):
    patch.object(Story, 'execute_function', new=async_mock())
    patch.object(Story, 'story')
    function_name = 'function_name'
    await Story.run(app, logger, 'story_name',
                    context='context', function_name=function_name)
    Story.story().prepare.assert_called_with('context')
    Story.story().function_line_by_name.assert_called_with(function_name)
    Story.execute_function.mock \
        .assert_called_with(logger, Story.story(),
                            Story.story().function_line_by_name())
예제 #8
0
async def test_story_run(patch, app, logger, async_mock, magic):
    patch.object(time, 'time')
    patch.object(Story, 'execute', new=async_mock())
    patch.object(Story, 'story')
    assert Metrics.story_run_total is not None
    assert Metrics.story_run_success is not None
    Metrics.story_run_total = magic()
    Metrics.story_run_success = magic()

    await Story.run(app, logger, 'story_name')
    Story.story.assert_called_with(app, logger, 'story_name')
    Story.story.return_value.prepare.assert_called_with(None)
    Story.execute.mock.assert_called_with(logger, Story.story())

    Metrics.story_run_total.labels.assert_called_with(app_id=app.app_id,
                                                      story_name='story_name')
    Metrics.story_run_total.labels.return_value.observe.assert_called_once()

    Metrics.story_run_success.labels \
        .assert_called_with(app_id=app.app_id, story_name='story_name')
    Metrics.story_run_success.labels.return_value.observe.assert_called_once()
예제 #9
0
def test_format_command_no_spec(logger, app, echo_line):
    story = Story.story(app, logger, 'echo.story')
    app.services = {}
    with pytest.raises(ContainerSpecNotRegisteredError):
        Containers.format_command(story, echo_line, 'alpine', 'echo')
예제 #10
0
def test_format_command(logger, app, echo_service, echo_line):
    story = Story.story(app, logger, 'echo.story')
    app.services = echo_service

    cmd = Containers.format_command(story, echo_line, 'alpine', 'echo')
    assert ['echo', '{"msg":"foo"}'] == cmd
예제 #11
0
def test_story_save_logger(logger, story):
    story.app_id = 'app_id'
    Story.save(logger, story, None)
    assert logger.log.call_count == 1
예제 #12
0
def test_story_story(patch, app, logger):
    patch.init(Stories)
    story = Story.story(app, logger, 'story_name')
    Stories.__init__.assert_called_with(app, 'story_name', logger)
    assert isinstance(story, Stories)