author | fabien@tzone.org |
Wed, 31 Dec 2008 01:53:22 -0500 | |
changeset 73 | c078d8a04d76 |
parent 70 | 1798859f7f6c |
permissions | -rw-r--r-- |
66 | 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): |
70 | 7 |
def setUp(self): |
8 |
" Setup a test-db environment." |
|
9 |
self.db = my_db.connect(testconfig.CONFIG, "test") |
|
10 |
self.prefs = { 'keywords_box' : 10, |
|
11 |
'keywords_sort' : 'count', |
|
12 |
'keywords_reverse': True, |
|
13 |
'fullname': 'Test User', |
|
14 |
'default_view': 1 } |
|
15 |
||
16 |
def tearDown(self): |
|
17 |
" Tear down the test-db environment" |
|
18 |
self.db.delete_user(self.db.userid) |
|
19 |
||
20 |
def testConnect(self): |
|
21 |
self.assertNotEqual(self.db, None) |
|
22 |
self.assertNotEqual(self.db.userid, -1) |
|
23 |
||
24 |
def testGetPreferences(self): |
|
25 |
prefs = self.db.get_preferences() |
|
26 |
keys = prefs.keys() |
|
27 |
keys.sort() |
|
28 |
expKeys = self.prefs.keys() |
|
29 |
expKeys.sort() |
|
30 |
self.assertEqual(expKeys, keys) |
|
65
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
31 |
|
70 | 32 |
def testSetPreferences(self): |
33 |
self.db.set_preferences(self.prefs) |
|
34 |
prefs = self.db.get_preferences() |
|
35 |
self.assertEqual(prefs, self.prefs) |
|
36 |
||
37 |
def testAddKeyword(self): |
|
38 |
kw = self.db.add_keyword('keyword') |
|
39 |
self.assertEqual(self.db.get_keyword(kw), 'keyword') |
|
65
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
40 |
|
70 | 41 |
def testRemoveKeyword(self): |
42 |
kw = self.db.add_keyword('keyword') |
|
43 |
self.db.remove_keyword(kw) |
|
44 |
kws = self.db.get_all_keywords() |
|
45 |
# There is always '--' by default |
|
46 |
self.assertEqual(len(kws), 1) |
|
65
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
47 |
|
70 | 48 |
def testMapKeywords(self): |
49 |
kws = ('kw1', 'kw2', 'kw3', 'kw4') |
|
50 |
kwids = map(self.db.add_keyword, kws[:-1]) |
|
51 |
expected_map = { kws[-1]: -1 } |
|
52 |
for kw, id in zip(kws[:-1], kwids): |
|
53 |
expected_map[kw] = id |
|
54 |
kw_map = self.db.map_keywords(kws) |
|
55 |
self.assertEqual(expected_map, kw_map) |
|
65
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
56 |
|
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
57 |
if __name__ == '__main__': |
b975a3d7606a
Partial submission, to include tests.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
58 |
unittest.main() |