Skip to content

Commit

Permalink
SAT: unit tests test_state_with_abnormally_large_values + add missi…
Browse files Browse the repository at this point in the history
…ng `future_state_path` (#17791)
  • Loading branch information
alafanechere authored Oct 12, 2022
1 parent 07e5e35 commit 0cbd4de
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog

## 0.2.5
Unit test `test_state_with_abnormally_large_values` to check state emission testing is working.

## 0.2.4
Make incremental tests compatible with per stream states.[#16686](https://github.com/airbytehq/airbyte/pull/16686/)


## 0.2.3
Backward compatibility tests: improve `check_if_type_of_type_field_changed` to make it less radical when validating specs and allow `'str' -> ['str', '<another_type>']` type changes.[#16429](https://github.com/airbytehq/airbyte/pull/16429/)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY pytest.ini setup.py ./
COPY source_acceptance_test ./source_acceptance_test
RUN pip install .

LABEL io.airbyte.version=0.2.4
LABEL io.airbyte.version=0.2.5
LABEL io.airbyte.name=airbyte/source-acceptance-test

ENTRYPOINT ["python", "-m", "pytest", "-p", "source_acceptance_test.plugin", "-r", "fEsx"]
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,71 @@ def test_config_skip_test():

# This is guaranteed to fail when the test gets executed
docker_runner_mock.call_read.assert_not_called()


@pytest.mark.parametrize(
"read_output, expectation",
[
pytest.param([], pytest.raises(AssertionError), id="Error because incremental stream should always emit state messages"),
pytest.param(
[
AirbyteMessage(
type=Type.RECORD, record=AirbyteRecordMessage(stream="test_stream", data={"date": "2022-10-04"}, emitted_at=111)
),
AirbyteMessage(
type=Type.STATE,
state=AirbyteStateMessage(
type=AirbyteStateType.STREAM,
stream=AirbyteStreamState(
stream_descriptor=StreamDescriptor(name="test_stream"),
stream_state=AirbyteStateBlob.parse_obj({"date": "2022-10-04"}),
),
data={"date": "2022-10-04"},
),
),
],
pytest.raises(AssertionError),
id="Error because incremental sync with abnormally large state value should not produce record.",
),
pytest.param(
[
AirbyteMessage(
type=Type.STATE,
state=AirbyteStateMessage(
type=AirbyteStateType.STREAM,
stream=AirbyteStreamState(
stream_descriptor=StreamDescriptor(name="test_stream"),
stream_state=AirbyteStateBlob.parse_obj({"date": "2022-10-04"}),
),
data={"date": "2022-10-04"},
),
)
],
does_not_raise(),
),
],
)
def test_state_with_abnormally_large_values(mocker, read_output, expectation):
docker_runner_mock = mocker.MagicMock()
docker_runner_mock.call_read_with_state.return_value = read_output
t = _TestIncremental()
with expectation:
t.test_state_with_abnormally_large_values(
connector_config=mocker.MagicMock(),
configured_catalog=ConfiguredAirbyteCatalog(
streams=[
ConfiguredAirbyteStream(
stream=AirbyteStream(
name="test_stream",
json_schema={"type": "object", "properties": {"date": {"type": "date"}}},
supported_sync_modes=[SyncMode.full_refresh, SyncMode.incremental],
),
sync_mode=SyncMode.incremental,
destination_sync_mode=DestinationSyncMode.overwrite,
cursor_field=["date"],
)
]
),
future_state=mocker.MagicMock(),
docker_runner=docker_runner_mock,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests:
incremental:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
# future_state_path: "integration_tests/abnormal_state.json"
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
Original file line number Diff line number Diff line change
@@ -1,23 +1,79 @@
{
"customers": {
"date_modified": "2080-07-30T22:16:46"
[
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2080-07-30T22:16:46"
},
"stream_descriptor": {
"name": "customers"
}
}
},
"orders": {
"date_modified": "2080-07-30T22:16:46+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2080-07-30T22:16:46+00:00"
},
"stream_descriptor": {
"name": "orders"
}
}
},
"transactions": {
"id": 5783048848838997
{
"type": "STREAM",
"stream": {
"stream_state": {
"id": 5783048848838997
},
"stream_descriptor": {
"name": "transactions"
}
}
},
"pages": {
"id": 9000002039398998
{
"type": "STREAM",
"stream": {
"stream_state": {
"id": 9000002039398998
},
"stream_descriptor": {
"name": "pages"
}
}
},
"products": {
"date_modified": "2080-01-10T00:17:08+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2080-01-10T00:17:08+00:00"
},
"stream_descriptor": {
"name": "products"
}
}
},
"channels": {
"date_modified": "2080-01-10T00:17:08+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2080-01-10T00:17:08+00:00"
},
"stream_descriptor": {
"name": "channels"
}
}
},
"store": {
"store_id": 99199991999999199
{
"type": "STREAM",
"stream": {
"stream_state": {
"store_id": 99199991999999200
},
"stream_descriptor": {
"name": "store"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -1,23 +1,79 @@
{
"customers": {
"date_modified": "2021-08-11T15:18:55Z"
[
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2021-08-11T15:18:55Z"
},
"stream_descriptor": {
"name": "customers"
}
}
},
"orders": {
"date_modified": "2021-08-16T21:09:10+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2021-08-16T21:09:10+00:00"
},
"stream_descriptor": {
"name": "orders"
}
}
},
"transactions": {
"id": 0
{
"type": "STREAM",
"stream": {
"stream_state": {
"id": 0
},
"stream_descriptor": {
"name": "transactions"
}
}
},
"pages": {
"id": 4
{
"type": "STREAM",
"stream": {
"stream_state": {
"id": 4
},
"stream_descriptor": {
"name": "pages"
}
}
},
"products": {
"date_modified": "2022-01-10T00:17:08+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2022-01-10T00:17:08+00:00"
},
"stream_descriptor": {
"name": "products"
}
}
},
"channels": {
"date_modified": "2022-01-10T00:17:08+00:00"
{
"type": "STREAM",
"stream": {
"stream_state": {
"date_modified": "2022-01-10T00:17:08+00:00"
},
"stream_descriptor": {
"name": "channels"
}
}
},
"store": {
"store_id": 0
{
"type": "STREAM",
"stream": {
"stream_state": {
"store_id": 0
},
"stream_descriptor": {
"name": "store"
}
}
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ tests:
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: ['disputes', 'transfers', 'settlements', 'invoices']
empty_streams: ["disputes", "transfers", "settlements", "invoices"]
incremental:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "customers"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "disputes"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"created_at": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "invoices"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "refunds"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "settlements"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "subscriptions"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "transactions"
}
}
},
{
"type": "STREAM",
"stream": {
"stream_state": {
"createdAt": "2099-08-01T00:00:00Z"
},
"stream_descriptor": {
"name": "transfers"
}
}
}
]
Loading

0 comments on commit 0cbd4de

Please sign in to comment.