Integrate the new Location class
- the old `UTMCoordinate` class becomes the new `Location` class - its main purpose is to represent locations in both lat-long coordinates as well as in the UTM system - remove `Address.__init__()` and `City.__init__()` methods as they are not executed for entries retrieved from the database - simplfiy the `Location.__init__()` => remove `relative_to` argument
This commit is contained in:
parent
2e3ccd14d5
commit
a1cbb808fd
8 changed files with 198 additions and 157 deletions
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from tests.db.utils import test_coordinates as consts
|
||||
from tests.db.utils import test_locations as consts
|
||||
from urban_meal_delivery import db
|
||||
from urban_meal_delivery.db import utils
|
||||
|
||||
|
||||
class TestSpecialMethods:
|
||||
|
|
@ -39,16 +40,22 @@ class TestConstraints:
|
|||
class TestProperties:
|
||||
"""Test properties in `City`."""
|
||||
|
||||
def test_location_data(self, city, city_data):
|
||||
"""Test `City.location` property."""
|
||||
result = city.location
|
||||
def test_center(self, city, city_data):
|
||||
"""Test `City.center` property."""
|
||||
result = city.center
|
||||
|
||||
assert isinstance(result, dict)
|
||||
assert len(result) == 2
|
||||
assert result['latitude'] == pytest.approx(city_data['_center_latitude'])
|
||||
assert result['longitude'] == pytest.approx(city_data['_center_longitude'])
|
||||
assert isinstance(result, utils.Location)
|
||||
assert result.latitude == pytest.approx(city_data['_center_latitude'])
|
||||
assert result.longitude == pytest.approx(city_data['_center_longitude'])
|
||||
|
||||
def test_viewport_data_overall(self, city):
|
||||
def test_center_is_cached(self, city):
|
||||
"""Test `City.center` property."""
|
||||
result1 = city.center
|
||||
result2 = city.center
|
||||
|
||||
assert result1 is result2
|
||||
|
||||
def test_viewport_overall(self, city):
|
||||
"""Test `City.viewport` property."""
|
||||
result = city.viewport
|
||||
|
||||
|
|
@ -56,18 +63,24 @@ class TestProperties:
|
|||
assert len(result) == 2
|
||||
|
||||
@pytest.mark.parametrize('corner', ['northeast', 'southwest'])
|
||||
def test_viewport_data_corners(self, city, city_data, corner):
|
||||
def test_viewport_corners(self, city, city_data, corner):
|
||||
"""Test `City.viewport` property."""
|
||||
result = city.viewport[corner]
|
||||
|
||||
assert isinstance(result, dict)
|
||||
assert len(result) == 2
|
||||
assert result['latitude'] == pytest.approx(city_data[f'_{corner}_latitude'])
|
||||
assert result['longitude'] == pytest.approx(city_data[f'_{corner}_longitude'])
|
||||
assert isinstance(result, utils.Location)
|
||||
assert result.latitude == pytest.approx(city_data[f'_{corner}_latitude'])
|
||||
assert result.longitude == pytest.approx(city_data[f'_{corner}_longitude'])
|
||||
|
||||
def test_city_in_utm_coordinates(self, city):
|
||||
"""Test `City.as_origin` property."""
|
||||
result = city.as_origin
|
||||
def test_viewport_is_cached(self, city):
|
||||
"""Test `City.viewport` property."""
|
||||
result1 = city.viewport
|
||||
result2 = city.viewport
|
||||
|
||||
assert result1 is result2
|
||||
|
||||
def test_city_as_xy_origin(self, city):
|
||||
"""Test `City.as_xy_origin` property."""
|
||||
result = city.as_xy_origin
|
||||
|
||||
assert result.zone == consts.ZONE
|
||||
assert consts.MIN_EASTING < result.easting < consts.MAX_EASTING
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue