forked from tomasvotava/tap-airtable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement missing tests (tomasvotava#12)
- Loading branch information
1 parent
2856159
commit 7176b9e
Showing
7 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |