~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/backends/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (4.4.9 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-5rk3p18nyanuhj6g
* SECURITY UPDATE: XSS in CSRF protections. New upstream release
  - CVE-2010-3082
* debian/patches/01_disable_url_verify_regression_tests.diff:
  - updated to disable another test that fails without internet connection
  - patch based on work by Kai Kasurinen and Krzysztof Klimonda
* debian/control: don't Build-Depends on locales-all, which doesn't exist
  in maverick

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import unittest
6
6
from django.db import backend, connection, DEFAULT_DB_ALIAS
7
7
from django.db.backends.signals import connection_created
 
8
from django.db.backends.postgresql import version as pg_version
8
9
from django.conf import settings
9
10
from django.test import TestCase
10
11
 
88
89
        self.assertRaises(Exception, cursor.executemany, query, [(1,2,3),])
89
90
        self.assertRaises(Exception, cursor.executemany, query, [(1,),])
90
91
 
91
 
 
92
 
def connection_created_test(sender, **kwargs):
93
 
    print 'connection_created signal'
94
 
 
95
 
__test__ = {'API_TESTS': """
96
 
# Check Postgres version parsing
97
 
>>> from django.db.backends.postgresql import version as pg_version
98
 
 
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)")
100
 
(8, 3, 1)
101
 
 
102
 
>>> pg_version._parse_version("PostgreSQL 8.3.6")
103
 
(8, 3, 6)
104
 
 
105
 
>>> pg_version._parse_version("PostgreSQL 8.3")
106
 
(8, 3, None)
107
 
 
108
 
>>> pg_version._parse_version("EnterpriseDB 8.3")
109
 
(8, 3, None)
110
 
 
111
 
>>> pg_version._parse_version("PostgreSQL 8.3 beta4")
112
 
(8, 3, None)
113
 
 
114
 
>>> pg_version._parse_version("PostgreSQL 8.4beta1")
115
 
(8, 4, None)
116
 
 
117
 
"""}
 
92
class PostgresVersionTest(TestCase):
 
93
    def assert_parses(self, version_string, version):
 
94
        self.assertEqual(pg_version._parse_version(version_string), version)
 
95
 
 
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))
118
103
 
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()
130
 
"""
131
 
 
132
 
if __name__ == '__main__':
133
 
    unittest.main()
 
107
if settings.DATABASES[DEFAULT_DB_ALIAS]["ENGINE"] != "django.db.backends.sqlite3":
 
108
    class ConnectionCreatedSignalTest(TestCase):
 
109
        def test_signal(self):
 
110
            data = {}
 
111
            def receiver(sender, connection, **kwargs):
 
112
                data["connection"] = connection
 
113
 
 
114
            connection_created.connect(receiver)
 
115
            connection.close()
 
116
            cursor = connection.cursor()
 
117
            self.assertTrue(data["connection"] is connection)
 
118
 
 
119
            connection_created.disconnect(receiver)
 
120
            data.clear()
 
121
            cursor = connection.cursor()
 
122
            self.assertTrue(data == {})