Skip to content

Commit 641a3d9

Browse files
committed
[qa] Refactor after rebasing
Signed-off-by: DragnEmperor <[email protected]>
1 parent 6538f8d commit 641a3d9

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

openwisp_controller/config/whois/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def _need_whois_lookup(self, new_ip):
9292
9393
The lookup is not triggered if:
9494
- The new IP address is None or it is a private IP address.
95-
- The WhoIs information of new ip is already present.
96-
- WhoIs is disabled in the organization settings. (query from db)
95+
- The WHOIS information of new ip is already present.
96+
- WHOIS is disabled in the organization settings. (query from db)
9797
"""
9898

9999
# Check cheap conditions first before hitting the database

openwisp_controller/config/whois/tasks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from openwisp_utils.tasks import OpenwispCeleryTask
1313

1414
from .. import settings as app_settings
15+
from .utils import send_whois_task_notification
1516

1617
logger = logging.getLogger(__name__)
1718

@@ -44,8 +45,6 @@ class WHOISCeleryRetryTask(OpenwispCeleryTask):
4445

4546
def on_failure(self, exc, task_id, args, kwargs, einfo):
4647
"""Notify the user about the failure of the WHOIS task."""
47-
from .utils import send_whois_task_notification
48-
4948
device_pk = kwargs.get("device_pk")
5049
send_whois_task_notification(device_pk=device_pk, notify_type="device_error")
5150
logger.error(f"WHOIS lookup failed. Details: {exc}")

openwisp_controller/config/whois/test_whois.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import importlib
22
from unittest import mock
33

4-
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
54
from django.contrib.gis.geos import Point
5+
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
66
from django.core.exceptions import ImproperlyConfigured, ValidationError
77
from django.db.models.signals import post_delete, post_save
88
from django.test import TestCase, TransactionTestCase, override_settings, tag
@@ -326,7 +326,7 @@ class TestWHOISTransaction(
326326
CreateWHOISMixin, WHOISTransactionMixin, TransactionTestCase
327327
):
328328
_WHOIS_GEOIP_CLIENT = (
329-
"openwisp_controller.config.whois.tasks.geoip2_webservice.Client.city"
329+
"openwisp_controller.config.whois.tasks.geoip2_webservice.Client"
330330
)
331331
_WHOIS_TASKS_INFO_LOGGER = "openwisp_controller.config.whois.tasks.logger.info"
332332
_WHOIS_TASKS_WARN_LOGGER = "openwisp_controller.config.whois.tasks.logger.warning"

openwisp_controller/config/whois/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
from swapper import load_model
44

55
from .. import settings as app_settings
6-
from .serializers import WHOISSerializer
7-
from .service import WHOISService
8-
9-
Device = load_model("config", "Device")
106

117
MESSAGE_MAP = {
128
"device_error": {
@@ -46,6 +42,11 @@ def send_whois_task_notification(device_pk, notify_type):
4642

4743

4844
def get_whois_info(pk):
45+
from .serializers import WHOISSerializer
46+
from .service import WHOISService
47+
48+
Device = load_model("config", "Device")
49+
4950
if not app_settings.WHOIS_CONFIGURED or not pk:
5051
return None
5152
device = (

openwisp_controller/geo/estimated_location/tasks.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ def _update_or_create_estimated_location(
5959
# we do not update it, but create a new one.
6060
_create_estimated_location(device_location, location_defaults)
6161
return
62-
updated = False
62+
update_fields = []
6363
for attr, value in location_defaults.items():
6464
if getattr(current_location, attr) != value:
6565
setattr(current_location, attr, value)
66-
updated = True
67-
if updated:
68-
current_location.full_clean()
69-
current_location.save()
66+
update_fields.append(attr)
67+
if update_fields:
68+
current_location.save(update_fields=update_fields)
7069
logger.info(
7170
f"Estimated location saved successfully for {device_pk}"
7271
f" for IP: {ip_address}"

0 commit comments

Comments
 (0)