Debian Codegraph @

tests/postgres_tests/test_signals.py

raw
1 from django.db import connection
2
3 from . import PostgreSQLTestCase
4
5 try:
6 from django.contrib.postgres.signals import (
7 get_citext_oids,
8 get_hstore_oids,
9 register_type_handlers,
10 )
11 except ImportError:
12 pass # psycopg isn't installed.
13
14
15 class OIDTests(PostgreSQLTestCase):
16 def assertOIDs(self, oids):
17 self.assertIsInstance(oids, tuple)
18 self.assertGreater(len(oids), 0)
19 self.assertTrue(all(isinstance(oid, int) for oid in oids))
20
21 def test_hstore_cache(self):
22 get_hstore_oids(connection.alias)
23 with self.assertNumQueries(0):
24 get_hstore_oids(connection.alias)
25
26 def test_citext_cache(self):
27 get_citext_oids(connection.alias)
28 with self.assertNumQueries(0):
29 get_citext_oids(connection.alias)
30
31 def test_hstore_values(self):
32 oids, array_oids = get_hstore_oids(connection.alias)
33 self.assertOIDs(oids)
34 self.assertOIDs(array_oids)
35
36 def test_citext_values(self):
37 oids, citext_oids = get_citext_oids(connection.alias)
38 self.assertOIDs(oids)
39 self.assertOIDs(citext_oids)
40
41 def test_register_type_handlers_no_db(self):
42 """Registering type handlers for the nodb connection does nothing."""
43 with connection._nodb_cursor() as cursor:
44 register_type_handlers(cursor.db)