Skip to content

Commit

Permalink
[tests] Fixed coverage issues
Browse files Browse the repository at this point in the history
- Changed leftover references to CleanInsights Events in tests
  • Loading branch information
pandafy committed Feb 21, 2024
1 parent 59f9490 commit 31db451
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions openwisp_utils/measurements/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'hardware_platform': 'x86_64',
}

_MODULES_UPGRADE_EXPECTED_EVENTS = [
_MODULES_UPGRADE_EXPECTED_METRICS = [
{
'category': 'OS Detail',
'action': 'kernel_version',
Expand Down Expand Up @@ -92,7 +92,7 @@
},
]

_HEARTBEAT_EVENTS = [
_HEARTBEAT_METRICS = [
{
'category': 'OS Detail',
'action': 'kernel_version',
Expand Down Expand Up @@ -148,7 +148,7 @@
'period_end': 1701388800,
},
]
_NEW_INSTALLATION_EVENTS = [
_NEW_INSTALLATION_METRICS = [
{
'category': 'OS Detail',
'action': 'kernel_version',
Expand Down
21 changes: 14 additions & 7 deletions openwisp_utils/measurements/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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()),
{},
Expand All @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 31db451

Please sign in to comment.