]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_db_properties.py
Encapsulation of tools/special_phrases.py into SpecialPhrasesImporter class and add...
[nominatim.git] / test / python / test_db_properties.py
1 """
2 Tests for property table manpulation.
3 """
4 import pytest
5
6 from nominatim.db import properties
7
8 @pytest.fixture
9 def prop_table(table_factory):
10     table_factory('nominatim_properties', 'property TEXT, value TEXT')
11
12
13 def test_get_property_existing(prop_table, temp_db_conn, temp_db_cursor):
14     temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('foo', 'bar')")
15
16     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
17
18
19 def test_get_property_unknown(prop_table, temp_db_conn, temp_db_cursor):
20     temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('other', 'bar')")
21
22     assert properties.get_property(temp_db_conn, 'foo') is None
23
24
25 @pytest.mark.parametrize("prefill", (True, False))
26 def test_set_property_new(prop_table, temp_db_conn, temp_db_cursor, prefill):
27     if prefill:
28         temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('something', 'bar')")
29
30     properties.set_property(temp_db_conn, 'something', 'else')
31
32     assert temp_db_cursor.scalar("""SELECT value FROM nominatim_properties
33                                     WHERE property = 'something'""") == 'else'
34
35     assert properties.get_property(temp_db_conn, 'something') == 'else'