~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to tests/test_connection.py

  • Committer: Federico Di Gregorio
  • Date: 2009-04-20 22:38:09 UTC
  • Revision ID: fog@erin-20090420223809-y59bb142mo3vadnw
Better detection of PostgreSQL version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import unittest
 
3
 
 
4
import psycopg2
 
5
import tests
 
6
 
 
7
 
 
8
class ConnectionTests(unittest.TestCase):
 
9
 
 
10
    def connect(self):
 
11
        return psycopg2.connect(tests.dsn)
 
12
 
 
13
    def test_closed_attribute(self):
 
14
        conn = self.connect()
 
15
        self.assertEqual(conn.closed, False)
 
16
        conn.close()
 
17
        self.assertEqual(conn.closed, True)
 
18
 
 
19
    def test_cursor_closed_attribute(self):
 
20
        conn = self.connect()
 
21
        curs = conn.cursor()
 
22
        self.assertEqual(curs.closed, False)
 
23
        curs.close()
 
24
        self.assertEqual(curs.closed, True)
 
25
 
 
26
        # Closing the connection closes the cursor:
 
27
        curs = conn.cursor()
 
28
        conn.close()
 
29
        self.assertEqual(curs.closed, True)
 
30
 
 
31
 
 
32
def test_suite():
 
33
    return unittest.TestLoader().loadTestsFromName(__name__)
 
34