Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / trunk / psycopg2 / tests / extras_dictcursor.py
1 # extras_dictcursor - test if DictCursor extension class works
2 #
3 # Copyright (C) 2004 Federico Di Gregorio  <fog@debian.org>
4 #
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
8 # version.
9 #
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
13 # for more details.
14
15 import psycopg2
16 import psycopg2.extras
17 from unittest import TestCase, TestSuite, main
18
19
20 class ExtrasDictCursorTests(TestCase):
21     """Test if DictCursor extension class works."""
22
23     def setUp(self):
24         self.conn = psycopg2.connect("dbname=test")
25         curs = self.conn.cursor()
26         curs.execute("CREATE TABLE ExtrasDictCursorTests (foo text)")
27     
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")
32         row = curs.fetchone()
33         self.failUnless(row['foo'] == 'bar')
34         self.failUnless(row[0] == 'bar')
35
36 class ExtrasDictCursorSuite(TestSuite):
37     """Build a suite of all tests."""
38
39     def __init__(self):
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))
44
45
46 if __name__ == "__main__":
47     main()