2 Test for tiger data function
4 from pathlib import Path
9 from nominatim.tools import tiger_data, database_import
12 @pytest.mark.parametrize("threads", (1, 5))
13 def test_add_tiger_data(dsn, src_dir, def_config, tmp_path, sql_preprocessor,
14 temp_db_cursor, threads, temp_db):
15 temp_db_cursor.execute('CREATE EXTENSION hstore')
16 temp_db_cursor.execute('CREATE EXTENSION postgis')
17 temp_db_cursor.execute('CREATE TABLE place (id INT)')
18 sqlfile = tmp_path / '1010.sql'
19 sqlfile.write_text("""INSERT INTO place values (1);
20 INSERT INTO non_existant_table values (1);""")
21 tiger_data.add_tiger_data(dsn, str(tmp_path), threads, def_config, src_dir / 'lib-sql')
23 assert temp_db_cursor.table_rows('place') == 1
25 @pytest.mark.parametrize("threads", (1, 5))
26 def test_add_tiger_data_bad_file(dsn, src_dir, def_config, tmp_path, sql_preprocessor,
27 temp_db_cursor, threads, temp_db):
28 temp_db_cursor.execute('CREATE EXTENSION hstore')
29 temp_db_cursor.execute('CREATE EXTENSION postgis')
30 temp_db_cursor.execute('CREATE TABLE place (id INT)')
31 sqlfile = tmp_path / '1010.txt'
32 sqlfile.write_text("""Random text""")
33 tiger_data.add_tiger_data(dsn, str(tmp_path), threads, def_config, src_dir / 'lib-sql')
35 assert temp_db_cursor.table_rows('place') == 0
37 @pytest.mark.parametrize("threads", (1, 5))
38 def test_add_tiger_data_tarfile(dsn, src_dir, def_config, tmp_path,
39 temp_db_cursor, threads, temp_db, sql_preprocessor):
40 temp_db_cursor.execute('CREATE EXTENSION hstore')
41 temp_db_cursor.execute('CREATE EXTENSION postgis')
42 temp_db_cursor.execute('CREATE TABLE place (id INT)')
43 sqlfile = tmp_path / '1010.sql'
44 sqlfile.write_text("""INSERT INTO place values (1);
45 INSERT INTO non_existant_table values (1);""")
46 tar = tarfile.open("sample.tar.gz", "w:gz")
49 tiger_data.add_tiger_data(dsn, str(src_dir / 'sample.tar.gz'), threads, def_config, src_dir / 'lib-sql')
51 assert temp_db_cursor.table_rows('place') == 1
53 @pytest.mark.parametrize("threads", (1, 5))
54 def test_add_tiger_data_bad_tarfile(dsn, src_dir, def_config, tmp_path,
55 temp_db_cursor, threads, temp_db, sql_preprocessor):
56 temp_db_cursor.execute('CREATE EXTENSION hstore')
57 temp_db_cursor.execute('CREATE EXTENSION postgis')
58 temp_db_cursor.execute('CREATE TABLE place (id INT)')
59 sqlfile = tmp_path / '1010.txt'
60 sqlfile.write_text("""Random text""")
61 tar = tarfile.open("sample.tar.gz", "w:gz")
64 tiger_data.add_tiger_data(dsn, str(src_dir / 'sample.tar.gz'), threads, def_config, src_dir / 'lib-sql')
66 assert temp_db_cursor.table_rows('place') == 0