1 # extras_dictcursor - test if DictCursor extension class works
3 # Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any later
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 import psycopg2.extras
17 from unittest import TestCase, TestSuite, main
20 class ExtrasDictCursorTests(TestCase):
21 """Test if DictCursor extension class works."""
24 self.conn = psycopg2.connect("dbname=test")
25 curs = self.conn.cursor()
26 curs.execute("CREATE TABLE ExtrasDictCursorTests (foo text)")
28 def testDictCursor(self):
29 curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
30 curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')")
31 curs.execute("SELECT * FROM ExtrasDictCursorTests")
33 self.failUnless(row['foo'] == 'bar')
34 self.failUnless(row[0] == 'bar')
36 class ExtrasDictCursorSuite(TestSuite):
37 """Build a suite of all tests."""
40 """Build a list of tests."""
41 self.tests = [x for x in dir(ExtrasDictCursorTests)
42 if x.startswith('test')]
43 TestSuite.__init__(self, map(TestModule, self.tests))
46 if __name__ == "__main__":