Пример #1
0
def test_scheduled_app(app_runner):  # <.>
    event = ScheduledEvent(asset_id=0, start_time=0, end_time=0,
                           company_id=0)  # <.>

    result = app_runner(scheduled_app, event=event)  # <.>

    assert result == 'Hello, World!'  # <.>
Пример #2
0
def test_fail_if_post_unsuccessful(
    exc_ctx,
    status_code,
    mocker: MockerFixture,
    requests_mock: RequestsMocker,
    app_runner,
):
    event = ScheduledEvent(asset_id=0, company_id=1, start_time=2, end_time=3)
    wits_record = WitsRecord(
        asset_id=0,
        company_id=1,
        timestamp=2,
        data=WitsRecordData(bit_depth=3.0, gamma_ray=4.0),
        metadata=WitsRecordMetadata(drillstring=''),
    ).dict(by_alias=True)

    mocker.patch.object(
        Api,
        'get_dataset',
        side_effect=[[wits_record], []],
    )
    post_mock = requests_mock.post(
        f"/api/v1/data/{SETTINGS.provider}/{SETTINGS.actual_gamma_depth_collection}/",
        status_code=status_code,
    )

    with exc_ctx:
        app_runner(lambda_handler, event)

    assert post_mock.called_once
Пример #3
0
def _test_gamma_depth(
    drillstrings,
    expected_gamma_depth,
    mocker: MockerFixture,
    app_runner,
    wits_record,
):
    event = ScheduledEvent(asset_id=0, company_id=1, start_time=2, end_time=3)

    mocker.patch.object(
        Api,
        'get_dataset',
        side_effect=[[wits_record], drillstrings],
    )
    post_mock = mocker.patch.object(Api, 'post')

    app_runner(lambda_handler, event)

    assert post_mock.call_args.kwargs['data'] == [
        ActualGammaDepth(
            asset_id=wits_record['asset_id'],
            collection=SETTINGS.actual_gamma_depth_collection,
            company_id=wits_record['company_id'],
            data=ActualGammaDepthData(
                gamma_depth=expected_gamma_depth,
                bit_depth=wits_record['data']['bit_depth'],
                gamma_ray=wits_record['data']['gamma_ray'],
            ),
            provider=SETTINGS.provider,
            timestamp=wits_record['timestamp'],
            version=SETTINGS.version,
        ).dict()
    ]
Пример #4
0
def test_tutorial001(app_runner, mocker: MockerFixture):
    event = ScheduledEvent(asset_id=0, start_time=0, end_time=0, company_id=0)

    store_spy = mocker.spy(RedisState, 'store')
    load_spy = mocker.spy(RedisState, 'load')
    load_all_spy = mocker.spy(RedisState, 'load_all')

    app_runner(tutorial001.scheduled_app, event)

    assert store_spy.call_count == 5
    assert load_spy.call_count == 4
    assert load_all_spy.call_count == 1
Пример #5
0
def test_early_return_if_no_records_fetched(records, exc_ctx,
                                            mocker: MockerFixture, app_runner):
    event = ScheduledEvent(asset_id=0, company_id=1, start_time=2, end_time=3)

    mocker.patch.object(
        GammaDepthEvent,
        '__init__',
        side_effect=Exception('test_early_return_if_no_records_fetched'),
    )  # raise to return early
    mocker.patch.object(Api, 'get_dataset', return_value=records)

    with exc_ctx:
        app_runner(lambda_handler, event)
Пример #6
0
def test_tutorial003(delta: datetime.timedelta, ctx, app_runner,
                     mocker: MockerFixture):
    event = ScheduledEvent(asset_id=0, start_time=0, end_time=0, company_id=0)

    store_spy = mocker.spy(RedisState, 'store')
    ttl_spy = mocker.spy(RedisState, 'ttl')
    pttl_spy = mocker.spy(RedisState, 'pttl')
    exists_spy = mocker.spy(RedisState, 'exists')

    time_to_freeze = datetime.datetime(year=2021, month=1, day=1)
    with freezegun.freeze_time(time_to_freeze) as frozen_time:
        mocker.patch.object(
            time,
            'sleep',
            lambda *args, **kwargs: frozen_time.move_to(time_to_freeze + delta
                                                        ),
        )
        with ctx:
            app_runner(tutorial003.scheduled_app, event)

    assert store_spy.call_count == 2
    assert ttl_spy.call_count == 1
    assert pttl_spy.call_count == 1
    assert exists_spy.call_count == 2
Пример #7
0
def test_tutorial003(app_runner):
    event = ScheduledEvent(asset_id=0, start_time=0, end_time=0, company_id=0)

    assert app_runner(tutorial003.scheduled_app, event) == 'Hello, World!'