@@ -63,7 +63,7 @@ def test_approximate_location_configuration_setting(self):
63
63
64
64
with self .subTest (
65
65
"Test Approximate Location field visible on admin when "
66
- "WHOIS_CONFIGURED True"
66
+ "WHOIS_CONFIGURED is True"
67
67
):
68
68
self ._login ()
69
69
org = self ._get_org ()
@@ -83,7 +83,7 @@ def test_approximate_location_configuration_setting(self):
83
83
importlib .reload (config_app_settings )
84
84
with self .subTest (
85
85
"Test Approximate Location field hidden on admin when "
86
- "WHOIS_CONFIGURED False"
86
+ "WHOIS_CONFIGURED is False"
87
87
):
88
88
self ._login ()
89
89
org = self ._get_org ()
@@ -118,6 +118,7 @@ def test_approximate_location_task_called(
118
118
):
119
119
connect_whois_handlers ()
120
120
mocked_client .return_value .city .return_value = self ._mocked_client_response ()
121
+
121
122
self ._task_called (
122
123
mocked_approximate_location_task , task_name = "Approximate location"
123
124
)
@@ -144,15 +145,21 @@ def test_approximate_location_creation_and_update(self, mock_client):
144
145
def _verify_location_details (device , mocked_response ):
145
146
location = device .devicelocation .location
146
147
mocked_location = mocked_response .location
147
- formatted_address = ", " .join (
148
+ address = ", " .join (
148
149
[
149
150
mocked_response .city .name ,
150
151
mocked_response .country .name ,
151
152
mocked_response .continent .name ,
152
153
mocked_response .postal .code ,
153
154
]
154
155
)
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 )
156
163
self .assertEqual (
157
164
location .geometry ,
158
165
GEOSGeometry (
@@ -168,6 +175,7 @@ def _verify_location_details(device, mocked_response):
168
175
device = self ._create_device (last_ip = "172.217.22.14" )
169
176
170
177
location = device .devicelocation .location
178
+ mocked_response .ip_address = device .last_ip
171
179
self .assertEqual (location .is_approximate , True )
172
180
self .assertEqual (location .is_mobile , False )
173
181
self .assertEqual (location .type , "outdoor" )
@@ -183,6 +191,7 @@ def _verify_location_details(device, mocked_response):
183
191
device .refresh_from_db ()
184
192
185
193
location = device .devicelocation .location
194
+ mocked_response .ip_address = device .last_ip
186
195
self .assertEqual (location .is_approximate , True )
187
196
self .assertEqual (location .is_mobile , False )
188
197
self .assertEqual (location .type , "outdoor" )
@@ -191,6 +200,7 @@ def _verify_location_details(device, mocked_response):
191
200
with self .subTest (
192
201
"Test Location not updated if it is not approximate when last ip is updated"
193
202
):
203
+ mocked_response .ip_address = device .last_ip
194
204
device .last_ip = "172.217.22.11"
195
205
device .devicelocation .location .is_approximate = False
196
206
mock_client .return_value .city .return_value = self ._mocked_client_response ()
0 commit comments