]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/test_db_properties.py
limit the number of variants that can be produced
[nominatim.git] / test / python / test_db_properties.py
index 9621c68cc9db652cb78b2c78c8486ac49d8cde4b..b17d41ea61de1e45c515b765c3b58777de5b6e53 100644 (file)
@@ -6,26 +6,32 @@ import pytest
 from nominatim.db import properties
 
 @pytest.fixture
 from nominatim.db import properties
 
 @pytest.fixture
-def prop_table(table_factory):
-    table_factory('nominatim_properties', 'property TEXT, value TEXT')
+def property_factory(property_table, temp_db_cursor):
+    """ A function fixture that adds a property into the property table.
+    """
+    def _add_property(name, value):
+        temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES(%s, %s)",
+                               (name, value))
 
 
+    return _add_property
 
 
-def test_get_property_existing(prop_table, temp_db_conn, temp_db_cursor):
-    temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('foo', 'bar')")
+
+def test_get_property_existing(property_factory, temp_db_conn):
+    property_factory('foo', 'bar')
 
     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
 
 
 
     assert properties.get_property(temp_db_conn, 'foo') == 'bar'
 
 
-def test_get_property_unknown(prop_table, temp_db_conn, temp_db_cursor):
-    temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('other', 'bar')")
+def test_get_property_unknown(property_factory, temp_db_conn):
+    property_factory('other', 'bar')
 
     assert properties.get_property(temp_db_conn, 'foo') is None
 
 
 @pytest.mark.parametrize("prefill", (True, False))
 
     assert properties.get_property(temp_db_conn, 'foo') is None
 
 
 @pytest.mark.parametrize("prefill", (True, False))
-def test_set_property_new(prop_table, temp_db_conn, temp_db_cursor, prefill):
+def test_set_property_new(property_factory, temp_db_conn, temp_db_cursor, prefill):
     if prefill:
     if prefill:
-        temp_db_cursor.execute("INSERT INTO nominatim_properties VALUES('something', 'bar')")
+        property_factory('something', 'bar')
 
     properties.set_property(temp_db_conn, 'something', 'else')
 
 
     properties.set_property(temp_db_conn, 'something', 'else')