1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for property table manpulation.
 
  12 from nominatim_db.db import properties
 
  16 def property_factory(property_table, temp_db_cursor):
 
  17     """ A function fixture that adds a property into the property table.
 
  19     def _add_property(name, value):
 
  20         temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES(%s, %s)",
 
  26 def test_get_property_existing(property_factory, temp_db_conn):
 
  27     property_factory('foo', 'bar')
 
  29     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
 
  32 def test_get_property_unknown(property_factory, temp_db_conn):
 
  33     property_factory('other', 'bar')
 
  35     assert properties.get_property(temp_db_conn, 'foo') is None
 
  38 @pytest.mark.parametrize("prefill", (True, False))
 
  39 def test_set_property_new(property_factory, temp_db_conn, temp_db_cursor, prefill):
 
  41         property_factory('something', 'bar')
 
  43     properties.set_property(temp_db_conn, 'something', 'else')
 
  45     assert temp_db_cursor.scalar("""SELECT value FROM nominatim_properties
 
  46                                     WHERE property = 'something'""") == 'else'
 
  48     assert properties.get_property(temp_db_conn, 'something') == 'else'