comparison test/test_cgi.py @ 7164:5487882ff17a

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.
author John Rouillard <rouilj@ieee.org>
date Fri, 24 Feb 2023 17:15:29 -0500
parents ed63b6d35838
children 1549c7e74ef8
comparison
equal deleted inserted replaced
7163:0b52ee664580 7164:5487882ff17a
573 print(pw1) 573 print(pw1)
574 self.assertEqual(pw1.needs_migration(), True) 574 self.assertEqual(pw1.needs_migration(), True)
575 self.db.user.set(chef, password=pw1) 575 self.db.user.set(chef, password=pw1)
576 self.db.commit() 576 self.db.commit()
577 actions.LoginAction(cl).handle() 577 actions.LoginAction(cl).handle()
578 pw = self.db.user.get(chef, 'password') 578 pw = cl.db.user.get(chef, 'password')
579 print(pw) 579 print(pw)
580 self.assertEqual(pw, 'foo') 580 self.assertEqual(pw, 'foo')
581 self.assertEqual(pw.needs_migration(), False) 581 self.assertEqual(pw.needs_migration(), False)
582 cl.db.Otk = self.db.Otk
582 pw1 = pw 583 pw1 = pw
583 self.assertEqual(pw1.needs_migration(), False) 584 self.assertEqual(pw1.needs_migration(), False)
584 scheme = password.Password.known_schemes[0] 585 scheme = password.Password.known_schemes[0]
585 self.assertEqual(scheme, pw1.scheme) 586 self.assertEqual(scheme, pw1.scheme)
586 actions.LoginAction(cl).handle() 587 actions.LoginAction(cl).handle()
587 pw = self.db.user.get(chef, 'password') 588 pw = cl.db.user.get(chef, 'password')
588 self.assertEqual(pw, 'foo') 589 self.assertEqual(pw, 'foo')
589 self.assertEqual(pw, pw1) 590 self.assertEqual(pw, pw1)
590 cl.db.close() 591 cl.db.close()
591 592
592 def testPasswordConfigOption(self): 593 def testPasswordConfigOption(self):
1886 'REQUEST_METHOD':'POST'}, db_test_base.makeForm(form)) 1887 'REQUEST_METHOD':'POST'}, db_test_base.makeForm(form))
1887 cl.classname = classname 1888 cl.classname = classname
1888 if nodeid is not None: 1889 if nodeid is not None:
1889 cl.nodeid = nodeid 1890 cl.nodeid = nodeid
1890 cl.db = self.db 1891 cl.db = self.db
1892 cl.db.Otk = cl.db.getOTKManager()
1891 #cl.db.Otk = MockNull() 1893 #cl.db.Otk = MockNull()
1892 #cl.db.Otk.data = {} 1894 #cl.db.Otk.data = {}
1893 #cl.db.Otk.getall = self.data_get 1895 #cl.db.Otk.getall = self.data_get
1894 #cl.db.Otk.set = self.data_set 1896 #cl.db.Otk.set = self.data_set
1895 cl.userid = userid 1897 cl.userid = userid
3054 'REQUEST_METHOD':'POST'}, db_test_base.makeForm(form)) 3056 'REQUEST_METHOD':'POST'}, db_test_base.makeForm(form))
3055 cl.classname = classname 3057 cl.classname = classname
3056 if nodeid is not None: 3058 if nodeid is not None:
3057 cl.nodeid = nodeid 3059 cl.nodeid = nodeid
3058 cl.db = self.db 3060 cl.db = self.db
3061 cl.db.Otk = cl.db.getOTKManager()
3059 #cl.db.Otk = MockNull() 3062 #cl.db.Otk = MockNull()
3060 #cl.db.Otk.data = {} 3063 #cl.db.Otk.data = {}
3061 #cl.db.Otk.getall = self.data_get 3064 #cl.db.Otk.getall = self.data_get
3062 #cl.db.Otk.set = self.data_set 3065 #cl.db.Otk.set = self.data_set
3063 cl.userid = userid 3066 cl.userid = userid

Roundup Issue Tracker: http://roundup-tracker.org/