1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2024 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
 
  15 def property_factory(property_table, temp_db_cursor):
 
  16     """ A function fixture that adds a property into the property table.
 
  18     def _add_property(name, value):
 
  19         temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES(%s, %s)",
 
  25 def test_get_property_existing(property_factory, temp_db_conn):
 
  26     property_factory('foo', 'bar')
 
  28     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
 
  31 def test_get_property_unknown(property_factory, temp_db_conn):
 
  32     property_factory('other', 'bar')
 
  34     assert properties.get_property(temp_db_conn, 'foo') is None
 
  37 @pytest.mark.parametrize("prefill", (True, False))
 
  38 def test_set_property_new(property_factory, temp_db_conn, temp_db_cursor, prefill):
 
  40         property_factory('something', 'bar')
 
  42     properties.set_property(temp_db_conn, 'something', 'else')
 
  44     assert temp_db_cursor.scalar("""SELECT value FROM nominatim_properties
 
  45                                     WHERE property = 'something'""") == 'else'
 
  47     assert properties.get_property(temp_db_conn, 'something') == 'else'