Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase coverage #39

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
Loading