2017-09-15 14:00:12 +00:00
|
|
|
from django.db import connection
|
|
|
|
|
|
|
|
from . import PostgreSQLTestCase
|
|
|
|
|
|
|
|
try:
|
2017-09-18 18:29:47 +00:00
|
|
|
from django.contrib.postgres.signals import (
|
2022-02-03 19:24:19 +00:00
|
|
|
get_citext_oids,
|
|
|
|
get_hstore_oids,
|
|
|
|
register_type_handlers,
|
2017-09-18 18:29:47 +00:00
|
|
|
)
|
2017-09-15 14:00:12 +00:00
|
|
|
except ImportError:
|
2022-12-06 11:33:44 +00:00
|
|
|
pass # psycopg isn't installed.
|
2017-09-15 14:00:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OIDTests(PostgreSQLTestCase):
|
|
|
|
def assertOIDs(self, oids):
|
|
|
|
self.assertIsInstance(oids, tuple)
|
|
|
|
self.assertGreater(len(oids), 0)
|
|
|
|
self.assertTrue(all(isinstance(oid, int) for oid in oids))
|
|
|
|
|
|
|
|
def test_hstore_cache(self):
|
2018-10-09 13:23:36 +00:00
|
|
|
get_hstore_oids(connection.alias)
|
2017-09-15 14:00:12 +00:00
|
|
|
with self.assertNumQueries(0):
|
|
|
|
get_hstore_oids(connection.alias)
|
|
|
|
|
|
|
|
def test_citext_cache(self):
|
2018-10-09 13:23:36 +00:00
|
|
|
get_citext_oids(connection.alias)
|
2017-09-15 14:00:12 +00:00
|
|
|
with self.assertNumQueries(0):
|
|
|
|
get_citext_oids(connection.alias)
|
|
|
|
|
|
|
|
def test_hstore_values(self):
|
|
|
|
oids, array_oids = get_hstore_oids(connection.alias)
|
|
|
|
self.assertOIDs(oids)
|
|
|
|
self.assertOIDs(array_oids)
|
|
|
|
|
|
|
|
def test_citext_values(self):
|
2022-12-01 09:59:20 +00:00
|
|
|
oids, citext_oids = get_citext_oids(connection.alias)
|
2017-09-15 14:00:12 +00:00
|
|
|
self.assertOIDs(oids)
|
2022-12-01 09:59:20 +00:00
|
|
|
self.assertOIDs(citext_oids)
|
2017-09-18 18:29:47 +00:00
|
|
|
|
|
|
|
def test_register_type_handlers_no_db(self):
|
|
|
|
"""Registering type handlers for the nodb connection does nothing."""
|
2020-02-04 03:07:00 +00:00
|
|
|
with connection._nodb_cursor() as cursor:
|
|
|
|
register_type_handlers(cursor.db)
|