-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from VianneyMI/75-cannot-group-with-more-than-…
…one-field-name 75-cannot-group-with-more-than-one-field-name
- Loading branch information
Showing
9 changed files
with
195 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
"""Module to test group (temp)""" | ||
|
||
#from dictdiffer import diff | ||
from monggregate import Pipeline | ||
from monggregate.stages.group import Group | ||
|
||
|
||
def test_group_stage(): | ||
"""Test group stage""" | ||
|
||
# Test by as list | ||
# ------------------------------ | ||
assert Group( | ||
by=["name", "age"], | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
).statement == { | ||
"$group":{ | ||
"_id":["$name", "$age"], | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
|
||
# Test by as set | ||
# ------------------------------ | ||
group = Group( | ||
by={"name", "age"}, | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
) | ||
|
||
expected_statement = { | ||
"$group":{ | ||
"_id":["$age", "$name"], | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
assert group.statement == expected_statement | ||
#, list(diff(expected_statement, group.statement)) | ||
|
||
|
||
# Test by as dict | ||
# ------------------------------ | ||
assert Group( | ||
by={"name":"$name", "age":"$age"}, | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
).statement == { | ||
"$group":{ | ||
"_id":{"name":"$name", "age":"$age"}, | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
|
||
def test_group_in_pipeline(): | ||
|
||
# Reproduce tests above with pipeline | ||
# ----------------------------------- | ||
# | ||
# Test by as list | ||
# ------------------------------ | ||
|
||
assert Pipeline().group( | ||
by=["name", "age"], | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
).statement == [ | ||
{ | ||
"$group":{ | ||
"_id":["$name", "$age"], | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
] | ||
|
||
# Test by as set | ||
# ------------------------------ | ||
assert Pipeline().group( | ||
by={"name", "age"}, | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
).statement == [ | ||
{ | ||
"$group":{ | ||
"_id":["$age", "$name"], | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
] | ||
|
||
# Test by as dict | ||
# ------------------------------ | ||
assert Pipeline().group( | ||
by={"name":"$name", "age":"$age"}, | ||
query = { | ||
"output":{"$sum":"income"} | ||
} | ||
).statement == [ | ||
{ | ||
"$group":{ | ||
"_id":{"name":"$name", "age":"$age"}, | ||
"output":{"$sum":"income"} | ||
} | ||
} | ||
] | ||
|
||
if __name__ == "__main__": | ||
test_group_stage() | ||
test_group_in_pipeline() | ||
print("All tests passed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters