-@pytest.fixture
-def nonexistant_db():
- dbname = 'test_nominatim_python_unittest'
-
- conn = psycopg2.connect(database='postgres')
-
- conn.set_isolation_level(0)
- with conn.cursor() as cur:
- cur.execute('DROP DATABASE IF EXISTS {}'.format(dbname))
-
- yield dbname
-
- with conn.cursor() as cur:
- cur.execute('DROP DATABASE IF EXISTS {}'.format(dbname))
-
-@pytest.mark.parametrize("no_partitions", (True, False))
-def test_setup_skeleton(src_dir, nonexistant_db, no_partitions):
- database_import.setup_database_skeleton('dbname=' + nonexistant_db,
- src_dir / 'data', no_partitions)
-
- conn = psycopg2.connect(database=nonexistant_db)
-
- try:
- with conn.cursor() as cur:
- cur.execute("SELECT distinct partition FROM country_name")
- partitions = set([r[0] for r in list(cur)])
- if no_partitions:
- assert partitions == set([0])
- else:
- assert len(partitions) > 10
- finally:
- conn.close()
-
-
-def test_create_db_success(nonexistant_db):
- database_import.create_db('dbname=' + nonexistant_db, rouser='www-data')
-
- conn = psycopg2.connect(database=nonexistant_db)
- conn.close()
-
-
-def test_create_db_already_exists(temp_db):
- with pytest.raises(UsageError):
- database_import.create_db('dbname=' + temp_db)
-