99from django .core .exceptions import ValidationError
1010from django .db .models .signals import post_save
1111from django .db .utils import IntegrityError
12- from django .http .response import HttpResponse , HttpResponseNotFound
1312from django .test import TestCase , TransactionTestCase
1413from requests .exceptions import ConnectionError , RequestException , Timeout
1514from swapper import load_model
@@ -828,6 +827,9 @@ def test_update_vpn_server_configuration(self):
828827 f"Cannot update configuration of { vpn .name } VPN server, "
829828 "webhook endpoint and authentication token are empty."
830829 )
830+ success_response = mock .Mock (spec = requests .Response )
831+ success_response .status_code = 200
832+ success_response .raise_for_status = mock .Mock ()
831833
832834 with self .subTest ("Webhook endpoint and authentication endpoint is present" ):
833835 vpn .webhook_endpoint = "https://example.com"
@@ -838,24 +840,29 @@ def test_update_vpn_server_configuration(self):
838840 with mock .patch (
839841 "openwisp_controller.config.tasks.logger.info"
840842 ) as mocked_logger , mock .patch (
841- "requests.post" , return_value = HttpResponse ()
843+ "requests.post" , return_value = success_response
842844 ):
843845 post_save .send (
844846 instance = vpn_client , sender = vpn_client ._meta .model , created = False
845847 )
846848 mocked_logger .assert_called_once_with (
847849 f"Triggered update webhook of VPN Server UUID: { vpn .pk } "
848850 )
851+ fail_response = mock .Mock (spec = requests .Response )
852+ fail_response .status_code = 404
853+ fail_response .raise_for_status .side_effect = requests .exceptions .HTTPError (
854+ "Not Found"
855+ )
849856
850- with mock .patch ("logging.Logger.error " ) as mocked_logger , mock .patch (
851- "requests.post" , return_value = HttpResponseNotFound ()
857+ with mock .patch ("logging.Logger.warning " ) as mocked_logger , mock .patch (
858+ "requests.post" , return_value = fail_response
852859 ):
853860 post_save .send (
854861 instance = vpn_client , sender = vpn_client ._meta .model , created = False
855862 )
856863 mocked_logger .assert_called_once_with (
857864 "Failed to update VPN Server configuration. "
858- f"Response status code: 404 , VPN Server UUID: { vpn .pk } "
865+ f"Error: Not Found , VPN Server UUID: { vpn .pk } "
859866 )
860867
861868 def test_vpn_peers_changed (self ):
@@ -1467,7 +1474,9 @@ class TestZeroTierTransaction(
14671474):
14681475 _ZT_SERVICE_REQUESTS = "openwisp_controller.config.api.zerotier_service.requests"
14691476 _ZT_API_TASKS_INFO_LOGGER = "openwisp_controller.config.tasks_zerotier.logger.info"
1470- _ZT_API_TASKS_WARN_LOGGER = "openwisp_controller.config.tasks_zerotier.logger.warn"
1477+ _ZT_API_TASKS_WARN_LOGGER = (
1478+ "openwisp_controller.config.tasks_zerotier.logger.warning"
1479+ )
14711480 _ZT_API_TASKS_ERR_LOGGER = "openwisp_controller.config.tasks_zerotier.logger.error"
14721481 # As the locmem cache does not support the redis backend cache.keys() method
14731482 _ZT_API_TASKS_LOCMEM_CACHE_KEYS = f"{ settings .CACHES ['default' ]['BACKEND' ]} .keys"
0 commit comments