Skip to content

Commit

Permalink
Merge pull request #39 from mohamadkhalaj/main
Browse files Browse the repository at this point in the history
Increase coverage
  • Loading branch information
mohamadkhalaj authored Nov 5, 2023
2 parents 4c71c44 + f91a770 commit 442457e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 0 additions & 2 deletions aggify/aggify.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,6 @@ def lookup(
expected_list=[["local_field", "foreign_field"], "let"]
)
elif not let:
if not (local_field and foreign_field):
raise InvalidArgument(expected_list=["local_field", "foreign_field"])
lookup_stage = {
"$lookup": {
"from": from_collection_name,
Expand Down
11 changes: 0 additions & 11 deletions aggify/utilty.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
from aggify.types import CollectionType


def int_to_slice(final_index: int) -> slice:
"""
Converts an integer to a slice, assuming that the start index is 0.
Examples:
>>> int_to_slice(3)
slice(0, 2)
"""
return slice(0, final_index)


def to_mongo_positive_index(index: Union[int, slice]) -> slice:
if isinstance(index, int):
if index < 0:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_aggify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
InvalidOperator,
AlreadyExistsField,
InvalidEmbeddedField,
MongoIndexError,
)


Expand Down Expand Up @@ -597,3 +598,19 @@ def test_replace_base_invalid_embedded_field(self):
aggify = Aggify(BaseModel)
with pytest.raises(InvalidEmbeddedField):
aggify._replace_base("name")

def test_aggify_get_item_negative_index(self):
with pytest.raises(MongoIndexError):
var = Aggify(BaseModel).filter(name=1)[-1:1]

def test_aggify_get_item_slice_step_not_none(self):
with pytest.raises(MongoIndexError):
var = Aggify(BaseModel).filter(name=1)[slice(1, 3, 2)]

def test_aggify_get_item_slice_start_gte_stop(self):
with pytest.raises(MongoIndexError):
var = Aggify(BaseModel).filter(name=1)[slice(3, 1)]

def test_aggify_get_item_slice_negative_start(self):
with pytest.raises(MongoIndexError):
var = Aggify(BaseModel).filter(name=1)[slice(-5, -1)]

0 comments on commit 442457e

Please sign in to comment.