diff --git a/n2y/blocks.py b/n2y/blocks.py index c625fbd1..856ced95 100644 --- a/n2y/blocks.py +++ b/n2y/blocks.py @@ -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) diff --git a/n2y/notion_mocks.py b/n2y/notion_mocks.py index b336afb4..fa1efd93 100644 --- a/n2y/notion_mocks.py +++ b/n2y/notion_mocks.py @@ -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() + 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': { + 'id': 'title', + 'type': 'title', + 'title': mock_rich_text_array([ + (title, []), + ]), + } + }, + 'url': f'https://www.notion.so/{hyphenated_title}-{notion_id}', + } diff --git a/tests/test_blocks.py b/tests/test_blocks.py index 5391f3f7..1ff18ae4 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -48,6 +48,7 @@ mock_paragraph_block, mock_rich_text, mock_page_mention, + mock_page, ) @@ -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): + 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():