From 31db451950fb2255762e5b2bffe81de2ca1502ed Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Wed, 21 Feb 2024 18:48:06 +0530 Subject: [PATCH] [tests] Fixed coverage issues - Changed leftover references to CleanInsights Events in tests --- openwisp_utils/measurements/tests/__init__.py | 6 +++--- .../measurements/tests/test_models.py | 21 ++++++++++++------- runtests.py | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/openwisp_utils/measurements/tests/__init__.py b/openwisp_utils/measurements/tests/__init__.py index 87e50bf0..5a964e0f 100644 --- a/openwisp_utils/measurements/tests/__init__.py +++ b/openwisp_utils/measurements/tests/__init__.py @@ -8,7 +8,7 @@ 'hardware_platform': 'x86_64', } -_MODULES_UPGRADE_EXPECTED_EVENTS = [ +_MODULES_UPGRADE_EXPECTED_METRICS = [ { 'category': 'OS Detail', 'action': 'kernel_version', @@ -92,7 +92,7 @@ }, ] -_HEARTBEAT_EVENTS = [ +_HEARTBEAT_METRICS = [ { 'category': 'OS Detail', 'action': 'kernel_version', @@ -148,7 +148,7 @@ 'period_end': 1701388800, }, ] -_NEW_INSTALLATION_EVENTS = [ +_NEW_INSTALLATION_METRICS = [ { 'category': 'OS Detail', 'action': 'kernel_version', diff --git a/openwisp_utils/measurements/tests/test_models.py b/openwisp_utils/measurements/tests/test_models.py index 7e36029d..1a5b1c3a 100644 --- a/openwisp_utils/measurements/tests/test_models.py +++ b/openwisp_utils/measurements/tests/test_models.py @@ -12,9 +12,9 @@ from ..models import OpenwispVersion from . import ( _ENABLED_OPENWISP_MODULES_RETURN_VALUE, - _HEARTBEAT_EVENTS, - _MODULES_UPGRADE_EXPECTED_EVENTS, - _NEW_INSTALLATION_EVENTS, + _HEARTBEAT_METRICS, + _MODULES_UPGRADE_EXPECTED_METRICS, + _NEW_INSTALLATION_METRICS, _OS_DETAILS_RETURN_VALUE, ) @@ -35,7 +35,14 @@ def setUp(self): ).replace(tzinfo=timezone.utc), ) - def test_get_upgraded_models_on_new_installation(self): + def test_get_upgraded_modules_when_openwispversion_object_does_not_exist(self): + OpenwispVersion.objects.all().delete() + self.assertEqual( + OpenwispVersion.get_upgraded_modules(tasks.get_enabled_openwisp_modules()), + {}, + ) + + def test_get_upgraded_modules_on_new_installation(self): self.assertEqual( OpenwispVersion.get_upgraded_modules(tasks.get_enabled_openwisp_modules()), {}, @@ -57,7 +64,7 @@ def test_get_upgraded_models_on_new_installation(self): def test_new_installation(self, mocked_post, *args): OpenwispVersion.objects.all().delete() tasks.send_usage_metrics.delay() - mocked_post.assert_called_with(_NEW_INSTALLATION_EVENTS) + mocked_post.assert_called_with(_NEW_INSTALLATION_METRICS) self.assertEqual(OpenwispVersion.objects.count(), 1) version = OpenwispVersion.objects.first() expected_module_version = { @@ -86,7 +93,7 @@ def test_heartbeat(self, mocked_post, *args): } self.assertEqual(OpenwispVersion.objects.count(), 1) tasks.send_usage_metrics.delay() - mocked_post.assert_called_with(_HEARTBEAT_EVENTS) + mocked_post.assert_called_with(_HEARTBEAT_METRICS) self.assertEqual(OpenwispVersion.objects.count(), 1) version = OpenwispVersion.objects.first() self.assertEqual(version.module_version, expected_module_version) @@ -114,7 +121,7 @@ def test_modules_upgraded(self, mocked_post, *args): } ) tasks.send_usage_metrics.delay() - mocked_post.assert_called_with(_MODULES_UPGRADE_EXPECTED_EVENTS) + mocked_post.assert_called_with(_MODULES_UPGRADE_EXPECTED_METRICS) self.assertEqual(OpenwispVersion.objects.count(), 2) version = OpenwispVersion.objects.first() diff --git a/runtests.py b/runtests.py index 5427a446..4dbbe8a1 100755 --- a/runtests.py +++ b/runtests.py @@ -13,4 +13,5 @@ args = sys.argv args.insert(1, "test") args.insert(2, "test_project") + args.insert(3, "openwisp_utils.measurements") execute_from_command_line(args)