]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/cursor.py
Merge pull request #3480 from mtmail/import-style-adits
[nominatim.git] / test / python / cursor.py
index 9b8ff83b1af9a300efebe9dea2169419be42b759..7d586b3c1520d9e0fea75cbd144c6111b3c0e58a 100644 (file)
@@ -1,9 +1,15 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
 """
 Specialised psycopg2 cursor with shortcut functions useful for testing.
 """
 import psycopg2.extras
 
 """
 Specialised psycopg2 cursor with shortcut functions useful for testing.
 """
 import psycopg2.extras
 
-class TestingCursor(psycopg2.extras.DictCursor):
+class CursorForTesting(psycopg2.extras.DictCursor):
     """ Extension to the DictCursor class that provides execution
         short-cuts that simplify writing assertions.
     """
     """ Extension to the DictCursor class that provides execution
         short-cuts that simplify writing assertions.
     """
@@ -37,6 +43,15 @@ class TestingCursor(psycopg2.extras.DictCursor):
         return num == 1
 
 
         return num == 1
 
 
+    def index_exists(self, table, index):
+        """ Check that an indexwith the given name exists on the given table.
+        """
+        num = self.scalar("""SELECT count(*) FROM pg_indexes
+                             WHERE tablename = %s and indexname = %s""",
+                          (table, index))
+        return num == 1
+
+
     def table_rows(self, table, where=None):
         """ Return the number of rows in the given table.
         """
     def table_rows(self, table, where=None):
         """ Return the number of rows in the given table.
         """