Skip to content

Commit ff021ca

Browse files
committed
Fix test failure when run alone.
testPasswordMigration was failing when run pytest -k testPasswordMigration. Was always failing on third test. When run as part of whole FormTestCase class it worked. Fixed it by: Using cl.db after call to actions.LoginAction. Make sure to set cl.db.Otk = self.db.Otk before calling LoginAction. Add real Otk database and not a mock to a couple of db's. Without this the third element in the loop (crypt at this point) still has the old vale when eading from db. I think this is due to the original cl.db being closed inside LoginAction (to re-open db using new user's credentials cl.db.ptimize is not set). I think the old self.db is returning the cached values. At least that's my guess.
1 parent 906f6bc commit ff021ca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/test_cgi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,16 +575,17 @@ def testPasswordMigration(self):
575575
self.db.user.set(chef, password=pw1)
576576
self.db.commit()
577577
actions.LoginAction(cl).handle()
578-
pw = self.db.user.get(chef, 'password')
578+
pw = cl.db.user.get(chef, 'password')
579579
print(pw)
580580
self.assertEqual(pw, 'foo')
581581
self.assertEqual(pw.needs_migration(), False)
582+
cl.db.Otk = self.db.Otk
582583
pw1 = pw
583584
self.assertEqual(pw1.needs_migration(), False)
584585
scheme = password.Password.known_schemes[0]
585586
self.assertEqual(scheme, pw1.scheme)
586587
actions.LoginAction(cl).handle()
587-
pw = self.db.user.get(chef, 'password')
588+
pw = cl.db.user.get(chef, 'password')
588589
self.assertEqual(pw, 'foo')
589590
self.assertEqual(pw, pw1)
590591
cl.db.close()
@@ -1888,6 +1889,7 @@ def _make_client(self, form, classname='user', nodeid='1',
18881889
if nodeid is not None:
18891890
cl.nodeid = nodeid
18901891
cl.db = self.db
1892+
cl.db.Otk = cl.db.getOTKManager()
18911893
#cl.db.Otk = MockNull()
18921894
#cl.db.Otk.data = {}
18931895
#cl.db.Otk.getall = self.data_get
@@ -3056,6 +3058,7 @@ def _make_client(self, form, classname='user', nodeid='1',
30563058
if nodeid is not None:
30573059
cl.nodeid = nodeid
30583060
cl.db = self.db
3061+
cl.db.Otk = cl.db.getOTKManager()
30593062
#cl.db.Otk = MockNull()
30603063
#cl.db.Otk.data = {}
30613064
#cl.db.Otk.getall = self.data_get

0 commit comments

Comments
 (0)