2007-11-11 13:40:12 +03:00
|
|
|
#!/usr/bin/env python
|
2005-01-13 19:50:29 +03:00
|
|
|
# extras_dictcursor - test if DictCursor extension class works
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by the
|
|
|
|
# Free Software Foundation; either version 2, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# for more details.
|
|
|
|
|
2005-07-17 08:26:27 +04:00
|
|
|
import psycopg2
|
|
|
|
import psycopg2.extras
|
2007-11-11 13:40:12 +03:00
|
|
|
import unittest
|
2005-01-13 19:50:29 +03:00
|
|
|
|
2007-11-11 13:40:12 +03:00
|
|
|
import tests
|
2005-01-13 19:50:29 +03:00
|
|
|
|
2007-11-11 13:40:12 +03:00
|
|
|
|
|
|
|
class ExtrasDictCursorTests(unittest.TestCase):
|
2005-01-13 19:50:29 +03:00
|
|
|
"""Test if DictCursor extension class works."""
|
|
|
|
|
|
|
|
def setUp(self):
|
2007-11-11 13:40:12 +03:00
|
|
|
self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
|
2005-01-13 19:50:29 +03:00
|
|
|
curs = self.conn.cursor()
|
2007-11-11 13:40:12 +03:00
|
|
|
curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.conn.close()
|
|
|
|
|
2005-01-13 19:50:29 +03:00
|
|
|
def testDictCursor(self):
|
2005-07-17 08:26:27 +04:00
|
|
|
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
2005-01-13 19:50:29 +03:00
|
|
|
curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')")
|
|
|
|
curs.execute("SELECT * FROM ExtrasDictCursorTests")
|
|
|
|
row = curs.fetchone()
|
|
|
|
self.failUnless(row['foo'] == 'bar')
|
|
|
|
self.failUnless(row[0] == 'bar')
|
|
|
|
|
|
|
|
|
2007-11-11 13:40:12 +03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
2005-01-13 19:50:29 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2007-11-11 13:40:12 +03:00
|
|
|
unittest.main()
|