diff --git a/tests/tests_operators/tests_accumulators/test_accumulator.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_accumulator.py similarity index 100% rename from tests/tests_operators/tests_accumulators/test_accumulator.py rename to tests/tests_monggregate/tests_operators/tests_accumulators/test_accumulator.py diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_avg.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_avg.py new file mode 100644 index 00000000..e21e9b78 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_avg.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_count.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_count.py new file mode 100644 index 00000000..b6185451 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_count.py @@ -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": {}} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_first.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_first.py new file mode 100644 index 00000000..bc59c31a --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_first.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_last.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_last.py new file mode 100644 index 00000000..f00559e1 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_last.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_max.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_max.py new file mode 100644 index 00000000..6ced7225 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_max.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_min.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_min.py new file mode 100644 index 00000000..e1cbece0 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_min.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_push.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_push.py new file mode 100644 index 00000000..9101387b --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_push.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_accumulators/test_sum.py b/tests/tests_monggregate/tests_operators/tests_accumulators/test_sum.py new file mode 100644 index 00000000..80365674 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_accumulators/test_sum.py @@ -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} diff --git a/tests/tests_monggregate/tests_operators/tests_arithmetic/test_add.py b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_add.py new file mode 100644 index 00000000..f10f5feb --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_add.py @@ -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]} diff --git a/tests/tests_monggregate/tests_operators/tests_arithmetic/test_divide.py b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_divide.py new file mode 100644 index 00000000..9b4a5421 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_divide.py @@ -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]} diff --git a/tests/tests_monggregate/tests_operators/tests_arithmetic/test_multiply.py b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_multiply.py new file mode 100644 index 00000000..60ee2979 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_multiply.py @@ -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]} diff --git a/tests/tests_monggregate/tests_operators/tests_arithmetic/test_pow.py b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_pow.py new file mode 100644 index 00000000..390b8b13 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_pow.py @@ -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]} diff --git a/tests/tests_monggregate/tests_operators/tests_arithmetic/test_subtract.py b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_subtract.py new file mode 100644 index 00000000..700e869a --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_arithmetic/test_subtract.py @@ -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]} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_array_to_object.py b/tests/tests_monggregate/tests_operators/tests_array/test_array_to_object.py new file mode 100644 index 00000000..ba280e8a --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_array_to_object.py @@ -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]] + } diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_filter.py b/tests/tests_monggregate/tests_operators/tests_array/test_filter.py new file mode 100644 index 00000000..5d55d2ef --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_filter.py @@ -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, + } + } diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_first.py b/tests/tests_monggregate/tests_operators/tests_array/test_first.py new file mode 100644 index 00000000..4f5d441e --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_first.py @@ -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"} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_in.py b/tests/tests_monggregate/tests_operators/tests_array/test_in.py new file mode 100644 index 00000000..160d8e33 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_in.py @@ -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"]]} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_is_array.py b/tests/tests_monggregate/tests_operators/tests_array/test_is_array.py new file mode 100644 index 00000000..c80a3168 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_is_array.py @@ -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"} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_last.py b/tests/tests_monggregate/tests_operators/tests_array/test_last.py new file mode 100644 index 00000000..35ef51e2 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_last.py @@ -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"} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_max_n.py b/tests/tests_monggregate/tests_operators/tests_array/test_max_n.py new file mode 100644 index 00000000..0d9d97a9 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_max_n.py @@ -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}} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_min_n.py b/tests/tests_monggregate/tests_operators/tests_array/test_min_n.py new file mode 100644 index 00000000..4490834e --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_min_n.py @@ -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]}} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_size.py b/tests/tests_monggregate/tests_operators/tests_array/test_size.py new file mode 100644 index 00000000..c84c0739 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_size.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.array.size` module.""" + +from monggregate.operators.array.size import Size + + +class TestSize: + """Tests for `Size` class.""" + + def test_instantiation(self) -> None: + """Test that `Size` class can be instantiated.""" + size_op = Size(operand="$items") + assert isinstance(size_op, Size) + + def test_expression(self) -> None: + """Test that `Size` class returns the correct expression.""" + size_op = Size(operand="$items") + assert size_op.expression == {"$size": "$items"} diff --git a/tests/tests_monggregate/tests_operators/tests_array/test_sort_array.py b/tests/tests_monggregate/tests_operators/tests_array/test_sort_array.py new file mode 100644 index 00000000..0b573459 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_array/test_sort_array.py @@ -0,0 +1,19 @@ +"""Tests for `monggregate.operators.array.sort_array` module.""" + +from monggregate.operators.array.sort_array import SortArray + + +class TestSortArray: + """Tests for `SortArray` class.""" + + def test_instantiation(self) -> None: + """Test that `SortArray` class can be instantiated.""" + sort_array_op = SortArray(operand="$items", by={"score": 1}) + assert isinstance(sort_array_op, SortArray) + + def test_expression(self) -> None: + """Test that `SortArray` class returns the correct expression.""" + sort_array_op = SortArray(operand="$items", by={"score": 1}) + assert sort_array_op.expression == { + "$sortArray": {"input": "$items", "sortBy": {"score": 1}} + } diff --git a/tests/tests_monggregate/tests_operators/tests_boolean/test_and.py b/tests/tests_monggregate/tests_operators/tests_boolean/test_and.py new file mode 100644 index 00000000..e172409c --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_boolean/test_and.py @@ -0,0 +1,19 @@ +"""Tests for `monggregate.operators.boolean.and_` module.""" + +from monggregate.operators.boolean.and_ import And + + +class TestAnd: + """Tests for `And` class.""" + + def test_instantiation(self) -> None: + """Test that `And` class can be instantiated.""" + and_op = And(operands=[{"$gt": ["$age", 18]}, {"$lt": ["$age", 65]}]) + assert isinstance(and_op, And) + + def test_expression(self) -> None: + """Test that `And` class returns the correct expression.""" + and_op = And(operands=[{"$gt": ["$age", 18]}, {"$lt": ["$age", 65]}]) + assert and_op.expression == { + "$and": [{"$gt": ["$age", 18]}, {"$lt": ["$age", 65]}] + } diff --git a/tests/tests_monggregate/tests_operators/tests_boolean/test_not.py b/tests/tests_monggregate/tests_operators/tests_boolean/test_not.py new file mode 100644 index 00000000..27d6180c --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_boolean/test_not.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.boolean.not_` module.""" + +from monggregate.operators.boolean.not_ import Not + + +class TestNot: + """Tests for `Not` class.""" + + def test_instantiation(self) -> None: + """Test that `Not` class can be instantiated.""" + not_op = Not(operand={"$eq": ["$status", "inactive"]}) + assert isinstance(not_op, Not) + + def test_expression(self) -> None: + """Test that `Not` class returns the correct expression.""" + not_op = Not(operand={"$eq": ["$status", "inactive"]}) + assert not_op.expression == {"$not": [{"$eq": ["$status", "inactive"]}]} diff --git a/tests/tests_monggregate/tests_operators/tests_boolean/test_or.py b/tests/tests_monggregate/tests_operators/tests_boolean/test_or.py new file mode 100644 index 00000000..817bb9b1 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_boolean/test_or.py @@ -0,0 +1,19 @@ +"""Tests for `monggregate.operators.boolean.or_` module.""" + +from monggregate.operators.boolean.or_ import Or + + +class TestOr: + """Tests for `Or` class.""" + + def test_instantiation(self) -> None: + """Test that `Or` class can be instantiated.""" + or_op = Or(operands=[{"$eq": ["$status", "active"]}, {"$gt": ["$priority", 5]}]) + assert isinstance(or_op, Or) + + def test_expression(self) -> None: + """Test that `Or` class returns the correct expression.""" + or_op = Or(operands=[{"$eq": ["$status", "active"]}, {"$gt": ["$priority", 5]}]) + assert or_op.expression == { + "$or": [{"$eq": ["$status", "active"]}, {"$gt": ["$priority", 5]}] + } diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_cmp.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_cmp.py new file mode 100644 index 00000000..b81c5059 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_cmp.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.cmp` module.""" + +from monggregate.operators.comparison.cmp import Compare + + +class TestCompare: + """Tests for `Compare` class.""" + + def test_instantiation(self) -> None: + """Test that `Compare` class can be instantiated.""" + cmp_op = Compare(left="$field", right=10) + assert isinstance(cmp_op, Compare) + + def test_expression(self) -> None: + """Test that `Compare` class returns the correct expression.""" + cmp_op = Compare(left="$field", right=10) + assert cmp_op.expression == {"$cmp": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_eq.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_eq.py new file mode 100644 index 00000000..8e3cb4f2 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_eq.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.eq` module.""" + +from monggregate.operators.comparison.eq import Equal + + +class TestEqual: + """Tests for `Equal` class.""" + + def test_instantiation(self) -> None: + """Test that `Equal` class can be instantiated.""" + equal_op = Equal(left="$field", right=10) + assert isinstance(equal_op, Equal) + + def test_expression(self) -> None: + """Test that `Equal` class returns the correct expression.""" + equal_op = Equal(left="$field", right=10) + assert equal_op.expression == {"$eq": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_gt.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_gt.py new file mode 100644 index 00000000..cabeaa10 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_gt.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.gt` module.""" + +from monggregate.operators.comparison.gt import GreatherThan + + +class TestGreatherThan: + """Tests for `GreatherThan` class.""" + + def test_instantiation(self) -> None: + """Test that `GreatherThan` class can be instantiated.""" + gt_op = GreatherThan(left="$field", right=10) + assert isinstance(gt_op, GreatherThan) + + def test_expression(self) -> None: + """Test that `GreatherThan` class returns the correct expression.""" + gt_op = GreatherThan(left="$field", right=10) + assert gt_op.expression == {"$gt": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_gte.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_gte.py new file mode 100644 index 00000000..72721a76 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_gte.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.gte` module.""" + +from monggregate.operators.comparison.gte import GreatherThanOrEqual + + +class TestGreatherThanOrEqual: + """Tests for `GreatherThanOrEqual` class.""" + + def test_instantiation(self) -> None: + """Test that `GreatherThanOrEqual` class can be instantiated.""" + gte_op = GreatherThanOrEqual(left="$field", right=10) + assert isinstance(gte_op, GreatherThanOrEqual) + + def test_expression(self) -> None: + """Test that `GreatherThanOrEqual` class returns the correct expression.""" + gte_op = GreatherThanOrEqual(left="$field", right=10) + assert gte_op.expression == {"$gte": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_lt.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_lt.py new file mode 100644 index 00000000..506db97f --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_lt.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.lt` module.""" + +from monggregate.operators.comparison.lt import LowerThan + + +class TestLowerThan: + """Tests for `LowerThan` class.""" + + def test_instantiation(self) -> None: + """Test that `LowerThan` class can be instantiated.""" + lt_op = LowerThan(left="$field", right=10) + assert isinstance(lt_op, LowerThan) + + def test_expression(self) -> None: + """Test that `LowerThan` class returns the correct expression.""" + lt_op = LowerThan(left="$field", right=10) + assert lt_op.expression == {"$lt": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_lte.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_lte.py new file mode 100644 index 00000000..3d3bd593 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_lte.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.lte` module.""" + +from monggregate.operators.comparison.lte import LowerThanOrEqual + + +class TestLowerThanOrEqual: + """Tests for `LowerThanOrEqual` class.""" + + def test_instantiation(self) -> None: + """Test that `LowerThanOrEqual` class can be instantiated.""" + lte_op = LowerThanOrEqual(left="$field", right=10) + assert isinstance(lte_op, LowerThanOrEqual) + + def test_expression(self) -> None: + """Test that `LowerThanOrEqual` class returns the correct expression.""" + lte_op = LowerThanOrEqual(left="$field", right=10) + assert lte_op.expression == {"$lte": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_comparison/test_ne.py b/tests/tests_monggregate/tests_operators/tests_comparison/test_ne.py new file mode 100644 index 00000000..6fe9457b --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_comparison/test_ne.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.comparison.ne` module.""" + +from monggregate.operators.comparison.ne import NotEqual + + +class TestNotEqual: + """Tests for `NotEqual` class.""" + + def test_instantiation(self) -> None: + """Test that `NotEqual` class can be instantiated.""" + not_equal_op = NotEqual(left="$field", right=10) + assert isinstance(not_equal_op, NotEqual) + + def test_expression(self) -> None: + """Test that `NotEqual` class returns the correct expression.""" + not_equal_op = NotEqual(left="$field", right=10) + assert not_equal_op.expression == {"$ne": ["$field", 10]} diff --git a/tests/tests_monggregate/tests_operators/tests_conditional/test_cond.py b/tests/tests_monggregate/tests_operators/tests_conditional/test_cond.py new file mode 100644 index 00000000..810aaff2 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_conditional/test_cond.py @@ -0,0 +1,19 @@ +"""Tests for `monggregate.operators.conditional.cond` module.""" + +from monggregate.operators.conditional.cond import Cond + + +class TestCond: + """Tests for `Cond` class.""" + + def test_instantiation_with_if_then_else(self) -> None: + """Test that `Cond` class can be instantiated with if/then/else syntax.""" + cond_op = Cond(if_={"$gt": ["$age", 18]}, then_="Adult", else_="Minor") + assert isinstance(cond_op, Cond) + + def test_expression_with_if_then_else(self) -> None: + """Test that `Cond` class returns the correct expression with if/then/else syntax.""" + cond_op = Cond(if_={"$gt": ["$age", 18]}, then_="Adult", else_="Minor") + assert cond_op.expression == { + "$cond": {"if": {"$gt": ["$age", 18]}, "then": "Adult", "else": "Minor"} + } diff --git a/tests/tests_monggregate/tests_operators/tests_conditional/test_if_null.py b/tests/tests_monggregate/tests_operators/tests_conditional/test_if_null.py new file mode 100644 index 00000000..f63e1bcb --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_conditional/test_if_null.py @@ -0,0 +1,19 @@ +"""Tests for `monggregate.operators.conditional.if_null` module.""" + +from monggregate.operators.conditional.if_null import IfNull + + +class TestIfNull: + """Tests for `IfNull` class.""" + + def test_instantiation(self) -> None: + """Test that `IfNull` class can be instantiated.""" + if_null_op = IfNull(operand="$optional_field", output="default_value") + assert isinstance(if_null_op, IfNull) + + def test_expression(self) -> None: + """Test that `IfNull` class returns the correct expression.""" + if_null_op = IfNull(operand="$optional_field", output="default_value") + assert if_null_op.expression == { + "$ifNull": ["$optional_field", "default_value"] + } diff --git a/tests/tests_monggregate/tests_operators/tests_conditional/test_switch.py b/tests/tests_monggregate/tests_operators/tests_conditional/test_switch.py new file mode 100644 index 00000000..56d71785 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_conditional/test_switch.py @@ -0,0 +1,37 @@ +"""Tests for `monggregate.operators.conditional.switch` module.""" + +from monggregate.operators.conditional.switch import Switch + + +class TestSwitch: + """Tests for `Switch` class.""" + + def test_instantiation(self) -> None: + """Test that `Switch` class can be instantiated.""" + switch_op = Switch( + branches=[ + {"case": {"$eq": ["$type", "A"]}, "then": "Type A"}, + {"case": {"$eq": ["$type", "B"]}, "then": "Type B"}, + ], + default="Unknown Type", + ) + assert isinstance(switch_op, Switch) + + def test_expression(self) -> None: + """Test that `Switch` class returns the correct expression.""" + switch_op = Switch( + branches=[ + {"case": {"$eq": ["$type", "A"]}, "then": "Type A"}, + {"case": {"$eq": ["$type", "B"]}, "then": "Type B"}, + ], + default="Unknown Type", + ) + assert switch_op.expression == { + "$switch": { + "branches": [ + {"case": {"$eq": ["$type", "A"]}, "then": "Type A"}, + {"case": {"$eq": ["$type", "B"]}, "then": "Type B"}, + ], + "default": "Unknown Type", + } + } diff --git a/tests/tests_monggregate/tests_operators/tests_date/test_millisecond.py b/tests/tests_monggregate/tests_operators/tests_date/test_millisecond.py new file mode 100644 index 00000000..c923ed6e --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_date/test_millisecond.py @@ -0,0 +1,24 @@ +"""Tests for `monggregate.operators.date.millisecond` module.""" + +from monggregate.operators.date.millisecond import Millisecond + + +class TestMillisecond: + """Tests for `Millisecond` class.""" + + def test_instantiation(self) -> None: + """Test that `Millisecond` class can be instantiated.""" + millisecond_op = Millisecond(operand="$date", timezone=None) + assert isinstance(millisecond_op, Millisecond) + + def test_expression_without_timezone(self) -> None: + """Test that `Millisecond` class returns the correct expression without timezone.""" + millisecond_op = Millisecond(operand="$date", timezone=None) + assert millisecond_op.expression == {"$millisecond": "$date"} + + def test_expression_with_timezone(self) -> None: + """Test that `Millisecond` class returns the correct expression with timezone.""" + millisecond_op = Millisecond(operand="$date", timezone="America/New_York") + assert millisecond_op.expression == { + "$millisecond": {"date": "$date", "timezone": "America/New_York"} + } diff --git a/tests/tests_monggregate/tests_operators/tests_objects/test_merge_objects.py b/tests/tests_monggregate/tests_operators/tests_objects/test_merge_objects.py new file mode 100644 index 00000000..7a96f33b --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_objects/test_merge_objects.py @@ -0,0 +1,31 @@ +"""Tests for `monggregate.operators.objects.merge_objects` module.""" + +from monggregate.operators.objects.merge_objects import MergeObjects + + +class TestMergeObjects: + """Tests for `MergeObjects` class.""" + + def test_instantiation_with_single_operand(self) -> None: + """Test that `MergeObjects` class can be instantiated with a single operand.""" + merge_objects_op = MergeObjects(operand={"field1": 1, "field2": 2}) + assert isinstance(merge_objects_op, MergeObjects) + + def test_instantiation_with_multiple_operands(self) -> None: + """Test that `MergeObjects` class can be instantiated with multiple operands.""" + merge_objects_op = MergeObjects(operand=[{"field1": 1}, {"field2": 2}]) + assert isinstance(merge_objects_op, MergeObjects) + + def test_expression_with_single_operand(self) -> None: + """Test that `MergeObjects` class returns the correct expression with a single operand.""" + merge_objects_op = MergeObjects(operand={"field1": 1, "field2": 2}) + assert merge_objects_op.expression == { + "$mergeObjects": {"field1": 1, "field2": 2} + } + + def test_expression_with_multiple_operands(self) -> None: + """Test that `MergeObjects` class returns the correct expression with multiple operands.""" + merge_objects_op = MergeObjects(operand=[{"field1": 1}, {"field2": 2}]) + assert merge_objects_op.expression == { + "$mergeObjects": [{"field1": 1}, {"field2": 2}] + } diff --git a/tests/tests_monggregate/tests_operators/tests_objects/test_object_to_array.py b/tests/tests_monggregate/tests_operators/tests_objects/test_object_to_array.py new file mode 100644 index 00000000..d9a44683 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_objects/test_object_to_array.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.objects.object_to_array` module.""" + +from monggregate.operators.objects.object_to_array import ObjectToArray + + +class TestObjectToArray: + """Tests for `ObjectToArray` class.""" + + def test_instantiation(self) -> None: + """Test that `ObjectToArray` class can be instantiated.""" + object_to_array_op = ObjectToArray(operand="$document") + assert isinstance(object_to_array_op, ObjectToArray) + + def test_expression(self) -> None: + """Test that `ObjectToArray` class returns the correct expression.""" + object_to_array_op = ObjectToArray(operand="$document") + assert object_to_array_op.expression == {"$objectToArray": "$document"} diff --git a/tests/tests_monggregate/tests_operators/tests_strings/test_concat.py b/tests/tests_monggregate/tests_operators/tests_strings/test_concat.py new file mode 100644 index 00000000..6f7b87e1 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_strings/test_concat.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.strings.concat` module.""" + +from monggregate.operators.strings.concat import Concat + + +class TestConcat: + """Tests for `Concat` class.""" + + def test_instantiation(self) -> None: + """Test that `Concat` class can be instantiated.""" + concat_op = Concat(operands=["$firstName", " ", "$lastName"]) + assert isinstance(concat_op, Concat) + + def test_expression(self) -> None: + """Test that `Concat` class returns the correct expression.""" + concat_op = Concat(operands=["$firstName", " ", "$lastName"]) + assert concat_op.expression == {"$concat": ["$firstName", " ", "$lastName"]} diff --git a/tests/tests_monggregate/tests_operators/tests_strings/test_date_from_string.py b/tests/tests_monggregate/tests_operators/tests_strings/test_date_from_string.py new file mode 100644 index 00000000..1a27b7ad --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_strings/test_date_from_string.py @@ -0,0 +1,61 @@ +"""Tests for `monggregate.operators.strings.date_from_string` module.""" + +from monggregate.operators.strings.date_from_string import DateFromString + + +class TestDateFromString: + """Tests for `DateFromString` class.""" + + def test_instantiation_minimal(self) -> None: + """Test that `DateFromString` class can be instantiated with minimal parameters.""" + date_from_string_op = DateFromString( + date_string="2023-01-01", + format_=None, + timezone=None, + on_error=None, + on_null=None, + ) + assert isinstance(date_from_string_op, DateFromString) + + def test_instantiation_full(self) -> None: + """Test that `DateFromString` class can be instantiated with all parameters.""" + date_from_string_op = DateFromString( + date_string="2023-01-01", + format_="%Y-%m-%d", + timezone="America/New_York", + on_error="Invalid date", + on_null="No date provided", + ) + assert isinstance(date_from_string_op, DateFromString) + + def test_expression_minimal(self) -> None: + """Test that `DateFromString` class returns the correct expression with minimal parameters.""" + date_from_string_op = DateFromString( + date_string="2023-01-01", + format_=None, + timezone=None, + on_error=None, + on_null=None, + ) + assert date_from_string_op.expression == { + "$dateFromString": {"dateString": "2023-01-01"} + } + + def test_expression_full(self) -> None: + """Test that `DateFromString` class returns the correct expression with all parameters.""" + date_from_string_op = DateFromString( + date_string="2023-01-01", + format_="%Y-%m-%d", + timezone="America/New_York", + on_error="Invalid date", + on_null="No date provided", + ) + assert date_from_string_op.expression == { + "$dateFromString": { + "dateString": "2023-01-01", + "format": "%Y-%m-%d", + "timezone": "America/New_York", + "onError": "Invalid date", + "onNull": "No date provided", + } + } diff --git a/tests/tests_monggregate/tests_operators/tests_strings/test_date_to_string.py b/tests/tests_monggregate/tests_operators/tests_strings/test_date_to_string.py new file mode 100644 index 00000000..b9c886e5 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_strings/test_date_to_string.py @@ -0,0 +1,48 @@ +"""Tests for `monggregate.operators.strings.date_to_string` module.""" + +from monggregate.operators.strings.date_to_string import DateToString + + +class TestDateToString: + """Tests for `DateToString` class.""" + + def test_instantiation_minimal(self) -> None: + """Test that `DateToString` class can be instantiated with minimal parameters.""" + date_to_string_op = DateToString( + date="$date", format_=None, timezone=None, on_null=None + ) + assert isinstance(date_to_string_op, DateToString) + + def test_instantiation_full(self) -> None: + """Test that `DateToString` class can be instantiated with all parameters.""" + date_to_string_op = DateToString( + date="$date", + format_="%Y-%m-%d", + timezone="America/New_York", + on_null="No date available", + ) + assert isinstance(date_to_string_op, DateToString) + + def test_expression_minimal(self) -> None: + """Test that `DateToString` class returns the correct expression with minimal parameters.""" + date_to_string_op = DateToString( + date="$date", format_=None, timezone=None, on_null=None + ) + assert date_to_string_op.expression == {"$dateToString": {"date": "$date"}} + + def test_expression_full(self) -> None: + """Test that `DateToString` class returns the correct expression with all parameters.""" + date_to_string_op = DateToString( + date="$date", + format_="%Y-%m-%d", + timezone="America/New_York", + on_null="No date available", + ) + assert date_to_string_op.expression == { + "$dateToString": { + "date": "$date", + "format": "%Y-%m-%d", + "timezone": "America/New_York", + "onNull": "No date available", + } + } diff --git a/tests/tests_monggregate/tests_operators/tests_type_/test_type.py b/tests/tests_monggregate/tests_operators/tests_type_/test_type.py new file mode 100644 index 00000000..52b809d1 --- /dev/null +++ b/tests/tests_monggregate/tests_operators/tests_type_/test_type.py @@ -0,0 +1,17 @@ +"""Tests for `monggregate.operators.type_.type_` module.""" + +from monggregate.operators.type_.type_ import Type_ + + +class TestType: + """Tests for `Type_` class.""" + + def test_instantiation(self) -> None: + """Test that `Type_` class can be instantiated.""" + type_op = Type_(operand="$field") + assert isinstance(type_op, Type_) + + def test_expression(self) -> None: + """Test that `Type_` class returns the correct expression.""" + type_op = Type_(operand="$field") + assert type_op.expression == {"$type": "$field"}