]> git.openstreetmap.org Git - nominatim.git/blob - test/python/db/test_properties.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / db / test_properties.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for property table manpulation.
9 """
10 import pytest
11
12 from nominatim_db.db import properties
13
14
15 @pytest.fixture
16 def property_factory(property_table, temp_db_cursor):
17     """ A function fixture that adds a property into the property table.
18     """
19     def _add_property(name, value):
20         temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES(%s, %s)",
21                                (name, value))
22
23     return _add_property
24
25
26 def test_get_property_existing(property_factory, temp_db_conn):
27     property_factory('foo', 'bar')
28
29     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
30
31
32 def test_get_property_unknown(property_factory, temp_db_conn):
33     property_factory('other', 'bar')
34
35     assert properties.get_property(temp_db_conn, 'foo') is None
36
37
38 @pytest.mark.parametrize("prefill", (True, False))
39 def test_set_property_new(property_factory, temp_db_conn, temp_db_cursor, prefill):
40     if prefill:
41         property_factory('something', 'bar')
42
43     properties.set_property(temp_db_conn, 'something', 'else')
44
45     assert temp_db_cursor.scalar("""SELECT value FROM nominatim_properties
46                                     WHERE property = 'something'""") == 'else'
47
48     assert properties.get_property(temp_db_conn, 'something') == 'else'