2 Tests for functions to maintain the artificial postcode table.
7 from nominatim.tools import postcodes
10 def postcode_table(temp_db_with_extensions, temp_db_cursor, table_factory,
11 placex_table, word_table):
12 table_factory('location_postcode',
14 parent_place_id BIGINT,
16 rank_address SMALLINT,
17 indexed_status SMALLINT,
18 indexed_date TIMESTAMP,
19 country_code varchar(2),
21 geometry GEOMETRY(Geometry, 4326)""")
22 temp_db_cursor.execute('CREATE SEQUENCE seq_place')
23 temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION getorcreate_postcode_id(postcode TEXT)
24 RETURNS INTEGER AS $$ BEGIN RETURN 1; END; $$ LANGUAGE plpgsql;
28 def test_import_postcodes_empty(dsn, temp_db_cursor, postcode_table, tmp_path):
29 postcodes.import_postcodes(dsn, tmp_path)
31 assert temp_db_cursor.table_exists('gb_postcode')
32 assert temp_db_cursor.table_exists('us_postcode')
33 assert temp_db_cursor.table_rows('location_postcode') == 0
36 def test_import_postcodes_from_placex(dsn, temp_db_cursor, postcode_table, tmp_path):
37 temp_db_cursor.execute("""
38 INSERT INTO placex (place_id, country_code, address, geometry)
39 VALUES (1, 'xx', '"postcode"=>"9486"', 'SRID=4326;POINT(10 12)')
42 postcodes.import_postcodes(dsn, tmp_path)
44 rows = temp_db_cursor.row_set(""" SELECT postcode, country_code,
45 ST_X(geometry), ST_Y(geometry)
46 FROM location_postcode""")
49 assert rows == set((('9486', 'xx', 10, 12), ))