Skip to content

Commit 249f28a

Browse files
committed
[fix] Fixed tests
1 parent cc29d7c commit 249f28a

11 files changed

Lines changed: 84 additions & 32 deletions

File tree

openwisp_controller/config/whois/tests/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,8 @@ def test_process_whois_details_handles_missing_coordinates(self, mock_client):
456456
def test_fetch_whois_emits_signal(self, mock_client):
457457
connect_whois_handlers()
458458
mock_client.return_value.city.return_value = self._mocked_client_response()
459-
device = self._create_device(last_ip="172.217.22.14")
460459
with catch_signal(whois_fetched) as handler:
461-
fetch_whois_details(device_pk=device.pk, initial_ip_address=None)
460+
self._create_device(last_ip="172.217.22.14")
462461
handler.assert_called()
463462

464463
@mock.patch.object(app_settings, "WHOIS_CONFIGURED", True)

openwisp_controller/geo/apps.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from openwisp_utils.admin_theme import register_dashboard_chart
1616
from openwisp_utils.admin_theme.menu import register_menu_group
1717

18-
from ..config import settings as config_app_settings
1918
from .estimated_location.handlers import (
2019
register_estimated_location_notification_types,
2120
whois_fetched_handler,
@@ -64,16 +63,15 @@ def connect_receivers(self):
6463
sender=self.org_geo_settings_model,
6564
dispatch_uid="invalidate_org_geo_settings_cache_on_delete",
6665
)
67-
if config_app_settings.WHOIS_CONFIGURED:
68-
# connect estimated location handler to whois_fetched signal
69-
whois_fetched.connect(
70-
whois_fetched_handler,
71-
dispatch_uid="whois_fetched_estimated_location_handler",
72-
)
73-
whois_lookup_skipped.connect(
74-
whois_lookup_skipped_handler,
75-
dispatch_uid="whois_lookup_skipped_estimated_location_handler",
76-
)
66+
# connect estimated location handler to whois_fetched signal
67+
whois_fetched.connect(
68+
whois_fetched_handler,
69+
dispatch_uid="whois_fetched_estimated_location_handler",
70+
)
71+
whois_lookup_skipped.connect(
72+
whois_lookup_skipped_handler,
73+
dispatch_uid="whois_lookup_skipped_estimated_location_handler",
74+
)
7775

7876
def _add_params_to_test_config(self):
7977
"""

openwisp_controller/geo/estimated_location/service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from openwisp_controller.config import settings as config_app_settings
99
from openwisp_controller.config.whois.utils import send_whois_task_notification
1010

11-
from .. import settings as geo_settings
12-
1311
logger = logging.getLogger(__name__)
1412

1513

openwisp_controller/geo/estimated_location/tests/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def test_estimated_location_configuration_setting(self):
9393
response, 'name="geo_settings-0-estimated_location_enabled"'
9494
)
9595

96+
@mock.patch.object(config_app_settings, "WHOIS_CONFIGURED", True)
9697
def test_organization_geo_settings_validation(self):
9798
"""Test OrganizationGeoSettings model validation."""
9899
org = self._get_org()
@@ -392,7 +393,7 @@ def _verify_location_details(device, mocked_response):
392393

393394
with self.subTest("Test Estimated location created when device is created"):
394395
device = self._create_device(last_ip="172.217.22.14")
395-
with self.assertNumQueries(14):
396+
with self.assertNumQueries(13):
396397
manage_estimated_locations(device.pk, device.last_ip)
397398
location = device.devicelocation.location
398399
mocked_response.ip_address = device.last_ip

openwisp_controller/geo/estimated_location/tests/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def setUp(self):
2121
# Ensure OrganizationGeoSettings exists (signals usually create it on
2222
# Organization creation, but make this explicit to avoid RelatedObject
2323
# errors in some test setups).
24-
org_geo_settings, _ = OrganizationGeoSettings.objects.get_or_create(organization=org)
24+
org_geo_settings, _ = OrganizationGeoSettings.objects.get_or_create(
25+
organization=org
26+
)
2527
org_geo_settings.estimated_location_enabled = True
2628
org_geo_settings.save()
2729

openwisp_controller/geo/migrations/0005_organizationgeosettings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Migration(migrations.Migration):
4545
models.OneToOneField(
4646
on_delete=django.db.models.deletion.CASCADE,
4747
related_name="geo_settings",
48-
to="openwisp_users.organization",
48+
to=swapper.get_model_name("openwisp_users", "Organization"),
4949
verbose_name="organization",
5050
),
5151
),

openwisp_controller/geo/migrations/0006_create_geo_settings_for_existing_orgs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from django.db import migrations
44

5-
from . import assign_geo_settings_permissions_to_groups
65
from ...migrations import get_swapped_model
6+
from . import assign_geo_settings_permissions_to_groups
7+
78

89
def create_geo_settings_for_existing_orgs(apps, schema_editor):
910
"""

openwisp_controller/geo/tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _create_organization(self, **kwargs):
2121

2222
def _add_default_org(self, kwargs):
2323
if "organization" not in kwargs:
24-
kwargs["organization"] = self._get_org()
24+
kwargs["organization"] = self._create_organization()
2525
return kwargs
2626

2727
def _create_object(self, **kwargs):

openwisp_controller/tests/mixins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def _get_org_edit_form_inline_params(self, user, org):
1111
"config_settings-INITIAL_FORMS": 0,
1212
"config_settings-MIN_NUM_FORMS": 0,
1313
"config_settings-MAX_NUM_FORMS": 0,
14+
# geo inline
15+
"geo_settings-TOTAL_FORMS": 0,
16+
"geo_settings-INITIAL_FORMS": 0,
17+
"geo_settings-MIN_NUM_FORMS": 0,
18+
"geo_settings-MAX_NUM_FORMS": 0,
1419
# device limit inline
1520
"config_limits-TOTAL_FORMS": 0,
1621
"config_limits-INITIAL_FORMS": 0,

tests/openwisp2/sample_config/migrations/0009_organizationconfigsettings_approximate_location_enabled_and_more.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ class Migration(migrations.Migration):
1313
]
1414

1515
operations = [
16-
migrations.AddField(
17-
model_name="organizationconfigsettings",
18-
name="estimated_location_enabled",
19-
field=openwisp_utils.fields.FallbackBooleanChoiceField(
20-
blank=True,
21-
default=None,
22-
fallback=False,
23-
help_text="Whether the estimated location feature is enabled",
24-
null=True,
25-
verbose_name="Estimated Location Enabled",
26-
),
27-
),
2816
migrations.AddField(
2917
model_name="whoisinfo",
3018
name="coordinates",

0 commit comments

Comments
 (0)