55from data_scribe .components .writers import NotionWriter
66from data_scribe .core .exceptions import ConfigError
77
8+
89@pytest .fixture
910def mock_db_catalog_data ():
1011 """Provides a mock catalog data structure for standard DB connections."""
@@ -50,7 +51,7 @@ def test_notion_writer_success(mock_notion_client, mock_db_catalog_data):
5051 mock_client_instance = MagicMock ()
5152 mock_client_instance .pages .create .return_value = {
5253 "id" : "new-page-id" ,
53- "url" : "http://notion.so/new-page-id"
54+ "url" : "http://notion.so/new-page-id" ,
5455 }
5556 mock_notion_client .return_value = mock_client_instance
5657
@@ -59,7 +60,7 @@ def test_notion_writer_success(mock_notion_client, mock_db_catalog_data):
5960 kwargs = {
6061 "api_token" : "fake_token" ,
6162 "parent_page_id" : "fake-parent-id" ,
62- "project_name" : "test_db"
63+ "project_name" : "test_db" ,
6364 }
6465
6566 # 3. Run
@@ -71,39 +72,51 @@ def test_notion_writer_success(mock_notion_client, mock_db_catalog_data):
7172 # 5. Assert Page Creation
7273 expected_title = "Data Catalog - test_db"
7374 expected_parent = {"page_id" : "fake-parent-id" }
74-
75+
7576 mock_client_instance .pages .create .assert_called_once ()
76-
77+
7778 # Get the arguments passed to pages.create
7879 create_args , create_kwargs = mock_client_instance .pages .create .call_args
79-
80+
8081 assert create_kwargs ["parent" ] == expected_parent
81- assert create_kwargs ["properties" ]["title" ][0 ]["text" ]["content" ] == expected_title
82-
82+ assert (
83+ create_kwargs ["properties" ]["title" ][0 ]["text" ]["content" ]
84+ == expected_title
85+ )
86+
8387 # Check that blocks were generated
8488 blocks = create_kwargs ["children" ]
8589 assert len (blocks ) > 0
86- assert blocks [0 ]["type" ] == "heading_2" # "🔎 Views"
87- assert blocks [0 ]["heading_2" ]["rich_text" ][0 ]["text" ]["content" ] == "🔎 Views"
90+ assert blocks [0 ]["type" ] == "heading_2" # "🔎 Views"
91+ assert (
92+ blocks [0 ]["heading_2" ]["rich_text" ][0 ]["text" ]["content" ] == "🔎 Views"
93+ )
8894 # Find the table H2
89- table_h2 = next (b for b in blocks if b .get ("type" ) == "heading_2" and "Tables" in b ["heading_2" ]["rich_text" ][0 ]["text" ]["content" ])
95+ table_h2 = next (
96+ b
97+ for b in blocks
98+ if b .get ("type" ) == "heading_2"
99+ and "Tables" in b ["heading_2" ]["rich_text" ][0 ]["text" ]["content" ]
100+ )
90101 assert table_h2 is not None
91102
92103
93104@patch .dict (os .environ , {"NOTION_TEST_KEY" : "env_key_value" })
94105@patch ("data_scribe.components.writers.notion_writer.Client" )
95- def test_notion_writer_resolves_env_var (mock_notion_client , mock_db_catalog_data ):
106+ def test_notion_writer_resolves_env_var (
107+ mock_notion_client , mock_db_catalog_data
108+ ):
96109 """
97110 Tests that the writer correctly resolves API tokens from environment variables.
98111 """
99- mock_notion_client .return_value = MagicMock () # Basic mock
100-
112+ mock_notion_client .return_value = MagicMock () # Basic mock
113+
101114 writer = NotionWriter ()
102115 kwargs = {
103- "api_token" : "${NOTION_TEST_KEY}" , # Reference the env var
116+ "api_token" : "${NOTION_TEST_KEY}" , # Reference the env var
104117 "parent_page_id" : "fake-parent-id" ,
105118 }
106-
119+
107120 writer .write (mock_db_catalog_data , ** kwargs )
108121
109122 # Assert client was initialized with the *resolved* key
@@ -118,14 +131,8 @@ def test_notion_writer_config_errors(mock_db_catalog_data):
118131
119132 # 1. Missing api_token
120133 with pytest .raises (ConfigError , match = "'api_token'.*is required" ):
121- writer .write (
122- mock_db_catalog_data ,
123- parent_page_id = "fake-parent-id"
124- )
134+ writer .write (mock_db_catalog_data , parent_page_id = "fake-parent-id" )
125135
126136 # 2. Missing parent_page_id
127137 with pytest .raises (ConfigError , match = "'parent_page_id' is required" ):
128- writer .write (
129- mock_db_catalog_data ,
130- api_token = "fake_token"
131- )
138+ writer .write (mock_db_catalog_data , api_token = "fake_token" )
0 commit comments