Skip to content

Commit 68c76f2

Browse files
committed
add unit tests
Signed-off-by: wiseaidev <[email protected]>
1 parent f6c76ac commit 68c76f2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/test_hash_model.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Order(BaseHashModel):
4343
created_on: datetime.datetime
4444

4545
class Member(BaseHashModel):
46+
id: int = Field(index=True)
4647
first_name: str = Field(index=True)
4748
last_name: str = Field(index=True)
4849
email: str = Field(index=True)
@@ -64,6 +65,7 @@ class Meta:
6465
@pytest_asyncio.fixture
6566
async def members(m):
6667
member1 = m.Member(
68+
id=0,
6769
first_name="Andrew",
6870
last_name="Brookins",
6971
@@ -73,6 +75,7 @@ async def members(m):
7375
)
7476

7577
member2 = m.Member(
78+
id=1,
7679
first_name="Kim",
7780
last_name="Brookins",
7881
@@ -82,6 +85,7 @@ async def members(m):
8285
)
8386

8487
member3 = m.Member(
88+
id=2,
8589
first_name="Andrew",
8690
last_name="Smith",
8791
@@ -129,6 +133,9 @@ async def test_exact_match_queries(members, m):
129133
).all()
130134
assert actual == [member2]
131135

136+
actual = await m.Member.find(m.Member.id == 0).all()
137+
assert actual == [member1]
138+
132139

133140
@py_test_mark_asyncio
134141
async def test_full_text_search_queries(members, m):
@@ -143,6 +150,19 @@ async def test_full_text_search_queries(members, m):
143150
assert actual == [member1, member3]
144151

145152

153+
@py_test_mark_asyncio
154+
async def test_pagination_queries(members, m):
155+
member1, member2, member3 = members
156+
157+
actual = await m.Member.find(m.Member.last_name == "Brookins").page()
158+
159+
assert actual == [member1, member2]
160+
161+
actual = await m.Member.find().page(1,2)
162+
163+
assert actual == [member1]
164+
165+
146166
@py_test_mark_asyncio
147167
async def test_recursive_query_resolution(members, m):
148168
member1, member2, member3 = members
@@ -611,4 +631,3 @@ class Address(m.BaseHashModel):
611631
assert (
612632
Address.redisearch_schema()
613633
== f"ON HASH PREFIX 1 {key_prefix} SCHEMA pk TAG SEPARATOR | a_string TAG SEPARATOR | a_full_text_string TAG SEPARATOR | a_full_text_string AS a_full_text_string_fts TEXT an_integer NUMERIC SORTABLE a_float NUMERIC"
614-
)

0 commit comments

Comments
 (0)