Skip to content

Commit fbd5bb7

Browse files
committed
[qa] Refactoring in docs, tests
Signed-off-by: DragnEmperor <[email protected]>
1 parent fde52b0 commit fbd5bb7

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

docs/user/approximate-location.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Approximate Location
66
The **Approximate Location** feature is **disabled by default**.
77

88
Before enabling it, the :doc:`WHOIS Lookup feature <whois>` must be
9-
enabled and then set
9+
enabled. Then set
1010
:ref:`OPENWISP_CONTROLLER_APPROXIMATE_LOCATION_ENABLED` to ``True``
1111

1212
.. contents:: **Table of contents**:
@@ -35,12 +35,17 @@ Approximate Location is triggered when:
3535
Behavior
3636
--------
3737

38-
If **a matching location already exists** for another device with the same
39-
IP, the system will **attach that location** to the current device if:
38+
The system will **attach the already existing matching location** of
39+
another device with same ip to the current device if:
4040

4141
- Only one device is found with that IP and it has a location.
42-
- The current device **has no location** or if it does then the location
43-
is **approximate**.
42+
- The current device **has no location** or that location is
43+
**approximate**.
44+
45+
If there are multiple devices with location for the same IP, the system
46+
will **not attach any location** to the current device and a notification
47+
will be sent suggesting the user to manually assign/create a location for
48+
the device.
4449

4550
If there is **no matching location**, a new approximate location is
4651
created or the existing one is updated using coordinates from the WHOIS

openwisp_controller/geo/approximate_location/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _create_update_location():
4141
coords = Point(whois_obj.longitude, whois_obj.latitude, srid=4326)
4242
address = whois_obj.formatted_address
4343
location_name = (
44-
",".join(address.split(",")[:2]) + f" (Estimated: {ip_address})"
44+
",".join(address.split(",")[:2]) + f" (Estimated Location: {ip_address})"
4545
if address
4646
else f"Estimated Location: {ip_address}"
4747
)

openwisp_controller/geo/approximate_location/test_approximate_location.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)