diff --git a/notion_client/helpers.py b/notion_client/helpers.py index 5c5e661..7b339f5 100644 --- a/notion_client/helpers.py +++ b/notion_client/helpers.py @@ -104,3 +104,18 @@ def is_full_user(response: Dict[Any, Any]) -> bool: def is_full_comment(response: Dict[Any, Any]) -> bool: """Return `True` if response is a full comment.""" return "type" in response + + +def is_text_rich_text_item_response(rich_text: Dict[Any, Any]) -> bool: + """Return `True` if `rich_text` is a text.""" + return rich_text.get("type") == "text" + + +def is_equation_rich_text_item_response(rich_text: Dict[Any, Any]) -> bool: + """Return `True` if `rich_text` is an equation.""" + return rich_text.get("type") == "equation" + + +def is_mention_rich_text_item_response(rich_text: Dict[Any, Any]) -> bool: + """Return `True` if `rich_text` is a mention.""" + return rich_text.get("type") == "mention" diff --git a/tests/cassettes/test_is_equation_rich_text_item_response.yaml b/tests/cassettes/test_is_equation_rich_text_item_response.yaml new file mode 100644 index 0000000..3facb1b --- /dev/null +++ b/tests/cassettes/test_is_equation_rich_text_item_response.yaml @@ -0,0 +1,132 @@ +interactions: +- request: + body: '{"parent": {"page_id": "95ba0116-6776-4c19-9e45-54e77415f03b"}, "properties": + {"title": [{"text": {"content": "Test 2023-11-04 15:00:23.538078"}}]}, "children": + []}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '164' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: POST + uri: https://api.notion.com/v1/pages + response: + content: '{"object":"page","id":"cd594ab2-60e6-4080-bc1a-10e2b4ff7791","created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"cover":null,"icon":null,"parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"archived":false,"properties":{"title":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Test + 2023-11-04 15:00:23.538078","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Test + 2023-11-04 15:00:23.538078","href":null}]}},"url":"https://www.notion.so/Test-2023-11-04-15-00-23-538078-cd594ab260e64080bc1a10e2b4ff7791","public_url":null,"request_id":"52f4fe8a-e18a-4308-9059-510d5494cbd6"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '{"children": [{"paragraph": {"rich_text": [{"equation": {"expression": + "E = mc^2"}}]}}]}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '88' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: PATCH + uri: https://api.notion.com/v1/blocks/cd594ab2-60e6-4080-bc1a-10e2b4ff7791/children + response: + content: '{"object":"list","results":[{"object":"block","id":"3fa611db-c220-4be9-bed8-39294e4e6058","parent":{"type":"page_id","page_id":"cd594ab2-60e6-4080-bc1a-10e2b4ff7791"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"equation","equation":{"expression":"E + = mc^2"},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"E + = mc^2","href":null}],"color":"default"}}],"next_cursor":null,"has_more":false,"type":"block","block":{},"request_id":"5c6b693f-ac6b-4b2b-b2d0-d459867f3fec"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: GET + uri: https://api.notion.com/v1/blocks/3fa611db-c220-4be9-bed8-39294e4e6058 + response: + content: '{"object":"block","id":"3fa611db-c220-4be9-bed8-39294e4e6058","parent":{"type":"page_id","page_id":"cd594ab2-60e6-4080-bc1a-10e2b4ff7791"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"equation","equation":{"expression":"E + = mc^2"},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"E + = mc^2","href":null}],"color":"default"},"request_id":"8565fe0a-6cb1-4419-a573-5e1734e0a20b"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/3fa611db-c220-4be9-bed8-39294e4e6058 + response: + content: '{"object":"block","id":"3fa611db-c220-4be9-bed8-39294e4e6058","parent":{"type":"page_id","page_id":"cd594ab2-60e6-4080-bc1a-10e2b4ff7791"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"paragraph","paragraph":{"rich_text":[{"type":"equation","equation":{"expression":"E + = mc^2"},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"E + = mc^2","href":null}],"color":"default"},"request_id":"3f45697d-e41d-4594-9316-664ad4218563"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/cd594ab2-60e6-4080-bc1a-10e2b4ff7791 + response: + content: '{"object":"block","id":"cd594ab2-60e6-4080-bc1a-10e2b4ff7791","parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"child_page","child_page":{"title":"Test + 2023-11-04 15:00:23.538078"},"request_id":"4cce807e-f329-40b7-89e4-86f0375434c6"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +version: 1 diff --git a/tests/cassettes/test_is_mention_rich_text_item_response.yaml b/tests/cassettes/test_is_mention_rich_text_item_response.yaml new file mode 100644 index 0000000..9e26070 --- /dev/null +++ b/tests/cassettes/test_is_mention_rich_text_item_response.yaml @@ -0,0 +1,126 @@ +interactions: +- request: + body: '{"parent": {"page_id": "95ba0116-6776-4c19-9e45-54e77415f03b"}, "properties": + {"title": [{"text": {"content": "Test 2023-11-04 14:57:12.900460"}}]}, "children": + []}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '164' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: POST + uri: https://api.notion.com/v1/pages + response: + content: '{"object":"page","id":"b039260c-e8d3-4425-84bc-103f66ed886d","created_time":"2023-11-04T13:57:00.000Z","last_edited_time":"2023-11-04T13:57:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"cover":null,"icon":null,"parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"archived":false,"properties":{"title":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Test + 2023-11-04 14:57:12.900460","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Test + 2023-11-04 14:57:12.900460","href":null}]}},"url":"https://www.notion.so/Test-2023-11-04-14-57-12-900460-b039260ce8d3442584bc103f66ed886d","public_url":null,"request_id":"530b78a7-8893-4e46-ae0e-aa4870706dab"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '{"children": [{"paragraph": {"rich_text": [{"mention": {"type": "date", + "date": {"start": "2022-12-16", "end": null}}}]}}]}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '123' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: PATCH + uri: https://api.notion.com/v1/blocks/b039260c-e8d3-4425-84bc-103f66ed886d/children + response: + content: '{"object":"list","results":[{"object":"block","id":"c4f72aa9-81c5-4c6a-82b3-aa93c30822cd","parent":{"type":"page_id","page_id":"b039260c-e8d3-4425-84bc-103f66ed886d"},"created_time":"2023-11-04T13:57:00.000Z","last_edited_time":"2023-11-04T13:57:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"mention","mention":{"type":"date","date":{"start":"2022-12-16","end":null,"time_zone":null}},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"2022-12-16","href":null}],"color":"default"}}],"next_cursor":null,"has_more":false,"type":"block","block":{},"request_id":"274a2342-f82d-48a1-8679-4625580e5045"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: GET + uri: https://api.notion.com/v1/blocks/c4f72aa9-81c5-4c6a-82b3-aa93c30822cd + response: + content: '{"object":"block","id":"c4f72aa9-81c5-4c6a-82b3-aa93c30822cd","parent":{"type":"page_id","page_id":"b039260c-e8d3-4425-84bc-103f66ed886d"},"created_time":"2023-11-04T13:57:00.000Z","last_edited_time":"2023-11-04T13:57:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"mention","mention":{"type":"date","date":{"start":"2022-12-16","end":null,"time_zone":null}},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"2022-12-16","href":null}],"color":"default"},"request_id":"b361a703-25c5-4d0d-96f4-6323869598c4"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/c4f72aa9-81c5-4c6a-82b3-aa93c30822cd + response: + content: '{"object":"block","id":"c4f72aa9-81c5-4c6a-82b3-aa93c30822cd","parent":{"type":"page_id","page_id":"b039260c-e8d3-4425-84bc-103f66ed886d"},"created_time":"2023-11-04T13:57:00.000Z","last_edited_time":"2023-11-04T13:57:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"paragraph","paragraph":{"rich_text":[{"type":"mention","mention":{"type":"date","date":{"start":"2022-12-16","end":null,"time_zone":null}},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"2022-12-16","href":null}],"color":"default"},"request_id":"7a51618e-0673-4a93-b238-de2e77dc37e9"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/b039260c-e8d3-4425-84bc-103f66ed886d + response: + content: '{"object":"block","id":"b039260c-e8d3-4425-84bc-103f66ed886d","parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"created_time":"2023-11-04T13:57:00.000Z","last_edited_time":"2023-11-04T13:57:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"child_page","child_page":{"title":"Test + 2023-11-04 14:57:12.900460"},"request_id":"526bd552-2829-4893-bd0f-64929b344f50"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +version: 1 diff --git a/tests/cassettes/test_is_text_rich_text_item_response.yaml b/tests/cassettes/test_is_text_rich_text_item_response.yaml new file mode 100644 index 0000000..40e7664 --- /dev/null +++ b/tests/cassettes/test_is_text_rich_text_item_response.yaml @@ -0,0 +1,132 @@ +interactions: +- request: + body: '{"parent": {"page_id": "95ba0116-6776-4c19-9e45-54e77415f03b"}, "properties": + {"title": [{"text": {"content": "Test 2023-11-04 15:00:20.850229"}}]}, "children": + []}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '164' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: POST + uri: https://api.notion.com/v1/pages + response: + content: '{"object":"page","id":"671bf8c4-b59a-47fc-95f1-2619e93b8e8e","created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"cover":null,"icon":null,"parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"archived":false,"properties":{"title":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Test + 2023-11-04 15:00:20.850229","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Test + 2023-11-04 15:00:20.850229","href":null}]}},"url":"https://www.notion.so/Test-2023-11-04-15-00-20-850229-671bf8c4b59a47fc95f12619e93b8e8e","public_url":null,"request_id":"39d000ec-de7b-4dc6-ad0e-e7b0266dbe0d"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '{"children": [{"paragraph": {"rich_text": [{"text": {"content": "I''m a + paragraph."}}]}}]}' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + content-length: + - '89' + content-type: + - application/json + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: PATCH + uri: https://api.notion.com/v1/blocks/671bf8c4-b59a-47fc-95f1-2619e93b8e8e/children + response: + content: '{"object":"list","results":[{"object":"block","id":"8988b7c1-c451-4d20-b8b8-2ba43f83a6ef","parent":{"type":"page_id","page_id":"671bf8c4-b59a-47fc-95f1-2619e93b8e8e"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"text","text":{"content":"I''m + a paragraph.","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"I''m + a paragraph.","href":null}],"color":"default"}}],"next_cursor":null,"has_more":false,"type":"block","block":{},"request_id":"edf5a7eb-766d-4c0a-9970-0666f638a9ea"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: GET + uri: https://api.notion.com/v1/blocks/8988b7c1-c451-4d20-b8b8-2ba43f83a6ef + response: + content: '{"object":"block","id":"8988b7c1-c451-4d20-b8b8-2ba43f83a6ef","parent":{"type":"page_id","page_id":"671bf8c4-b59a-47fc-95f1-2619e93b8e8e"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":false,"type":"paragraph","paragraph":{"rich_text":[{"type":"text","text":{"content":"I''m + a paragraph.","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"I''m + a paragraph.","href":null}],"color":"default"},"request_id":"bb0cf4c9-d967-43be-9b6c-d76806023178"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/8988b7c1-c451-4d20-b8b8-2ba43f83a6ef + response: + content: '{"object":"block","id":"8988b7c1-c451-4d20-b8b8-2ba43f83a6ef","parent":{"type":"page_id","page_id":"671bf8c4-b59a-47fc-95f1-2619e93b8e8e"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"paragraph","paragraph":{"rich_text":[{"type":"text","text":{"content":"I''m + a paragraph.","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"I''m + a paragraph.","href":null}],"color":"default"},"request_id":"8437ff7e-6c0b-4008-8703-c52376f7bbdf"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +- request: + body: '' + headers: + accept: + - '*/*' + accept-encoding: + - gzip, deflate + authorization: + - secret_... + connection: + - keep-alive + host: + - api.notion.com + notion-version: + - '2022-06-28' + method: DELETE + uri: https://api.notion.com/v1/blocks/671bf8c4-b59a-47fc-95f1-2619e93b8e8e + response: + content: '{"object":"block","id":"671bf8c4-b59a-47fc-95f1-2619e93b8e8e","parent":{"type":"page_id","page_id":"95ba0116-6776-4c19-9e45-54e77415f03b"},"created_time":"2023-11-04T14:00:00.000Z","last_edited_time":"2023-11-04T14:00:00.000Z","created_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"last_edited_by":{"object":"user","id":"7775f3a3-893f-43fa-b625-460c61094c78"},"has_children":false,"archived":true,"type":"child_page","child_page":{"title":"Test + 2023-11-04 15:00:20.850229"},"request_id":"f30263cf-16ba-4cc5-b992-a5b823cba75f"}' + headers: {} + http_version: HTTP/1.1 + status_code: 200 +version: 1 diff --git a/tests/conftest.py b/tests/conftest.py index 71421ef..41f785f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -120,6 +120,44 @@ def comment_id(client, page_id) -> str: yield response["id"] +text_block_id = block_id + + +@pytest.fixture(scope="function") +def equation_block_id(client, page_id) -> str: + """create a block inside page_id that has an equation""" + children = [ + {"paragraph": {"rich_text": [{"equation": {"expression": "E = mc^2"}}]}} + ] + + response = client.blocks.children.append(block_id=page_id, children=children) + yield response["results"][0]["id"] + client.blocks.delete(block_id=response["results"][0]["id"]) + + +@pytest.fixture(scope="function") +def mention_block_id(client, page_id) -> str: + """create a block inside page_id that has a date mention""" + children = [ + { + "paragraph": { + "rich_text": [ + { + "mention": { + "type": "date", + "date": {"start": "2022-12-16", "end": None}, + } + } + ] + } + } + ] + + response = client.blocks.children.append(block_id=page_id, children=children) + yield response["results"][0]["id"] + client.blocks.delete(block_id=response["results"][0]["id"]) + + @pytest.fixture(scope="module") def client(token: Optional[str]): with Client({"auth": token}) as client: diff --git a/tests/test_helpers.py b/tests/test_helpers.py index ed90cfe..c61fb6d 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -8,12 +8,15 @@ collect_paginated_api, get_id, get_url, + is_equation_rich_text_item_response, is_full_block, is_full_comment, is_full_database, is_full_page, is_full_page_or_database, is_full_user, + is_mention_rich_text_item_response, + is_text_rich_text_item_response, iterate_paginated_api, pick, ) @@ -152,3 +155,21 @@ def test_is_full_user(client): def test_is_full_comment(client, page_id, comment_id): response = client.comments.list(block_id=page_id) assert is_full_comment(response) + + +@pytest.mark.vcr() +def test_is_text_rich_text_item_response(client, text_block_id): + response = client.blocks.retrieve(block_id=text_block_id) + assert is_text_rich_text_item_response(response["paragraph"]["rich_text"][0]) + + +@pytest.mark.vcr() +def test_is_equation_rich_text_item_response(client, equation_block_id): + response = client.blocks.retrieve(block_id=equation_block_id) + assert is_equation_rich_text_item_response(response["paragraph"]["rich_text"][0]) + + +@pytest.mark.vcr() +def test_is_mention_rich_text_item_response(client, mention_block_id): + response = client.blocks.retrieve(block_id=mention_block_id) + assert is_mention_rich_text_item_response(response["paragraph"]["rich_text"][0])