Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notion): pages resource returns only meta info #460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sources/notion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def notion_pages(
"""
client = NotionClient(api_key)
pages = client.search(filter_criteria={"value": "page", "property": "object"})

for page in pages:
blocks = client.fetch_resource("blocks", page["id"], "children")["results"]
if page_ids and page["id"] not in page_ids:
continue
yield page

if blocks:
yield blocks


@dlt.source
Expand Down
28 changes: 16 additions & 12 deletions tests/notion/test_pages_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ def test_load_all_pages(destination_name: str):
loaded_tables = set(t["name"] for t in pipeline.default_schema.data_tables())

expected_tables = {
"notion_pages__properties__second_db_related__relation",
"notion_pages__properties__second_db__relation",
"notion_pages__properties__account_owner__people",
"notion_pages__properties__title__title",
"notion_pages",
"notion_pages__properties__text_property__rich_text",
"notion_pages__properties__name__title",
"notion_pages__properties__company__rich_text",
"notion_pages__heading_1__rich_text",
"notion_pages__bulleted_list_item__rich_text",
}

assert loaded_tables == expected_tables
Expand All @@ -36,20 +31,29 @@ def test_load_all_pages(destination_name: str):

@pytest.mark.parametrize("destination_name", ALL_DESTINATIONS)
def test_load_selected_pages(destination_name: str):
page_id = "29298248-6067-4332-b6db-ca516d4d9af3"

pipeline = dlt.pipeline(
pipeline_name="notion",
destination=destination_name,
dataset_name="notion_data",
full_refresh=True,
)

requested_pages = ["06e48554-9585-415b-bffe-aad4b2244f20"]

info = pipeline.run(notion_pages(requested_pages))
info = pipeline.run(notion_pages(page_ids=[page_id]))
assert_load_info(info)

assert load_table_counts(pipeline, "notion_pages")["notion_pages"] == 1
loaded_tables = set(t["name"] for t in pipeline.default_schema.data_tables())
expected_tables = {
"notion_pages",
"notion_pages__heading_1__rich_text",
"notion_pages__bulleted_list_item__rich_text",
}

assert loaded_tables == expected_tables

with pipeline.sql_client() as client:
with client.execute_query("SELECT * FROM notion_pages") as cur:
assert cur.fetchone()[1] in requested_pages
row = cur.fetchone()
assert row[0] == "block"
assert row[3] == page_id
Copy link
Collaborator Author

@IlyaFaer IlyaFaer May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the resource type and id of the parent page (as it was requested)

Loading