import pytest from dmp.locations.models import City from dmp.locations.repositories import CityRepository from dmp.locations.types import Point from tests.unit.types import CreateReportingModel class TestCityRepository: @pytest.mark.db def test_get_closest_by_country_code2_and_name( self, repository: CityRepository, create_reporting_model: CreateReportingModel, ) -> None: new_york = create_reporting_model( City, country_code2="US", name="New York City", latitude=40.71453, longitude=-74.00712, ) create_reporting_model( City, country_code2="US", name="New York", latitude=46.51802, longitude=-95.37615, ) result = repository.get_closest_by_country_code2_and_name( country_code2="US", name="New York", position=Point(latitude=40.7128, longitude=-74.0060), ) assert result == new_york @pytest.mark.db def test_get_closest_by_country_code2_and_name_not_found( self, repository: CityRepository ) -> None: result = repository.get_closest_by_country_code2_and_name( country_code2="US", name="New York", position=Point(latitude=40.7128, longitude=-74.0060), ) assert result is None