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 4 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
44 changes: 44 additions & 0 deletions n2y/notion_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,47 @@ def mock_select_option(name, **kwargs):

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


def mock_page(title="Mock Title"):

# Returns a mock version the data that would be returned by
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
# the Notion API on a client.get_page() request.

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(" ", "-")

page_object = {
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
'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': [{
'type': 'text', 'text': {'content': title, 'link': None},
'annotations': {
'bold': False,
'italic': False,
'strikethrough': False,
'underline': False,
'code': False,
'color': 'default'},
Copy link
Contributor

Choose a reason for hiding this comment

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

See other comment about trailing parens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. And the mock_rich_text_array() call took care of it anyway.

'plain_text': title, 'href': None
}]
}
},
'url': f'https://www.notion.so/{hyphenated_title}-{notion_id}',
johndgiese marked this conversation as resolved.
Show resolved Hide resolved
}

return page_object
24 changes: 12 additions & 12 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,19 +593,18 @@ 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"

mock_link_to_page_block = mock_block(
"link_to_page", {"type": "page_id", "page_id": mock_id()})
johndgiese marked this conversation as resolved.
Show resolved Hide resolved

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"


@pytest.mark.xfail(reason="Not fully implemented")
Expand Down