Skip to content
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
"""Tests for `monggregate.operators.accumulators.avg` module."""

from monggregate.operators.accumulators.avg import Average
from monggregate.operators.accumulators.avg import Average, avg

def test_avg_expression():
# Setup
expected_expression = {
"$avg": None
}

# Act
avg_op = Average()
result_expression = avg_op.expression

# Assert
assert result_expression == expected_expression

class TestAverage:
"""Tests for `Average` class."""
Expand All @@ -15,4 +27,4 @@ def test_expression(self) -> None:
"""Test that `Average` class returns the correct expression."""

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

from monggregate.operators.accumulators.count import Count
import pytest
from monggregate.operators.accumulators.count import Count, count

def test_count_expression():
# Setup
expected_expression = {
"$count": {}
}

# Act
count_op = count()
result_expression = count_op.expression

# Assert
assert result_expression == expected_expression

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

from monggregate.operators.accumulators.first import First
import pytest
from monggregate.operators.accumulators.first import First, first

def test_first_expression():
# Setup
operand = "$someField"
expected_expression = {
"$first": operand
}

# Act
first_op = first(operand)
result_expression = first_op.expression

# Assert
assert result_expression == expected_expression


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

from monggregate.operators.accumulators.last import Last
import pytest
from monggregate.operators.accumulators.last import Last, last

def test_last_expression():
# Setup
operand = "$someField"
expected_expression = {
"$last": operand
}

# Act
last_op = last(operand)
result_expression = last_op.expression

# Assert
assert result_expression == expected_expression


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

from monggregate.operators.accumulators.max import Max
import pytest
from monggregate.operators.accumulators.max import Max, max

def test_max_expression():
# Setup
operand = "$someNumericField"
expected_expression = {
"$max": operand
}

# Act
max_op = max(operand)
result_expression = max_op.expression

# Assert
assert result_expression == expected_expression


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

from monggregate.operators.accumulators.min import Min
import pytest
from monggregate.operators.accumulators.min import Min, min

def test_min_expression():
# Setup
operand = "$someNumericField"
expected_expression = {
"$min": operand
}

# Act
min_op = min(operand)
result_expression = min_op.expression

# Assert
assert result_expression == expected_expression


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

from monggregate.operators.accumulators.push import Push
import pytest
from monggregate.operators.accumulators.push import Push, push

def test_push_expression():
# Setup
operand = "$someField"
expected_expression = {
"$push": operand
}

# Act
push_op = push(operand)
result_expression = push_op.expression

# Assert
assert result_expression == expected_expression


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

from monggregate.operators.accumulators.sum import Sum
import pytest
from monggregate.operators.accumulators.sum import Sum, sum

def test_sum_operand():
# Setup
operand = "$amount"

# Act
result_op = {"$sum": operand}
expected_expression = {"$sum": "$amount"}

# Assert
assert result_op == expected_expression


class TestSum:
Expand All @@ -14,4 +26,4 @@ def test_instantiation(self) -> None:
def test_expression(self) -> None:
"""Test that `Sum` class returns the correct expression."""
sum_op = Sum(operand=1)
assert sum_op.expression == {"$sum": 1}
assert sum_op.expression == {"$sum": 1}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

from monggregate.operators.arithmetic.add import Add

def test_add_expression():
# Setup
operands = [1, 2, 3]
expected_expression = {"$add": operands}

# Act
add_op = Add(operands=operands)
result_expression = add_op.expression

# Assert
assert result_expression == expected_expression


class TestAdd:
"""Tests for `Add` class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

from monggregate.operators.arithmetic.divide import Divide

def test_divide_expression():
# Setup
numerator = 10
denominator = 2
expected_expression = {"$divide": [numerator, denominator]}

# Act
divide_op = Divide(numerator=numerator, denominator=denominator)
result_expression = divide_op.expression

# Assert
assert result_expression == expected_expression


class TestDivide:
"""Tests for `Divide` class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

from monggregate.operators.arithmetic.multiply import Multiply

def test_multiply_expression():
# Setup
operands = [2, 3, 4]
expected_expression = {"$multiply": operands}

# Act
multiply_op = Multiply(operands=operands)
result_expression = multiply_op.expression

# Assert
assert result_expression == expected_expression


class TestMultiply:
"""Tests for `Multiply` class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

from monggregate.operators.arithmetic.pow import Pow

def test_pow_expression():
# Setup
number = 2
exponent = 3
expected_expression = {"$pow": [number, exponent]}

# Act
pow_op = Pow(number=number, exponent=exponent)
result_expression = pow_op.expression

# Assert
assert result_expression == expected_expression


class TestPow:
"""Tests for `Pow` class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

from monggregate.operators.arithmetic.subtract import Subtract

def test_subtract_expression():
# Setup
left = 10
right = 4
expected_expression = {"$substract": [left, right]}

# Act
subtract_op = Subtract(left=left, right=right)
result_expression = subtract_op.expression

# Assert
assert result_expression == expected_expression


class TestSubtract:
"""Tests for `Subtract` class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

from monggregate.operators.array.array_to_object import ArrayToObject

def test_array_to_object_expression():
# Setup
operand = [ { "k": "item", "v": "abc123"}, { "k": "qty", "v": 25 } ]
expected_expression = { "$arrayToObject": operand }

# Act
array_to_object_op = ArrayToObject(operand=operand)
result_expression = array_to_object_op.expression

# Assert
assert result_expression == expected_expression


class TestArrayToObject:
"""Tests for `ArrayToObject` class."""
Expand All @@ -16,4 +28,4 @@ def test_expression(self) -> None:
array_to_object_op = ArrayToObject(operand=[["item", "abc123"], ["qty", 25]])
assert array_to_object_op.expression == {
"$arrayToObject": [["item", "abc123"], ["qty", 25]]
}
}
22 changes: 22 additions & 0 deletions tests/tests_monggregate/tests_operators/tests_array/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

from monggregate.operators.array.filter import Filter

def test_filter_expression():
# Setup
operand = [1, 2, 3, 4, 5]
let = "num"
query = {"$gt": ["$$num", 5]}
limit = None
expected_expression = {
"$filter": {
"input": operand,
"cond": query,
"as": let,
"limit": limit
}
}

# Act
filter_op = Filter(operand=operand, query=query, let=let, limit=limit)
result_expression = filter_op.expression

# Assert
assert result_expression == expected_expression


class TestFilter:
"""Tests for `Filter` class."""
Expand Down
Loading
Loading