]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_db_properties.py
reorganize and complete tests around generic token analysis
[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 property_factory(property_table, temp_db_cursor):
10     """ A function fixture that adds a property into the property table.
11     """
12     def _add_property(name, value):
13         temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES(%s, %s)",
14                                (name, value))
15
16     return _add_property
17
18
19 def test_get_property_existing(property_factory, temp_db_conn):
20     property_factory('foo', 'bar')
21
22     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
23
24
25 def test_get_property_unknown(property_factory, temp_db_conn):
26     property_factory('other', 'bar')
27
28     assert properties.get_property(temp_db_conn, 'foo') is None
29
30
31 @pytest.mark.parametrize("prefill", (True, False))
32 def test_set_property_new(property_factory, temp_db_conn, temp_db_cursor, prefill):
33     if prefill:
34         property_factory('something', 'bar')
35
36     properties.set_property(temp_db_conn, 'something', 'else')
37
38     assert temp_db_cursor.scalar("""SELECT value FROM nominatim_properties
39                                     WHERE property = 'something'""") == 'else'
40
41     assert properties.get_property(temp_db_conn, 'something') == 'else'