-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include data from parent resource in child resource: ported to a new …
…version
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ def load_github(): | |
} | ||
}, | ||
}, | ||
"include_from_parent": ["id"], | ||
}, | ||
], | ||
} | ||
|
Empty file.
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,51 @@ | ||
from tests.utils import ALL_DESTINATIONS, assert_load_info, load_table_counts | ||
import pytest | ||
import dlt | ||
|
||
from sources.rest_api import rest_api_source | ||
|
||
|
||
@pytest.mark.parametrize("destination_name", ALL_DESTINATIONS) | ||
def test_rest_api_source(destination_name: str) -> None: | ||
pipeline = dlt.pipeline( | ||
pipeline_name="rest_api", | ||
destination=destination_name, | ||
dataset_name="rest_api_data", | ||
full_refresh=True, | ||
) | ||
|
||
config = { | ||
"client": { | ||
"base_url": "https://pokeapi.co/api/v2/", | ||
}, | ||
"resource_defaults": { | ||
"endpoint": { | ||
"params": { | ||
"limit": 1000, | ||
}, | ||
} | ||
}, | ||
"resources": [ | ||
"pokemon", | ||
"berry", | ||
"location", | ||
], | ||
} | ||
|
||
load_info = pipeline.run(rest_api_source(config)) | ||
print(load_info) | ||
assert_load_info(load_info) | ||
table_names = [t["name"] for t in pipeline.default_schema.data_tables()] | ||
table_counts = load_table_counts(pipeline, *table_names) | ||
|
||
assert table_counts.keys() == {"pokemon", "berry", "location"} | ||
|
||
assert table_counts["pokemon"] == 1302 | ||
assert table_counts["berry"] == 64 | ||
assert table_counts["location"] == 1036 | ||
|
||
|
||
# TODO: Add incorrect config test | ||
# - incorrect default_resource (missing endpoint, nested params) | ||
# - incorrect resources | ||
# - incorrect key (default_resource) |