From 39ad9ab3e67787a867bceb9e31984d59849c4cfe Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Wed, 2 Jul 2025 17:22:55 +0200 Subject: [PATCH 1/2] endpoint metrics test: ignore order --- unittests/test_metrics_queries.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unittests/test_metrics_queries.py b/unittests/test_metrics_queries.py index 773a1f7d4cf..9910f16259d 100644 --- a/unittests/test_metrics_queries.py +++ b/unittests/test_metrics_queries.py @@ -216,7 +216,11 @@ def test_endpoint_queries(self, mock_now): # Assert that we get expected querysets back. This is to be used to # support refactoring, in attempt of lowering the query count. - self.assertSequenceEqual( + + # assertCountEqual(first, second, msg=None)¶ + # Test that sequence first contains the same elements as second, regardless of their order. When they dont, an error message listing the differences between the sequences will be generated. + # Duplicate elements are not ignored when comparing first and second. It verifies whether each element has the same count in both sequences. Equivalent to: assertEqual(Counter(list(first)), Counter(list(second))) but works with sequences of unhashable objects as well. + self.assertCountEqual( endpoint_queries["all"].values(), [ {"id": 1, "date": date(2020, 7, 1), "last_modified": datetime(2020, 7, 1, 17, 45, 39, 791907, tzinfo=pytz.UTC), "mitigated": False, "mitigated_time": None, "mitigated_by_id": None, "false_positive": False, "out_of_scope": False, "risk_accepted": False, "endpoint_id": 2, "finding_id": 2, "endpoint__product__prod_type__member": False, "endpoint__product__member": True, "endpoint__product__prod_type__authorized_group": False, "endpoint__product__authorized_group": False}, From b75a24743f51b3abd8e256ec5212795699847265 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Wed, 2 Jul 2025 17:28:33 +0200 Subject: [PATCH 2/2] endpoint metrics test: ignore order --- unittests/test_metrics_queries.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_metrics_queries.py b/unittests/test_metrics_queries.py index 9910f16259d..72bfe8ae1be 100644 --- a/unittests/test_metrics_queries.py +++ b/unittests/test_metrics_queries.py @@ -217,8 +217,8 @@ def test_endpoint_queries(self, mock_now): # Assert that we get expected querysets back. This is to be used to # support refactoring, in attempt of lowering the query count. - # assertCountEqual(first, second, msg=None)¶ - # Test that sequence first contains the same elements as second, regardless of their order. When they dont, an error message listing the differences between the sequences will be generated. + # https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertCountEqual + # Test that sequence first contains the same elements as second, regardless of their order. When they don't, an error message listing the differences between the sequences will be generated. # Duplicate elements are not ignored when comparing first and second. It verifies whether each element has the same count in both sequences. Equivalent to: assertEqual(Counter(list(first)), Counter(list(second))) but works with sequences of unhashable objects as well. self.assertCountEqual( endpoint_queries["all"].values(),