diff --git a/openwisp_controller/config/tests/test_admin.py b/openwisp_controller/config/tests/test_admin.py index 6ac0fb3cf..2716abebb 100644 --- a/openwisp_controller/config/tests/test_admin.py +++ b/openwisp_controller/config/tests/test_admin.py @@ -445,6 +445,7 @@ def test_download_device_config_404(self): response = self.client.get(path) self.assertEqual(response.status_code, 404) + @patch('openwisp_controller.config.settings.HARDWARE_ID_ENABLED', True) def test_preview_device_config(self): templates = Template.objects.all() path = reverse(f'admin:{self.app_label}_device_preview') @@ -807,6 +808,7 @@ def test_ip_in_change_device(self): response = self.client.get(path) self.assertContains(response, 'last_ip') + @patch('openwisp_controller.config.settings.HARDWARE_ID_ENABLED', True) def test_hardware_id_in_change_device(self): d = self._create_device() t = Template.objects.first() diff --git a/openwisp_controller/config/tests/test_config.py b/openwisp_controller/config/tests/test_config.py index c71788a5b..2d4a2e4ae 100644 --- a/openwisp_controller/config/tests/test_config.py +++ b/openwisp_controller/config/tests/test_config.py @@ -1,6 +1,6 @@ from copy import deepcopy +from unittest.mock import patch -from django.conf import settings from django.core.exceptions import ValidationError from django.db.transaction import atomic from django.test import TestCase @@ -229,13 +229,14 @@ def test_context_validation(self): 'the supplied value is not a JSON object', message_dict['context'] ) + @patch.dict(app_settings.CONTEXT, {'vpnserver1': 'vpn.testdomain.com'}) def test_context_setting(self): config = {'general': {'vpnserver1': '{{ vpnserver1 }}'}} c = Config( device=self._create_device(), backend='netjsonconfig.OpenWrt', config=config ) output = c.backend_instance.render() - vpnserver1 = settings.OPENWISP_CONTROLLER_CONTEXT['vpnserver1'] + vpnserver1 = app_settings.CONTEXT['vpnserver1'] self.assertIn(vpnserver1, output) def test_mac_address_as_hostname(self): diff --git a/openwisp_controller/config/tests/test_controller.py b/openwisp_controller/config/tests/test_controller.py index 269938847..b83a86bf1 100644 --- a/openwisp_controller/config/tests/test_controller.py +++ b/openwisp_controller/config/tests/test_controller.py @@ -705,6 +705,7 @@ def test_registration_disabled(self): self.assertEqual(response.status_code, 403) @patch('openwisp_controller.config.settings.REGISTRATION_SELF_CREATION', False) + @patch('openwisp_controller.config.settings.HARDWARE_ID_ENABLED', True) def test_self_creation_disabled(self): self._create_org() options = { diff --git a/openwisp_controller/config/tests/test_device.py b/openwisp_controller/config/tests/test_device.py index 87d54999a..d2f2e2db4 100644 --- a/openwisp_controller/config/tests/test_device.py +++ b/openwisp_controller/config/tests/test_device.py @@ -28,6 +28,7 @@ def test_str_name(self): d = Device(name='test') self.assertEqual(str(d), 'test') + @mock.patch('openwisp_controller.config.settings.HARDWARE_ID_ENABLED', True) @mock.patch('openwisp_controller.config.settings.HARDWARE_ID_AS_NAME', True) def test_str_hardware_id(self): d = Device(name='test', hardware_id='123') diff --git a/openwisp_controller/config/tests/test_template.py b/openwisp_controller/config/tests/test_template.py index c7ff500d6..91e2201e4 100644 --- a/openwisp_controller/config/tests/test_template.py +++ b/openwisp_controller/config/tests/test_template.py @@ -2,7 +2,6 @@ from unittest import mock from celery.exceptions import SoftTimeLimitExceeded -from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.test import TestCase, TransactionTestCase @@ -145,6 +144,7 @@ def test_auto_client_template_auto_cert_False(self): self.assertEqual(len(t.config['files']), 1) self.assertIn('ca_path', t.config['files'][0]['path']) + @mock.patch.dict(app_settings.CONTEXT, {'vpnserver1': 'vpn.testdomain.com'}) def test_template_context_var(self): org = self._get_org() t = self._create_template( @@ -164,13 +164,14 @@ def test_template_context_var(self): # clear cache del c.backend_instance output = c.backend_instance.render() - vpnserver1 = settings.OPENWISP_CONTROLLER_CONTEXT['vpnserver1'] + vpnserver1 = app_settings.CONTEXT['vpnserver1'] self.assertIn(vpnserver1, output) + @mock.patch.dict(app_settings.CONTEXT, {'vpnserver1': 'vpn.testdomain.com'}) def test_get_context(self): t = self._create_template() expected = {} - expected.update(settings.OPENWISP_CONTROLLER_CONTEXT) + expected.update(app_settings.CONTEXT) self.assertEqual(t.get_context(), expected) def test_tamplates_clone(self): diff --git a/openwisp_controller/config/tests/test_vpn.py b/openwisp_controller/config/tests/test_vpn.py index cc7bf546e..35021471f 100644 --- a/openwisp_controller/config/tests/test_vpn.py +++ b/openwisp_controller/config/tests/test_vpn.py @@ -1,7 +1,6 @@ from unittest import mock from celery.exceptions import SoftTimeLimitExceeded -from django.conf import settings from django.core.exceptions import ValidationError from django.test import TestCase, TransactionTestCase from swapper import load_model @@ -225,6 +224,7 @@ def test_get_auto_context_keys(self): } self.assertEqual(keys, control) + @mock.patch.dict(app_settings.CONTEXT, {'vpnserver1': 'vpn.testdomain.com'}) def test_get_context(self): v = self._create_vpn() expected = { @@ -233,7 +233,7 @@ def test_get_context(self): 'key': v.cert.private_key, 'dh': v.dh, } - expected.update(settings.OPENWISP_CONTROLLER_CONTEXT) + expected.update(app_settings.CONTEXT) self.assertEqual(v.get_context(), expected) self.assertNotEqual(v.get_context(), app_settings.CONTEXT) @@ -248,9 +248,10 @@ def test_dh(self, mocked_dhparam): self.assertTrue(v.dh.startswith('-----BEGIN DH PARAMETERS-----')) self.assertTrue(v.dh.endswith('-----END DH PARAMETERS-----\n')) + @mock.patch.dict(app_settings.CONTEXT, {'vpnserver1': 'vpn.testdomain.com'}) def test_get_context_empty_vpn(self): v = Vpn() - self.assertEqual(v.get_context(), settings.OPENWISP_CONTROLLER_CONTEXT) + self.assertEqual(v.get_context(), app_settings.CONTEXT) def test_key_validator(self): v = self._create_vpn() diff --git a/tests/openwisp2/settings.py b/tests/openwisp2/settings.py index 43b76e98b..22bf571d4 100644 --- a/tests/openwisp2/settings.py +++ b/tests/openwisp2/settings.py @@ -180,8 +180,6 @@ OPENWISP_CONTROLLER_CONTEXT = {'vpnserver1': 'vpn.testdomain.com'} TEST_RUNNER = 'openwisp_utils.tests.TimeLoggingTestRunner' -if TESTING: - OPENWISP_CONTROLLER_HARDWARE_ID_ENABLED = True if os.environ.get('SAMPLE_APP', False): # Replace Config