Skip to content

Commit

Permalink
test: implement missing tests (tomasvotava#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasvotava authored Jun 21, 2024
1 parent 2856159 commit 7176b9e
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
poetry run pre-commit run -a
test:
env:
AIRTABLE_INTEGRATION_TEST_TOKEN: "${{secrets.AIRTABLE_INTEGRATION_TEST_TOKEN}}"
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ addopts = [
"--cov-report=lcov",
]

# Singer SDK's deprecation warning
filterwarnings = [
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",
"ignore:.*pkg_resources.declare_namespace.*:DeprecationWarning",
"ignore:jsonschema.RefResolver:DeprecationWarning",
"ignore:Importing Validator directly:DeprecationWarning",
]


[tool.poetry.scripts]
# CLI declaration
tap-airtable = 'tap_airtable.tap:TapAirtable.cli'
Expand Down
5 changes: 0 additions & 5 deletions tap_airtable/tests/test_tap.py

This file was deleted.

File renamed without changes.
80 changes: 80 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

import dotenv
import pytest

from tap_airtable.client import AirtableClient
from tap_airtable.entities import AirtableBase, AirtableField, AirtableTable
from tap_airtable.tap import TapAirtable

test_base_foo = AirtableBase(
"foo",
"foo",
tables=[
AirtableTable(
id="table_1",
name="table_1",
fields=[
AirtableField("singleLineText", "field1", "field1"),
AirtableField("email", "email", "email"),
],
),
AirtableTable(
id="table_2",
name="table_2",
fields=[
AirtableField("dateTime", "created_at", "created_at"),
AirtableField("number", "number", "number"),
AirtableField("singleLineText", "name", "name"),
],
),
],
)

test_base_bar = AirtableBase(
"bar",
"bar",
tables=[
AirtableTable(
id="bar_table",
name="bar_table",
fields=[
AirtableField("singleLineText", "field1", "field1"),
AirtableField("singleLineText", "field2", "field2"),
AirtableField("singleLineText", "field3", "field3"),
AirtableField("singleLineText", "field4", "field4"),
],
)
],
)


@pytest.fixture()
def _patch_client(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("tap_airtable.client.AirtableClient.get_bases", lambda _, __: [test_base_foo, test_base_bar])


@pytest.fixture(name="integration_test_token", scope="session")
def integration_test_token_fixture() -> str:
try:
dotenv.load_dotenv()
token = os.environ["AIRTABLE_INTEGRATION_TEST_TOKEN"]
except KeyError:
pytest.skip("Integration tests cannot run without AIRTABLE_INTEGRATION_TEST_TOKEN variable.")
return token


@pytest.fixture()
def integration_test_tap(integration_test_token: str) -> TapAirtable:
return TapAirtable(
config={
"token": integration_test_token,
"base_ids": ["appwtyvkFPMTyR40b"],
"table_mapping": {"tblWqSoZj2A4uxTSR": "renamed_food"},
}
)


@pytest.fixture()
def integration_test_client(integration_test_token: str) -> AirtableClient:
return AirtableClient(integration_test_token)
19 changes: 19 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tap_airtable.client import AirtableClient
from tap_airtable.tap import TapAirtable


def test_discover_streams_integration(integration_test_tap: TapAirtable) -> None:
streams = integration_test_tap.discover_streams()

assert streams[0].name == "teams"
assert streams[1].name == "renamed_food"
assert streams[2].name == "faker_users"
assert streams[3].name == "faker_cars"

assert {stream.base_id for stream in streams} == {"appwtyvkFPMTyR40b"}


def test_client_get_records(integration_test_client: AirtableClient) -> None:
records = list(integration_test_client.get_records("appwtyvkFPMTyR40b", "tbl3SsrPtyxu3SiX6"))
assert len(records) == 3
assert set(records[0]["fields"].keys()) == {"Name", "Priority", "Flagged"}
42 changes: 42 additions & 0 deletions tests/test_tap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from tap_airtable.tap import TapAirtable


@pytest.mark.usefixtures("_patch_client")
def test_discover_streams() -> None:
tap = TapAirtable(config={"token": "token"})
streams = tap.discover_streams()
assert len(streams) == 3
assert streams[0].name == "table_1"
assert streams[0].base_id == "foo"
assert streams[0].original_airtable_table.name == "table_1"

assert streams[1].name == "table_2"
assert streams[1].base_id == "foo"
assert streams[1].original_airtable_table.name == "table_2"

assert streams[2].name == "bar_table"
assert streams[2].base_id == "bar"
assert streams[2].original_airtable_table.name == "bar_table"


@pytest.mark.usefixtures("_patch_client")
def test_discover_streams_mapping() -> None:
tap = TapAirtable(
config={
"token": "token",
"table_mapping": {"table_1": "Table 1", "table_2": "Table 2", "bar_table": "products"},
}
)

streams = tap.discover_streams()

assert streams[0].original_airtable_table.name == "Table 1"
assert streams[0].name == "table_1" # is slugified

assert streams[1].original_airtable_table.name == "Table 2"
assert streams[1].name == "table_2" # slugified

assert streams[2].original_airtable_table.name == "products"
assert streams[2].name == "products"

0 comments on commit 7176b9e

Please sign in to comment.