Skip to content

Commit

Permalink
#17 TestSort + add entry timestamp sort
Browse files Browse the repository at this point in the history
  • Loading branch information
lastorel committed May 22, 2022
1 parent 8c01bbd commit c42496f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pytion/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ def __repr__(self):
class Sort(object):
directions = ["ascending", "descending"]

def __init__(self, property_name: str, direction: str):
def __init__(self, property_name: str, direction: str = "ascending"):
if direction not in self.directions:
raise ValueError(f"Allowed types {self.directions} ({direction} is provided)")
self.sorts = [{"property": property_name, "direction": direction}]
if property_name in ("created_time", "last_edited_time"):
self.sorts = [{"timestamp": property_name, "direction": direction}]
else:
self.sorts = [{"property": property_name, "direction": direction}]

def add(self, property_name: str, direction: str):
if direction not in self.directions:
Expand Down
11 changes: 9 additions & 2 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,12 @@ def test_query__invalid_prop(self, little_database):
with pytest.raises(ValidationError):
little_database.db_query(sorts=s)

def test_query__timestamp(self):
pass
def test_query__timestamp(self, little_database):
s = Sort("last_edited_time")
r = little_database.db_query(sorts=s)
assert isinstance(r.obj[0], Page)
assert len(r.obj) == 4
assert str(r.obj[0]) == "wait, what?"
assert str(r.obj[2]) == "Parent testing page"
assert "friends" in str(r.obj[1])
assert bool(r.obj[3].title) is False

0 comments on commit c42496f

Please sign in to comment.