Skip to content

Commit

Permalink
Fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
tan-z-tan committed Aug 26, 2023
1 parent 507c0db commit b4bd21e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyfireconsole/models/pyfire_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def find(cls, path: str, allow_empty: bool = False) -> 'PyfireDoc':
if path.find('/') == -1:
collection_name = cls.collection_name()
id = path
path = f"{collection_name}/{id}"
else:
collection_name, id = path.rsplit('/', 1)

Expand Down
29 changes: 29 additions & 0 deletions tests/test_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@ def test_find_not_found(mock_db):
Book.find("99999")


def test_find_obj_ref_key(mock_db):
book = Book.new(
title="Math",
user_id="12345",
published_at=datetime.now(),
authors=["John", "Mary"],
publisher_ref="publisher/12345",
).save()

assert book.obj_ref_key() == f"books/{book.id}"
assert book.obj_collection_name() == "books"
assert Book.find(book.id).obj_ref_key() == f"books/{book.id}"


def test_deep_find_obj_ref_key(mock_db):
book = Book.new(
title="Math",
user_id="12345",
published_at=datetime.now(),
authors=["John", "Mary"],
publisher_ref=Publisher.new(name="publisher1").save().obj_ref_key(),
).save()

tag = book.tags.add(Tag.new(name="mathmatics"))

assert tag.obj_ref_key() == f"books/{book.id}/tags/{tag.id}"
assert Tag.find(f"books/{book.id}/tags/{tag.id}").obj_ref_key() == f"books/{book.id}/tags/{tag.id}"


def test_subcollection(mock_db):
book = Book.new(
title="Math",
Expand Down

0 comments on commit b4bd21e

Please sign in to comment.