def test_return_early_if_no_records_after_filtering( metadata, exc_ctx, mocker: MockerFixture, app_runner, ): """Records with no drillstring get deleted and app returns early.""" event = StreamTimeEvent( asset_id=0, company_id=1, records=[ StreamTimeRecord( timestamp=2, data=WitsRecordData(bit_depth=3, gamma_ray=4).dict(), metadata=metadata, ) ], ) mocker.patch.object( Api, 'get_dataset', side_effect=Exception('test_return_early_if_no_records_after_filtering'), ) with exc_ctx: app_runner(lambda_handler, event)
def test_fail_if_couldnt_post( exc_ctx, status_code, mocker: MockerFixture, requests_mock: requests_mock_lib.Mocker, app_runner, ): event = StreamTimeEvent( asset_id=0, company_id=1, records=[ StreamTimeRecord( timestamp=2, data=WitsRecordData(bit_depth=3, gamma_ray=4).dict(), metadata=WitsRecordMetadata(drillstring='5').dict(by_alias=True), ) ], ) mocker.patch.object( Api, 'get_dataset', return_value=[], ) post_mock = requests_mock.post(requests_mock_lib.ANY, status_code=status_code) with exc_ctx: app_runner(lambda_handler, event) assert post_mock.called_once
def test_stream_time_app(app_runner): # <.> event = StreamTimeEvent( # <.> asset_id=0, company_id=0, records=[StreamTimeRecord(timestamp=0)]) result = app_runner(stream_app, event=event) # <.> assert result == 'Hello, World!' # <.>
def parse_event(event: StreamTimeEvent) -> Optional[GammaDepthEvent]: event = GammaDepthEvent.parse_obj(event) new_records = GammaDepthEvent.filter_records(event=event) # return early if there are no records left after filtering if not new_records: return None new_event = event.copy(update={'records': new_records}, deep=True) return new_event
def test_gamma_depth_1( family, has_gamma_sensor, gamma_sensor_to_bit_distance, mocker: MockerFixture, app_runner, ): event = StreamTimeEvent( asset_id=0, company_id=1, records=[ StreamTimeRecord( timestamp=2, data=WitsRecordData(bit_depth=3, gamma_ray=4).dict(), metadata=WitsRecordMetadata(drillstring='5').dict(by_alias=True), ) ], ) drillstring = Drillstring( _id='5', data=DrillstringData( components=[ DrillstringDataComponent( family=family, has_gamma_sensor=has_gamma_sensor, gamma_sensor_to_bit_distance=gamma_sensor_to_bit_distance, ) ] ), ) expected_gamma_depth = 2.0 if drillstring.mwd_with_gamma_sensor else 3.0 _test_gamma_depth( event=event, drillstrings=[drillstring.dict(by_alias=True)], expected_gamma_depth=expected_gamma_depth, mocker=mocker, app_runner=app_runner, )
def test_gamma_depth_2( drillstrings, mwd_with_gamma_sensor, mocker: MockerFixture, app_runner ): event = StreamTimeEvent( asset_id=0, company_id=1, records=[ StreamTimeRecord( timestamp=2, data=WitsRecordData(bit_depth=3, gamma_ray=4).dict(), metadata=WitsRecordMetadata(drillstring='5').dict(by_alias=True), ) ], ) expected_gamma_depth = 2.0 if mwd_with_gamma_sensor else 3.0 _test_gamma_depth( event=event, drillstrings=drillstrings, expected_gamma_depth=expected_gamma_depth, mocker=mocker, app_runner=app_runner, )
def test_tutorial001(app_runner): event = StreamTimeEvent(asset_id=0, company_id=0, records=[StreamTimeRecord(timestamp=0)]) assert app_runner(tutorial001.stream_time_app, event) == 'Hello, World!'