Skip to content

Commit

Permalink
Update query op tests
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed Apr 13, 2022
1 parent 5b4af05 commit dce3d07
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/api/test_query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_pagination_functionality():

op = PaginationQuery()

assert op.query(skip=10, limit=20) == {"limit": 20, "skip": 10}
assert op.query(_skip=10, _limit=20) == {"limit": 20, "skip": 10}

with pytest.raises(HTTPException):
op.query(limit=10000)
Expand All @@ -42,7 +42,7 @@ def test_pagination_serialization():
with ScratchDir("."):
dumpfn(op, "temp.json")
new_op = loadfn("temp.json")
assert new_op.query(skip=10, limit=20) == {"limit": 20, "skip": 10}
assert new_op.query(_skip=10, _limit=20) == {"limit": 20, "skip": 10}


def test_sparse_query_functionality():
Expand All @@ -60,7 +60,9 @@ def test_sparse_query_serialization():
with ScratchDir("."):
dumpfn(op, "temp.json")
new_op = loadfn("temp.json")
assert new_op.query() == {"properties": ["name", "age", "weight", "last_updated"]}
assert new_op.query() == {
"properties": ["name", "age", "weight", "last_updated"]
}


def test_numeric_query_functionality():
Expand All @@ -69,7 +71,10 @@ def test_numeric_query_functionality():

assert op.meta() == {}
assert op.query(age_max=10, age_min=1, age_not_eq=[2, 3], weight_min=120) == {
"criteria": {"age": {"$lte": 10, "$gte": 1, "$ne": [2, 3]}, "weight": {"$gte": 120}}
"criteria": {
"age": {"$lte": 10, "$gte": 1, "$ne": [2, 3]},
"weight": {"$gte": 120},
}
}


Expand All @@ -87,7 +92,9 @@ def test_sort_query_functionality():

op = SortQuery()

assert op.query(sort_fields="volume,-density") == {"sort": {"volume": 1, "density": -1}}
assert op.query(_sort_fields="volume,-density") == {
"sort": {"volume": 1, "density": -1}
}


def test_sort_serialization():
Expand All @@ -97,7 +104,9 @@ def test_sort_serialization():
with ScratchDir("."):
dumpfn(op, "temp.json")
new_op = loadfn("temp.json")
assert new_op.query(sort_fields="volume,-density") == {"sort": {"volume": 1, "density": -1}}
assert new_op.query(_sort_fields="volume,-density") == {
"sort": {"volume": 1, "density": -1}
}


@pytest.fixture
Expand Down

0 comments on commit dce3d07

Please sign in to comment.