Skip to content

Commit

Permalink
fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
lastorel committed Sep 26, 2022
1 parent 7fabcbc commit eb983d1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v1.3.1
- [#32](https://github.com/lastorel/pytion/issues/32): Rollback of Page retrieving with properties

## v1.3.0

- [#27](https://github.com/lastorel/pytion/issues/27): Switched from `2022-02-22` to `2022-06-28` version of Notion API
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ See [Change Log](./CHANGELOG.md)

1. [Quick Start](#quick-start)
2. [Pytion API](#pytion-api)
1. [pytion.api.Element](#pytionapielement)
1. [Searching](#search)
2. [pytion.api.Element](#pytionapielement)
3. [Models](#models)
1. [pytion.models](#pytionmodels)
2. [Supported block types](#supported-block-types)
3. [Block creating examples](#block-creating-examples)
3. [Supported Property types](#supported-property-types)
4. [Block creating examples](#block-creating-examples)
4. [Logging](#logging)

## Quick start
Expand Down Expand Up @@ -162,6 +164,7 @@ There is a list of available methods for communicate with **api.notion.com**. Th
`.get_page_property(property_id, id_, limit)` - Retrieve a page property item.

`.get_page_properties(title_only, obj)` - Retrieve the title or all properties of current Page or Page `obj`
*(deprecated, useful for v1.3.0 only)*

`.db_query(id_, limit, filter_, sorts)` - Query Database.

Expand Down Expand Up @@ -210,7 +213,6 @@ There are classes **based on API** structures:
- use `.db_filter()` to get database content with filtering and/or sorting
- `Page` based on [Page object](https://developers.notion.com/reference/page)
- You can create object `Page.create(...)` and/or use `.page_create(...)` API method
- use `.get_page_properties()` to retrieve page title and other `PropertyValue`-s
- use `.page_update()` method to modify attributes or delete the page
- use `.get_block_children()` to get page content (without nested blocks) (it will be `BlockArray`)
- use `.get_block_children_recursive()` to get page content with nested blocks
Expand Down
6 changes: 2 additions & 4 deletions pytion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def get_block_children_recursive(

def get_page_property(self, property_id: str, id_: Optional[str] = None, limit: int = 0) -> Optional[Element]:
"""
DEPRECATED
Retrieve a page property item.
:param property_id: ID of property in current database
Expand Down Expand Up @@ -300,10 +301,7 @@ def db_query(
)
if r["object"] != "list":
return None
pa = Element(api=self.api, name="pages", obj=PageArray(r["results"]))
for p in pa.obj:
pa.get_page_properties(title_only=True, obj=p)
return pa
return Element(api=self.api, name="pages", obj=PageArray(r["results"]))

def db_filter(self, title: str = None, **kwargs) -> Optional[Element]:
"""
Expand Down
9 changes: 7 additions & 2 deletions pytion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,15 @@ def __init__(self, **kwargs) -> None:
self.url: str = kwargs.get("url")
self.children = kwargs["children"] if "children" in kwargs else LinkTo(block=self)
self.properties = {
name: (Property(data) if not isinstance(data, PropertyValue) else data)
name: (PropertyValue(data, name) if not isinstance(data, PropertyValue) else data)
for name, data in kwargs["properties"].items()
}
self.title = "unknown"
for p in self.properties.values():
if "title" in p.type:
self.title = p.value
break
else:
self.title = None

def __str__(self):
return str(self.title)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytion",
version="1.3.0",
version="1.3.1",
author="Yegor Gomzin",
author_email="slezycmex@mail.ru",
description="Unofficial Python client for official Notion API",
Expand All @@ -14,6 +14,7 @@
url="https://github.com/lastorel/pytion",
project_urls={
"Bug Tracker": "https://github.com/lastorel/pytion/issues",
"Changelog": "https://github.com/lastorel/pytion/blob/main/CHANGELOG.md",
},
classifiers=[
"Programming Language :: Python :: 3.7",
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ def page_for_pages(no):
@pytest.fixture(scope="session")
def page_for_updates(no):
page = no.pages.get("36223246a20e42df8f9b354ed1f11d75")
page.get_page_properties()
return page
29 changes: 6 additions & 23 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_get__page(self, root_page):
page = root_page
assert isinstance(page.obj, Page), "get of .pages. must return Page object"
assert page.obj.id == "878d628488d94894ab14f9b872cd6870"
page.get_page_properties()
assert str(page.obj.title) == "Pytion Tests"

def test_get__block(self, no):
Expand Down Expand Up @@ -90,7 +89,6 @@ def test_get_parent__block2(self, no):
parent_block = no.blocks.get_parent("8a920ba7dc1d4961811e5c82b28028ed") # Hello! How are you?
assert isinstance(parent_block.obj, Page)
assert parent_block.obj.id == "82ee5677402f44819a5da3302273400a"
parent_block.get_page_properties()
assert str(parent_block.obj) == "Page with some texts"

def test_get_parent__page(self, no):
Expand All @@ -113,7 +111,6 @@ def test_get_parent__block_obj(self, no):
parent_block = block.get_parent()
assert isinstance(parent_block.obj, Page)
assert parent_block.obj.id == "82ee5677402f44819a5da3302273400a"
parent_block.get_page_properties()
assert str(parent_block.obj) == "Page with some texts"

def test_get_parent__page_obj(self, no): # Database is the parent of this page
Expand All @@ -128,15 +125,13 @@ def test_get_parent__database_obj(self, little_database):
parent_page_block = database.get_parent()
assert isinstance(parent_page_block.obj, Page)
assert parent_page_block.obj.id == "878d628488d94894ab14f9b872cd6870"
parent_page_block.get_page_properties()
assert str(parent_page_block.obj) == "Pytion Tests"

def test_get_parent__child_page(self, no):
child_page = no.blocks.get("878d628488d94894ab14f9b872cd6870") # root page
page = child_page.get_parent()
assert isinstance(page.obj, Page)
assert page.obj.id == "878d628488d94894ab14f9b872cd6870"
page.get_page_properties()
assert str(page.obj.title) == "Pytion Tests"

def test_get_parent__child_database(self, no):
Expand Down Expand Up @@ -272,8 +267,8 @@ def test_get_page_property__bad_page(self, no):
def test_get_page_properties(self, no):
page = no.pages.get("b85877eaf7bf4245a8c5218055eeb81f") # Parent testing page
assert isinstance(page.obj, Page)
assert str(page.obj) == "unknown"
assert isinstance(page.obj.properties["Done"], Property)
# assert str(page.obj) == "unknown"
# assert isinstance(page.obj.properties["Done"], Property)
page.get_page_properties()
assert isinstance(page.obj.properties["Done"], PropertyValue)
assert page.obj.properties["Digit"].value == 2
Expand All @@ -282,11 +277,11 @@ def test_get_page_properties(self, no):
def test_get_page_properties__title(self, no):
page = no.pages.get("b85877eaf7bf4245a8c5218055eeb81f") # Parent testing page
assert isinstance(page.obj, Page)
assert str(page.obj) == "unknown"
assert isinstance(page.obj.properties["Done"], Property)
# assert str(page.obj) == "unknown"
# assert isinstance(page.obj.properties["Done"], Property)
page.get_page_properties(title_only=True)
assert hasattr(page.obj.properties["by"], "value") is False
assert isinstance(page.obj.properties["Done"], Property)
# assert hasattr(page.obj.properties["by"], "value") is False
# assert isinstance(page.obj.properties["Done"], Property)
assert str(page.obj.title) == "Parent testing page"

def test_db_query__id(self, no):
Expand Down Expand Up @@ -367,7 +362,6 @@ def test_db_filter__no_tags(self, little_database):

def test_db_filter__tag_property_obj(self, no, little_database):
page = no.pages.get("c2fc6b3dc3d244e9be2a3d28b26082bf") # Untitled
page.get_page_properties()
my_prop = page.obj.properties["Tags"]
pages = little_database.db_filter(property_obj=my_prop)
assert isinstance(pages.obj, PageArray)
Expand Down Expand Up @@ -468,7 +462,6 @@ def test_page_create__into_page(self, no, page_for_pages):
parent = LinkTo(from_object=page_for_pages.obj)
page = no.pages.page_create(parent=parent, title="Page 1")
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == "Page 1"
# delete section
delete_page = page.page_update(archived=True)
Expand All @@ -478,7 +471,6 @@ def test_page_create__into_database(self, no):
parent = LinkTo.create(database_id="35f50aa293964b0d93e09338bc980e2e") # Database for creating pages
page = no.pages.page_create(parent=parent, title="Page 2")
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == "Page 2"
# delete section
delete_page = page.page_update(archived=True)
Expand All @@ -493,7 +485,6 @@ def test_page_create__into_database_props(self, no):
}
page = no.pages.page_create(parent=parent, properties=props, title="Page 3")
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == "Page 3"
# delete section
delete_page = page.page_update(archived=True)
Expand All @@ -504,7 +495,6 @@ def test_page_create__with_children(self, no, page_for_pages):
child = Block.create("Hello, World!")
page = no.pages.page_create(parent=parent, title="Page 4", children=[child])
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == "Page 4"
blocks = page.get_block_children()
assert isinstance(blocks.obj, BlockArray)
Expand All @@ -520,7 +510,6 @@ def test_page_create__from_obj(self, no, page_for_pages):
page_obj = Page.create(parent=parent, title="Page 5")
page = no.pages.page_create(page_obj=page_obj)
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == "Page 5"
# delete section
delete_page = page.page_update(archived=True)
Expand All @@ -531,15 +520,12 @@ def test_page_update__rename(self, page_for_updates):
new_name = "Updating for page"
page = page_for_updates.page_update(title=new_name)
assert isinstance(page.obj, Page)
page.get_page_properties(title_only=True)
assert str(page.obj.title) == new_name

old_page = page.page_update(title=RichTextArray.create(old_name))
old_page.get_page_properties(title_only=True)
assert str(old_page.obj.title) == old_name

def test_page_update__change_props(self, page_for_updates):
page_for_updates.get_page_properties()
old_props = page_for_updates.obj.properties
new_props = {
"Tags": PropertyValue.create("multi_select", ["tag2"]),
Expand All @@ -548,12 +534,10 @@ def test_page_update__change_props(self, page_for_updates):
}
page = page_for_updates.page_update(properties=new_props)
assert isinstance(page.obj, Page)
page.get_page_properties()
assert "tag2" in page.obj.properties["Tags"].value
assert page.obj.properties["done"].value is False

old_page = page.page_update(properties=old_props)
old_page.get_page_properties()
assert "tag1" in old_page.obj.properties["Tags"].value
assert old_page.obj.properties["done"].value is True

Expand Down Expand Up @@ -650,7 +634,6 @@ def test_from_linkto__base(self, no):
page = no.pages.from_linkto(link)
assert isinstance(page.obj, Page)
assert page.obj.id == "878d628488d94894ab14f9b872cd6870"
page.get_page_properties(title_only=True)
assert str(page.obj) == "Pytion Tests"

def test_from_linkto__child(self, page_some_texts):
Expand Down

0 comments on commit eb983d1

Please sign in to comment.