tests/lib/test_my_db.py
author fabien@tzone.org
Wed, 31 Dec 2008 00:07:25 -0500
changeset 69 d79722064d8d
parent 66 a0aa025ee6a2
child 70 1798859f7f6c
permissions -rw-r--r--
Merge previous changeset and ensure everything seems to work.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
     1
import testconfig
65
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     2
import unittest
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     3
import my_db
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     4
import pgdb
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     5
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     6
class TestMyDbConnexion(unittest.TestCase):
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     7
    def setUp(self):
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     8
        " Setup a test-db environment."
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     9
        self.db = my_db.connect(testconfig.CONFIG, "test")
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    10
        self.prefs = { 'keywords_box' : 10,
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    11
                       'keywords_sort' : 'count',
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    12
                       'keywords_reverse': True,
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    13
                       'fullname': 'Test User',
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    14
                       'default_view': 1 }
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    15
    
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    16
    def tearDown(self):
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    17
        " Tear down the test-db environment"
66
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    18
        self.db.delete_user(self.db.userid)
65
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    19
        pass
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    20
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    21
    def testConnect(self):
66
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    22
        self.assertNotEqual(self.db, None)
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    23
        self.assertNotEqual(self.db.userid, -1)
65
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    24
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    25
    def testGetPreferences(self):
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    26
        prefs = self.db.get_preferences()
66
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    27
	keys = prefs.keys()
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    28
	keys.sort()
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    29
	expKeys = self.prefs.keys()
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    30
	expKeys.sort()
a0aa025ee6a2 New version with tester.
fabien@tzone.org
parents: 65
diff changeset
    31
        self.assertEqual(expKeys, keys)
65
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    32
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    33
    def testSetPreferences(self):
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    34
        self.db.set_preferences(self.prefs)
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    35
        prefs = self.db.get_preferences()
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    36
        self.assertEqual(prefs, self.prefs)
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    37
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    38
if __name__ == '__main__':
b975a3d7606a Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    39
    unittest.main()