Skip to content

Commit

Permalink
Adds test for first() on hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Prickett committed Apr 25, 2022
1 parent 129ef95 commit e5c6c04
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/test_hash_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Member(BaseHashModel):
last_name: str = Field(index=True)
email: str = Field(index=True)
join_date: datetime.date
age: int = Field(index=True)
age: int = Field(index=True, sortable=True)
bio: str = Field(index=True, full_text_search=True)

class Meta:
Expand Down Expand Up @@ -357,6 +357,43 @@ def test_validation_passes(m):
)
assert member.first_name == "Andrew"

@pytest.mark.asyncio
async def test_retrieve_first(m):
member = m.Member(
first_name="Simon",
last_name="Prickett",
email="[email protected]",
join_date=today,
age=99,
bio="This is the bio field for this user.",
)

await member.save()

member2 = m.Member(
first_name="Another",
last_name="Member",
email="[email protected]",
join_date=today,
age=98,
bio="This is the bio field for this user.",
)

await member2.save()

member3 = m.Member(
first_name="Third",
last_name="Member",
email="[email protected]",
join_date=today,
age=97,
bio="This is the bio field for this user.",
)

await member3.save()

first_one = await m.Member.find().sort_by("age").first()
assert first_one == member3

@pytest.mark.asyncio
async def test_saves_model_and_creates_pk(m):
Expand Down

0 comments on commit e5c6c04

Please sign in to comment.