Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Tests for `monggregate.operators.accumulators.avg` module."""

from monggregate.operators.accumulators.avg import Average


class TestAverage:
"""Tests for `Average` class."""

def test_instantiation(self) -> None:
"""Test that `Average` class can be instantiated."""
average = Average(operand=1)
assert isinstance(average, Average)

def test_expression(self) -> None:
"""Test that `Average` class returns the correct expression."""

average = Average(operand=1)
assert average.expression == {"$avg": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.count` module."""

from monggregate.operators.accumulators.count import Count


class TestCount:
"""Tests for `Count` class."""

def test_instantiation(self) -> None:
"""Test that `Count` class can be instantiated."""
count_op = Count()
assert isinstance(count_op, Count)

def test_expression(self) -> None:
"""Test that `Count` class returns the correct expression."""
count_op = Count()
assert count_op.expression == {"$count": {}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.first` module."""

from monggregate.operators.accumulators.first import First


class TestFirst:
"""Tests for `First` class."""

def test_instantiation(self) -> None:
"""Test that `First` class can be instantiated."""
first_op = First(operand=1)
assert isinstance(first_op, First)

def test_expression(self) -> None:
"""Test that `First` class returns the correct expression."""
first_op = First(operand=1)
assert first_op.expression == {"$first": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.last` module."""

from monggregate.operators.accumulators.last import Last


class TestLast:
"""Tests for `Last` class."""

def test_instantiation(self) -> None:
"""Test that `Last` class can be instantiated."""
last_op = Last(operand=1)
assert isinstance(last_op, Last)

def test_expression(self) -> None:
"""Test that `Last` class returns the correct expression."""
last_op = Last(operand=1)
assert last_op.expression == {"$last": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.max` module."""

from monggregate.operators.accumulators.max import Max


class TestMax:
"""Tests for `Max` class."""

def test_instantiation(self) -> None:
"""Test that `Max` class can be instantiated."""
max_op = Max(operand=1)
assert isinstance(max_op, Max)

def test_expression(self) -> None:
"""Test that `Max` class returns the correct expression."""
max_op = Max(operand=1)
assert max_op.expression == {"$max": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.min` module."""

from monggregate.operators.accumulators.min import Min


class TestMin:
"""Tests for `Min` class."""

def test_instantiation(self) -> None:
"""Test that `Min` class can be instantiated."""
min_op = Min(operand=1)
assert isinstance(min_op, Min)

def test_expression(self) -> None:
"""Test that `Min` class returns the correct expression."""
min_op = Min(operand=1)
assert min_op.expression == {"$min": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.push` module."""

from monggregate.operators.accumulators.push import Push


class TestPush:
"""Tests for `Push` class."""

def test_instantiation(self) -> None:
"""Test that `Push` class can be instantiated."""
push_op = Push(operand=1)
assert isinstance(push_op, Push)

def test_expression(self) -> None:
"""Test that `Push` class returns the correct expression."""
push_op = Push(operand=1)
assert push_op.expression == {"$push": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.accumulators.sum` module."""

from monggregate.operators.accumulators.sum import Sum


class TestSum:
"""Tests for `Sum` class."""

def test_instantiation(self) -> None:
"""Test that `Sum` class can be instantiated."""
sum_op = Sum(operand=1)
assert isinstance(sum_op, Sum)

def test_expression(self) -> None:
"""Test that `Sum` class returns the correct expression."""
sum_op = Sum(operand=1)
assert sum_op.expression == {"$sum": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.arithmetic.add` module."""

from monggregate.operators.arithmetic.add import Add


class TestAdd:
"""Tests for `Add` class."""

def test_instantiation(self) -> None:
"""Test that `Add` class can be instantiated."""
add_op = Add(operands=[1, 2, 3])
assert isinstance(add_op, Add)

def test_expression(self) -> None:
"""Test that `Add` class returns the correct expression."""
add_op = Add(operands=[1, 2, 3])
assert add_op.expression == {"$add": [1, 2, 3]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.arithmetic.divide` module."""

from monggregate.operators.arithmetic.divide import Divide


class TestDivide:
"""Tests for `Divide` class."""

def test_instantiation(self) -> None:
"""Test that `Divide` class can be instantiated."""
divide_op = Divide(numerator=10, denominator=2)
assert isinstance(divide_op, Divide)

def test_expression(self) -> None:
"""Test that `Divide` class returns the correct expression."""
divide_op = Divide(numerator=10, denominator=2)
assert divide_op.expression == {"$divide": [10, 2]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.arithmetic.multiply` module."""

from monggregate.operators.arithmetic.multiply import Multiply


class TestMultiply:
"""Tests for `Multiply` class."""

def test_instantiation(self) -> None:
"""Test that `Multiply` class can be instantiated."""
multiply_op = Multiply(operands=[2, 3, 4])
assert isinstance(multiply_op, Multiply)

def test_expression(self) -> None:
"""Test that `Multiply` class returns the correct expression."""
multiply_op = Multiply(operands=[2, 3, 4])
assert multiply_op.expression == {"$multiply": [2, 3, 4]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.arithmetic.pow` module."""

from monggregate.operators.arithmetic.pow import Pow


class TestPow:
"""Tests for `Pow` class."""

def test_instantiation(self) -> None:
"""Test that `Pow` class can be instantiated."""
pow_op = Pow(number=2, exponent=3)
assert isinstance(pow_op, Pow)

def test_expression(self) -> None:
"""Test that `Pow` class returns the correct expression."""
pow_op = Pow(number=2, exponent=3)
assert pow_op.expression == {"$pow": [2, 3]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.arithmetic.subtract` module."""

from monggregate.operators.arithmetic.subtract import Subtract


class TestSubtract:
"""Tests for `Subtract` class."""

def test_instantiation(self) -> None:
"""Test that `Subtract` class can be instantiated."""
subtract_op = Subtract(left=5, right=3)
assert isinstance(subtract_op, Subtract)

def test_expression(self) -> None:
"""Test that `Subtract` class returns the correct expression."""
subtract_op = Subtract(left=5, right=3)
assert subtract_op.expression == {"$substract": [5, 3]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Tests for `monggregate.operators.array.array_to_object` module."""

from monggregate.operators.array.array_to_object import ArrayToObject


class TestArrayToObject:
"""Tests for `ArrayToObject` class."""

def test_instantiation(self) -> None:
"""Test that `ArrayToObject` class can be instantiated."""
array_to_object_op = ArrayToObject(operand=[["item", "abc123"], ["qty", 25]])
assert isinstance(array_to_object_op, ArrayToObject)

def test_expression(self) -> None:
"""Test that `ArrayToObject` class returns the correct expression."""
array_to_object_op = ArrayToObject(operand=[["item", "abc123"], ["qty", 25]])
assert array_to_object_op.expression == {
"$arrayToObject": [["item", "abc123"], ["qty", 25]]
}
26 changes: 26 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Tests for `monggregate.operators.array.filter` module."""

from monggregate.operators.array.filter import Filter


class TestFilter:
"""Tests for `Filter` class."""

def test_instantiation(self) -> None:
"""Test that `Filter` class can be instantiated."""
filter_op = Filter(operand="$items", query={"$gt": ["$$num", 5]}, let="num")
assert isinstance(filter_op, Filter)

def test_expression(self) -> None:
"""Test that `Filter` class returns the correct expression."""
filter_op = Filter(
operand="$items", query={"$gt": ["$$num", 5]}, let="num", limit=3
)
assert filter_op.expression == {
"$filter": {
"input": "$items",
"cond": {"$gt": ["$$num", 5]},
"as": "num",
"limit": 3,
}
}
17 changes: 17 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.first` module."""

from monggregate.operators.array.first import First


class TestFirst:
"""Tests for `First` class."""

def test_instantiation(self) -> None:
"""Test that `First` class can be instantiated."""
first_op = First(operand="$items")
assert isinstance(first_op, First)

def test_expression(self) -> None:
"""Test that `First` class returns the correct expression."""
first_op = First(operand="$items")
assert first_op.expression == {"$first": "$items"}
17 changes: 17 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.in_` module."""

from monggregate.operators.array.in_ import In


class TestIn:
"""Tests for `In` class."""

def test_instantiation(self) -> None:
"""Test that `In` class can be instantiated."""
in_op = In(left="$value", right=["$array"])
assert isinstance(in_op, In)

def test_expression(self) -> None:
"""Test that `In` class returns the correct expression."""
in_op = In(left="$value", right=["$array"])
assert in_op.expression == {"$in": ["$value", ["$array"]]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.is_array` module."""

from monggregate.operators.array.is_array import IsArray


class TestIsArray:
"""Tests for `IsArray` class."""

def test_instantiation(self) -> None:
"""Test that `IsArray` class can be instantiated."""
is_array_op = IsArray(operand="$field")
assert isinstance(is_array_op, IsArray)

def test_expression(self) -> None:
"""Test that `IsArray` class returns the correct expression."""
is_array_op = IsArray(operand="$field")
assert is_array_op.expression == {"$isArray": "$field"}
17 changes: 17 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_last.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.last` module."""

from monggregate.operators.array.last import Last


class TestLast:
"""Tests for `Last` class."""

def test_instantiation(self) -> None:
"""Test that `Last` class can be instantiated."""
last_op = Last(operand="$items")
assert isinstance(last_op, Last)

def test_expression(self) -> None:
"""Test that `Last` class returns the correct expression."""
last_op = Last(operand="$items")
assert last_op.expression == {"$last": "$items"}
17 changes: 17 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_max_n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.max_n` module."""

from monggregate.operators.array.max_n import MaxN


class TestMaxN:
"""Tests for `MaxN` class."""

def test_instantiation(self) -> None:
"""Test that `MaxN` class can be instantiated."""
max_n_op = MaxN(input=[1, 2, 3], n=2)
assert isinstance(max_n_op, MaxN)

def test_expression(self) -> None:
"""Test that `MaxN` class returns the correct expression."""
max_n_op = MaxN(input=[1, 2, 3], n=2)
assert max_n_op.expression == {"$maxN": {"input": [1, 2, 3], "n": 2}}
17 changes: 17 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_min_n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for `monggregate.operators.array.min_n` module."""

from monggregate.operators.array.min_n import MinN


class TestMinN:
"""Tests for `MinN` class."""

def test_instantiation(self) -> None:
"""Test that `MinN` class can be instantiated."""
min_n_op = MinN(operand=[3, 1, 4, 1, 5], limit=2)
assert isinstance(min_n_op, MinN)

def test_expression(self) -> None:
"""Test that `MinN` class returns the correct expression."""
min_n_op = MinN(operand=[3, 1, 4, 1, 5], limit=2)
assert min_n_op.expression == {"$minN": {"n": 2, "input": [3, 1, 4, 1, 5]}}
Loading
Loading