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