]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/search/test_search_postcode.py
Merge pull request #3554 from lonvia/postcode-bbox
[nominatim.git] / test / python / api / search / test_search_postcode.py
index 6976b6a592ac5921fbb283c84c411065500793bb..369e15045e0fd4ecf11721e67ee342cb661ddef3 100644 (file)
@@ -2,17 +2,17 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for running the postcode searcher.
 """
 import pytest
 
 # For a full list of authors see the git log.
 """
 Tests for running the postcode searcher.
 """
 import pytest
 
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import PostcodeSearch
-from nominatim.api.search.db_search_fields import WeightedStrings, FieldLookup, \
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import PostcodeSearch
+from nominatim_api.search.db_search_fields import WeightedStrings, FieldLookup, \
                                                   FieldRanking, RankedTokens
 
 def run_search(apiobj, frontend, global_penalty, pcs, pc_penalties=None,
                                                   FieldRanking, RankedTokens
 
 def run_search(apiobj, frontend, global_penalty, pcs, pc_penalties=None,
@@ -59,6 +59,19 @@ def test_postcode_with_country(apiobj, frontend):
     assert results[0].place_id == 101
 
 
     assert results[0].place_id == 101
 
 
+def test_postcode_area(apiobj, frontend):
+    apiobj.add_postcode(place_id=100, country_code='ch', postcode='12345')
+    apiobj.add_placex(place_id=200, country_code='ch', postcode='12345',
+                      osm_type='R', osm_id=34, class_='boundary', type='postal_code',
+                      geometry='POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
+
+    results = run_search(apiobj, frontend, 0.3, ['12345'], [0.0])
+
+    assert len(results) == 1
+    assert results[0].place_id == 200
+    assert results[0].bbox.area == 1
+
+
 class TestPostcodeSearchWithAddress:
 
     @pytest.fixture(autouse=True)
 class TestPostcodeSearchWithAddress:
 
     @pytest.fixture(autouse=True)