@@ -63,7 +63,7 @@ def test_approximate_location_configuration_setting(self):
6363
6464 with self .subTest (
6565 "Test Approximate Location field visible on admin when "
66- "WHOIS_CONFIGURED True"
66+ "WHOIS_CONFIGURED is True"
6767 ):
6868 self ._login ()
6969 org = self ._get_org ()
@@ -83,7 +83,7 @@ def test_approximate_location_configuration_setting(self):
8383 importlib .reload (config_app_settings )
8484 with self .subTest (
8585 "Test Approximate Location field hidden on admin when "
86- "WHOIS_CONFIGURED False"
86+ "WHOIS_CONFIGURED is False"
8787 ):
8888 self ._login ()
8989 org = self ._get_org ()
@@ -118,6 +118,7 @@ def test_approximate_location_task_called(
118118 ):
119119 connect_whois_handlers ()
120120 mocked_client .return_value .city .return_value = self ._mocked_client_response ()
121+
121122 self ._task_called (
122123 mocked_approximate_location_task , task_name = "Approximate location"
123124 )
@@ -144,15 +145,21 @@ def test_approximate_location_creation_and_update(self, mock_client):
144145 def _verify_location_details (device , mocked_response ):
145146 location = device .devicelocation .location
146147 mocked_location = mocked_response .location
147- formatted_address = ", " .join (
148+ address = ", " .join (
148149 [
149150 mocked_response .city .name ,
150151 mocked_response .country .name ,
151152 mocked_response .continent .name ,
152153 mocked_response .postal .code ,
153154 ]
154155 )
155- self .assertEqual (location .address , formatted_address )
156+ ip_address = mocked_response .ip_address or device .last_ip
157+ location_name = (
158+ "," .join (address .split ("," )[:2 ])
159+ + f" (Estimated Location: { ip_address } )"
160+ )
161+ self .assertEqual (location .name , location_name )
162+ self .assertEqual (location .address , address )
156163 self .assertEqual (
157164 location .geometry ,
158165 GEOSGeometry (
@@ -168,6 +175,7 @@ def _verify_location_details(device, mocked_response):
168175 device = self ._create_device (last_ip = "172.217.22.14" )
169176
170177 location = device .devicelocation .location
178+ mocked_response .ip_address = device .last_ip
171179 self .assertEqual (location .is_approximate , True )
172180 self .assertEqual (location .is_mobile , False )
173181 self .assertEqual (location .type , "outdoor" )
@@ -183,6 +191,7 @@ def _verify_location_details(device, mocked_response):
183191 device .refresh_from_db ()
184192
185193 location = device .devicelocation .location
194+ mocked_response .ip_address = device .last_ip
186195 self .assertEqual (location .is_approximate , True )
187196 self .assertEqual (location .is_mobile , False )
188197 self .assertEqual (location .type , "outdoor" )
@@ -191,6 +200,7 @@ def _verify_location_details(device, mocked_response):
191200 with self .subTest (
192201 "Test Location not updated if it is not approximate when last ip is updated"
193202 ):
203+ mocked_response .ip_address = device .last_ip
194204 device .last_ip = "172.217.22.11"
195205 device .devicelocation .location .is_approximate = False
196206 mock_client .return_value .city .return_value = self ._mocked_client_response ()
0 commit comments