Skip to content

Commit

Permalink
[tests] Fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed May 19, 2022
1 parent d317b21 commit aaad59a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions openwisp_monitoring/check/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_auto_check_creation(self):
def test_device_deleted(self):
self.assertEqual(Check.objects.count(), 0)
d = self._create_device(organization=self._create_org())
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
d.delete()
self.assertEqual(Check.objects.count(), 0)

Expand All @@ -156,7 +156,7 @@ def test_config_modified_device_problem(self):
self._create_config(status='modified', organization=self._create_org())
d = Device.objects.first()
d.monitoring.update_status('ok')
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
self.assertEqual(Metric.objects.count(), 0)
self.assertEqual(AlertSettings.objects.count(), 0)
check = Check.objects.filter(check_type=self._CONFIG_APPLIED).first()
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_config_error(self):
self._create_config(status='error', organization=self._create_org())
dm = Device.objects.first().monitoring
dm.update_status('ok')
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
self.assertEqual(Metric.objects.count(), 0)
self.assertEqual(AlertSettings.objects.count(), 0)
check = Check.objects.filter(check_type=self._CONFIG_APPLIED).first()
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_config_error(self):
@patch('openwisp_monitoring.check.settings.AUTO_PING', False)
def test_config_check_critical_metric(self):
self._create_config(status='modified', organization=self._create_org())
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
d = Device.objects.first()
dm = d.monitoring
dm.update_status('ok')
Expand All @@ -238,7 +238,7 @@ def test_config_check_critical_metric(self):

def test_no_duplicate_check_created(self):
self._create_config(organization=self._create_org())
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
d = Device.objects.first()
auto_create_config_check.delay(
model=Device.__name__.lower(),
Expand All @@ -261,7 +261,7 @@ def test_device_unreachable_no_config_check(self):
self._create_config(status='modified', organization=self._create_org())
d = self.device_model.objects.first()
d.monitoring.update_status('critical')
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
c2 = Check.objects.filter(check_type=self._CONFIG_APPLIED).first()
c2.perform_check()
self.assertEqual(Metric.objects.count(), 0)
Expand All @@ -272,7 +272,7 @@ def test_device_unknown_no_config_check(self):
self._create_config(status='modified', organization=self._create_org())
d = self.device_model.objects.first()
d.monitoring.update_status('unknown')
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
c2 = Check.objects.filter(check_type=self._CONFIG_APPLIED).first()
c2.perform_check()
self.assertEqual(Metric.objects.count(), 0)
Expand Down
2 changes: 1 addition & 1 deletion openwisp_monitoring/check/tests/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_store_result(self, mocked_method):
device.management_ip = '10.40.0.1'
device.save()
# check created automatically by autoping
self.assertEqual(Check.objects.count(), 2)
self.assertEqual(Check.objects.count(), 3)
self.assertEqual(Metric.objects.count(), 0)
self.assertEqual(Chart.objects.count(), 0)
self.assertEqual(AlertSettings.objects.count(), 0)
Expand Down
2 changes: 2 additions & 0 deletions openwisp_monitoring/device/tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def test_trigger_device_recovery_task_regression(
dm = self._create_device_monitoring()
dm.device.management_ip = None
dm.device.save()
# Delete snmp check to prevent unnecessary response timeout
Check.objects.filter(check_type__endswith='Snmp').delete()
trigger_device_checks.delay(dm.device.pk)
self.assertTrue(Check.objects.exists())
# we expect update_status() to be called once (by the check)
Expand Down
2 changes: 2 additions & 0 deletions openwisp_monitoring/tests/test_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def test_restoring_deleted_device(self):
org = self._get_org()
self._create_credentials(auto_add=True, organization=org)
device = self._create_config(organization=org).device
# Delete snmp check to prevent unnecessary response timeout
Check.objects.filter(check_type__endswith='Snmp').delete()
device_data = DeviceData.objects.get(id=device.id)
device_checks = device_data.checks.all()
for check in device_checks:
Expand Down

0 comments on commit aaad59a

Please sign in to comment.