Skip to content

Commit

Permalink
Merge pull request #25 from lastorel/dev-i23
Browse files Browse the repository at this point in the history
#23 fixed
  • Loading branch information
lastorel authored May 15, 2022
2 parents 8db2901 + 0bb1b79 commit b04d3e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pytion/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,12 @@ def block_update(
return None
if isinstance(id_, str) and "-" in id_:
id_ = id_.replace("-", "")
if block_obj:
self.obj = block_obj
if self.obj:
id_ = self.obj.id
else:
self.get(id_)
if block_obj:
self.obj = block_obj
if not self.obj.get():
return None
if new_text:
Expand Down
6 changes: 1 addition & 5 deletions pytion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def create(cls, type_: Optional[str] = "", **kwargs):
Property Schema Object (watch docs)
+ addons:
set type = `None` to delete this Property
set type_ = `None` to delete this Property
set param `name` to rename this Property
"""
return cls({"type": type_, **kwargs})
Expand Down Expand Up @@ -433,10 +433,6 @@ def get(self):
def create(cls, type_: str = "", value: Any = None, **kwargs):
"""
Property Value Object (watch docs)
+ addons:
set type = `None` to delete this Property
set param `name` to rename this Property
"""
return cls({"type": type_, type_: value, **kwargs}, name="")

Expand Down
19 changes: 18 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_block_update__rename(self, no):
block = no.blocks.get("08326405c2924ccc929bd78ceb70a2f3") # Paragraph block to update.
old_name = str(block.obj.text)
new_name = old_name + old_name
new_block = block.block_update(new_text=new_name)
new_block = no.blocks.block_update(id_="08326405c2924ccc929bd78ceb70a2f3", new_text=new_name)
assert isinstance(new_block.obj, Block)
assert str(new_block.obj.text) == new_name

Expand All @@ -519,6 +519,23 @@ def test_block_update__delete(self, no):
old_block = new_block.block_update(archived=False)
assert old_block.obj.archived is False

def test_block_update__obj_retype(self, no):
block_obj = Block.create("To do block", type_="to_do")
with pytest.raises(ValidationError):
no.blocks.block_update(id_="08326405c2924ccc929bd78ceb70a2f3", block_obj=block_obj)

def test_block_update__obj(self, no):
block = no.blocks.get("08326405c2924ccc929bd78ceb70a2f3") # Paragraph block to update.
old_block_obj = block.obj
new_name = "Updated paragraph block"
block_obj = Block.create(new_name)
new_block = block.block_update(block_obj=block_obj)
assert isinstance(new_block.obj, Block)
assert new_block.obj.simple == new_name

old_block = new_block.block_update(block_obj=old_block_obj)
assert str(old_block.obj) == old_block_obj.simple

def test_block_append__single(self, no):
page = no.pages.get("365985ab349149d7826035fd46858b3f") # Page for creating blocks
my_block = Block.create("Such wow!")
Expand Down

0 comments on commit b04d3e3

Please sign in to comment.