88
89
self.assertRaises(Exception, cursor.executemany, query, [(1,2,3),])
89
90
self.assertRaises(Exception, cursor.executemany, query, [(1,),])
92
def connection_created_test(sender, **kwargs):
93
print 'connection_created signal'
95
__test__ = {'API_TESTS': """
96
# Check Postgres version parsing
97
>>> from django.db.backends.postgresql import version as pg_version
99
>>> pg_version._parse_version("PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)")
102
>>> pg_version._parse_version("PostgreSQL 8.3.6")
105
>>> pg_version._parse_version("PostgreSQL 8.3")
108
>>> pg_version._parse_version("EnterpriseDB 8.3")
111
>>> pg_version._parse_version("PostgreSQL 8.3 beta4")
114
>>> pg_version._parse_version("PostgreSQL 8.4beta1")
92
class PostgresVersionTest(TestCase):
93
def assert_parses(self, version_string, version):
94
self.assertEqual(pg_version._parse_version(version_string), version)
96
def test_parsing(self):
97
self.assert_parses("PostgreSQL 8.3 beta4", (8, 3, None))
98
self.assert_parses("PostgreSQL 8.3", (8, 3, None))
99
self.assert_parses("EnterpriseDB 8.3", (8, 3, None))
100
self.assert_parses("PostgreSQL 8.3.6", (8, 3, 6))
101
self.assert_parses("PostgreSQL 8.4beta1", (8, 4, None))
102
self.assert_parses("PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)", (8, 3, 1))
119
104
# Unfortunately with sqlite3 the in-memory test database cannot be
120
105
# closed, and so it cannot be re-opened during testing, and so we
121
106
# sadly disable this test for now.
122
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.sqlite3':
123
__test__['API_TESTS'] += """
124
>>> connection_created.connect(connection_created_test)
125
>>> connection.close() # Ensure the connection is closed
126
>>> cursor = connection.cursor()
127
connection_created signal
128
>>> connection_created.disconnect(connection_created_test)
129
>>> cursor = connection.cursor()
132
if __name__ == '__main__':
107
if settings.DATABASES[DEFAULT_DB_ALIAS]["ENGINE"] != "django.db.backends.sqlite3":
108
class ConnectionCreatedSignalTest(TestCase):
109
def test_signal(self):
111
def receiver(sender, connection, **kwargs):
112
data["connection"] = connection
114
connection_created.connect(receiver)
116
cursor = connection.cursor()
117
self.assertTrue(data["connection"] is connection)
119
connection_created.disconnect(receiver)
121
cursor = connection.cursor()
122
self.assertTrue(data == {})