コード例 #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
ファイル: Story.py プロジェクト: zeebonk/platform-engine
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
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())
コード例 #4
0
ファイル: Story.py プロジェクト: zeebonk/platform-engine
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()
コード例 #5
0
ファイル: Story.py プロジェクト: zeebonk/platform-engine
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)