Commit f19f4642 by Jörg Stucke

added tests to improve coverage

parent 41435cf9
from common_helper_mongo.aggregate import (
get_all_value_combinations_of_fields, get_field_average, get_field_sum, get_list_of_all_values,
get_objects_and_count_of_occurrence,
get_list_of_all_values_and_collect_information_of_additional_field, get_objects_and_count_of_occurrence,
)
from tests.base_class_database_test import MongoDbTest
......@@ -37,7 +37,7 @@ class TestAggregate(MongoDbTest):
def test_get_all_value_combinations_of_fields_id(self):
self.add_list_test_data()
result = get_all_value_combinations_of_fields(self.test_collection, "$test_list", "$_id", unwind=True, match=None)
result = get_all_value_combinations_of_fields(self.test_collection, "$test_list", "$_id", unwind=True)
self.assertIsInstance(result, dict, "result should be a dict")
self.assertEqual(len(result.keys()), 4, "number of results not correct")
self.assertEqual(len(result['c']), 2, "c should have two related object ids")
......@@ -77,3 +77,13 @@ class TestAggregate(MongoDbTest):
self.add_simple_test_data()
result = get_field_sum(self.test_collection, "$test_int", match={"test_int": {"$lt": 5}})
self.assertEqual(result, 10)
def test_get_field_execute_operation_empty(self):
result = get_field_sum(self.test_collection, "$test_int")
self.assertEqual(result, 0)
def test_get_list_of_all_values_and_collect_information_of_additional_field(self):
self.add_list_test_data()
with self.assertLogs() as logger:
get_list_of_all_values_and_collect_information_of_additional_field(self.test_collection, "$test_list", "$_id", unwind=True)
assert 'deprecation warning' in logger.output.pop()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment