示例#1
0
    def test_clear_user_cache_by_time(self):

        # Make some users
        old_account = UserInfo("old_account", "Luke Murphey", ["admin", "power"], 1000)
        old_account2 = UserInfo("old_account2", "Luke Murphey", ["admin", "power"], 2000)

        no_date = UserInfo("no_date", "Luke Murphey", ["admin", "power"])
        new_account = UserInfo("new_account", "Luke Murphey", ["admin", "power"])
        new_account.updateLastLogin()

        old_account.save(self.tmp_dir )
        old_account2.save(self.tmp_dir )
        no_date.save(self.tmp_dir )
        new_account.save(self.tmp_dir )

        # Confirm the number of entries after creation
        self.assertEqual(len(UserInfo.getAllUsers(self.tmp_dir)), 4)

        # Clear the cache
        removed_entries = UserInfo.clearCache(30, self.tmp_dir)
        self.assertEqual(len(removed_entries), 2)

        # Confirm the number of entries after deletion
        users = UserInfo.getAllUsers(self.tmp_dir)
        self.assertEqual(len(users), 2)

        # Clear all entries from the cache
        removed_entries = UserInfo.clearCache(0, self.tmp_dir)
        self.assertEqual(len(removed_entries), 2)

        # Confirm the number of entries after deletion
        users = UserInfo.getAllUsers(self.tmp_dir)
        self.assertEqual(len(users), 0)
示例#2
0
 def test_save_and_load_file(self):
     
     ui_before = UserInfo("lmurphey", "Luke Murphey", ["admin", "power"])
     ui_before.updateLastLogin()
     ui_before.updateLoadSignature()
     
     self.assertTrue(ui_before.save(self.tmp_dir ), "File was not saved properly" )
     
     ui_after = UserInfo.loadFile(os.path.join(self.tmp_dir, "3f0d712f3d3d99e26aa3a45a1f37494c.json") )
     
     self.assertEqual(ui_after.realname, ui_before.realname)
     self.assertEqual(ui_after.username, ui_before.username)
     self.assertEqual(ui_after.roles, ui_before.roles)
     self.assertEqual(ui_after.lastLoginTime, ui_before.lastLoginTime)
     self.assertEqual(ui_after.load_signature, ui_before.load_signature)
示例#3
0
    def test_signature_change_with_login_time(self):
        
        ui = UserInfo("jdoe", "John Doe", ["admin", "power"])
        
        self.assertFalse(ui.hasChanged())
        
        ui.updateLastLogin()

        self.assertTrue(ui.hasChanged())
        ui.updateLoadSignature()
        self.assertFalse(ui.hasChanged())

        # Let the time change a bit by sleeping a bit
        time.sleep(2)
        ui.updateLastLogin()
        self.assertTrue(ui.hasChanged())