44from django .contrib .gis .geos import GEOSGeometry
55from django .core .exceptions import ImproperlyConfigured , ValidationError
66from django .test import TestCase , TransactionTestCase , override_settings
7+ from django .urls import reverse
78from swapper import load_model
89
910from openwisp_controller .config import settings as config_app_settings
@@ -60,6 +61,41 @@ def test_approximate_location_configuration_setting(self):
6061 except AssertionError :
6162 self .fail ("ValidationError message not equal to expected message." )
6263
64+ with self .subTest (
65+ "Test Approximate Location field visible on admin when "
66+ "WHOIS_CONFIGURED True"
67+ ):
68+ self ._login ()
69+ org = self ._get_org ()
70+ url = reverse (
71+ "admin:openwisp_users_organization_change" ,
72+ args = [org .pk ],
73+ )
74+ response = self .client .get (url )
75+ self .assertContains (
76+ response , 'name="config_settings-0-approximate_location_enabled"'
77+ )
78+
79+ with override_settings (
80+ OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT = None ,
81+ OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY = None ,
82+ ):
83+ importlib .reload (config_app_settings )
84+ with self .subTest (
85+ "Test Approximate Location field hidden on admin when "
86+ "WHOIS_CONFIGURED False"
87+ ):
88+ self ._login ()
89+ org = self ._get_org ()
90+ url = reverse (
91+ "admin:openwisp_users_organization_change" ,
92+ args = [org .pk ],
93+ )
94+ response = self .client .get (url )
95+ self .assertNotContains (
96+ response , 'name="config_settings-0-approximate_location_enabled"'
97+ )
98+
6399
64100class TestApproximateLocationTransaction (
65101 TestApproximateLocationMixin , WHOISTransactionMixin , TransactionTestCase
@@ -128,7 +164,7 @@ def _verify_location_details(device, mocked_response):
128164 mocked_response = self ._mocked_client_response ()
129165 mock_client .return_value .city .return_value = mocked_response
130166
131- with self .subTest ("Test Fuzzy location created when device is created" ):
167+ with self .subTest ("Test Approximate location created when device is created" ):
132168 device = self ._create_device (last_ip = "172.217.22.14" )
133169
134170 location = device .devicelocation .location
@@ -137,7 +173,7 @@ def _verify_location_details(device, mocked_response):
137173 self .assertEqual (location .type , "outdoor" )
138174 _verify_location_details (device , mocked_response )
139175
140- with self .subTest ("Test Fuzzy location updated when last ip is updated" ):
176+ with self .subTest ("Test Approximate location updated when last ip is updated" ):
141177 device .last_ip = "172.217.22.10"
142178 mocked_response .location .latitude = 50
143179 mocked_response .location .longitude = 150
0 commit comments