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

Link to page block #73

Merged
merged 5 commits into from
Sep 15, 2022
Merged
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
8 changes: 4 additions & 4 deletions n2y/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,13 @@ def to_pandoc(self):
# TODO: in the future, if we are exporting the linked page too, then add
# a link to the page. For now, we just display the text of the page.

page = self.client.get_page_or_database(self.linked_page_id)
if page is None:
msg = "Permission denied when attempting to access linked page [%s]"
node = self.client.get_page_or_database(self.linked_page_id)
if node is None:
msg = "Permission denied when attempting to access linked node [%s]"
logger.warning(msg, self.notion_url)
return None
else:
title = page.title.to_pandoc()
title = node.title.to_pandoc()
return Para(title)


Expand Down
29 changes: 29 additions & 0 deletions n2y/notion_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,32 @@ def mock_select_option(name, **kwargs):

def mock_relation_value():
return {"id": mock_id()}


def mock_page(title="Mock Title"):
user = mock_user()
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
created_time = datetime.now().isoformat()
notion_id = mock_id()
hyphenated_title = title.replace(" ", "-")
return {
'object': 'page',
'id': notion_id,
'created_time': created_time,
'last_edited_time': created_time,
'created_by': user,
'last_edited_by': user,
'cover': None,
'icon': None,
'parent': {'type': 'page_id', 'page_id': mock_id()},
'archived': False,
'properties': {
'title': {
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
'id': 'title',
'type': 'title',
'title': mock_rich_text_array([
(title, []),
]),
}
},
'url': f'https://www.notion.so/{hyphenated_title}-{notion_id}',
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
}
34 changes: 9 additions & 25 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
mock_paragraph_block,
mock_rich_text,
mock_page_mention,
mock_page,
)


Expand Down Expand Up @@ -592,32 +593,15 @@ def test_synced_block_unshared():
assert unshared_reference_markdown == ""


@pytest.mark.xfail(reason="Not fully implemented")
def test_link_to_page_page():
# TODO: implement these tests; use mock.patch to mockout the notion API's
# response to the get_database_or_page call inside the default linktopage thing
# Also, create a separate `mock_page` and `mock_database` calls to test.
# Follow the format of the data in the Notion API docs for these
mock_page_id = mock_id()
notion_block = mock_block(
"link_to_page", {"type": "page_id", "page_id": mock_page_id}
)
pandoc_ast, markdown = process_block(notion_block)
assert pandoc_ast == Para([Str("All Blocks Test Page")])
assert markdown == "All Blocks Test Page\n"


@pytest.mark.xfail(reason="Not fully implemented")
def test_link_to_page_database():
mock_database_id = mock_id()
notion_block = mock_block(
"link_to_page", {"type": "database_id", "database_id": mock_database_id}
)

pandoc_ast, markdown = process_block(notion_block)

assert pandoc_ast == Para([Str("Simple Test Database")])
assert markdown == "Simple Test Database\n"
mock_link_to_page_block = mock_block(
"link_to_page", {"type": "page_id", "page_id": mock_id()},
)
page = mock_page("Linked Page")
with mock.patch("n2y.notion.Client._get_url", return_value=page):
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
pandoc_ast, markdown = process_block(mock_link_to_page_block)
assert pandoc_ast == Para([Str("Linked"), Space(), Str("Page")])
assert markdown == "Linked Page\n"


def test_column_block():
Expand Down