def test_token_delete_expire2(self): now = 30000 with open(os.path.join(self.token_dir, 'sampleToken1'), 'w', encoding='UTF-8') as f: f.write(str(29000)) with open(os.path.join(self.token_dir, 'sampleToken2'), 'w', encoding='UTF-8') as f: f.write(str(29100)) with open(os.path.join(self.token_dir, 'sampleToken3'), 'w', encoding='UTF-8') as f: f.write(str(30100)) with open(os.path.join(self.token_dir, 'sampleToken4'), 'w', encoding='UTF-8') as f: f.write(str(30500)) handler = wsbapp.WebHost(self.test_dir) handler.token_delete_expire(now) self.assertFalse( os.path.exists(os.path.join(self.token_dir, 'sampleToken1'))) self.assertFalse( os.path.exists(os.path.join(self.token_dir, 'sampleToken2'))) self.assertTrue( os.path.exists(os.path.join(self.token_dir, 'sampleToken3'))) self.assertTrue( os.path.exists(os.path.join(self.token_dir, 'sampleToken4')))
def test_token_delete_expire1(self): now = int(time.time()) with open(os.path.join(self.token_dir, 'sampleToken1'), 'w', encoding='UTF-8') as f: f.write(str(now - 100)) with open(os.path.join(self.token_dir, 'sampleToken2'), 'w', encoding='UTF-8') as f: f.write(str(now - 10)) with open(os.path.join(self.token_dir, 'sampleToken3'), 'w', encoding='UTF-8') as f: f.write(str(now + 10)) with open(os.path.join(self.token_dir, 'sampleToken4'), 'w', encoding='UTF-8') as f: f.write(str(now + 100)) handler = wsbapp.WebHost(self.test_dir) handler.token_delete_expire() self.assertFalse( os.path.exists(os.path.join(self.token_dir, 'sampleToken1'))) self.assertFalse( os.path.exists(os.path.join(self.token_dir, 'sampleToken2'))) self.assertTrue( os.path.exists(os.path.join(self.token_dir, 'sampleToken3'))) self.assertTrue( os.path.exists(os.path.join(self.token_dir, 'sampleToken4')))
def test_token_check_delete_expire5(self, mock_delete): now = 40000 handler = wsbapp.WebHost(self.test_dir) handler.token_last_purge = now - 900 handler.token_check_delete_expire(now) mock_delete.assert_not_called() self.assertEqual(handler.token_last_purge, now - 900)
def test_token_check_delete_expire4(self, mock_delete): now = 40000 handler = wsbapp.WebHost(self.test_dir) handler.token_last_purge = now - 1100 handler.token_check_delete_expire(now) self.assertAlmostEqual(mock_delete.call_args[0][0], now, delta=1) self.assertAlmostEqual(handler.token_last_purge, now, delta=1)
def test_token_check_delete_expire1(self, mock_delete): now = int(time.time()) handler = wsbapp.WebHost(self.test_dir) self.assertEqual(handler.token_last_purge, 0) handler.token_check_delete_expire() self.assertAlmostEqual(mock_delete.call_args[0][0], now, delta=1) self.assertAlmostEqual(handler.token_last_purge, now, delta=1)
def test_token_delete(self): token = 'sampleToken' token_file = os.path.join(self.token_dir, token) with open(token_file, 'w', encoding='UTF-8') as f: f.write(str(32768)) handler = wsbapp.WebHost(self.test_dir) handler.token_delete(token) self.assertFalse(os.path.exists(token_file))
def test_token_validate2(self): token = 'sampleToken' token_time = int(time.time()) - 3 token_file = os.path.join(self.token_dir, token) with open(token_file, 'w', encoding='UTF-8') as f: f.write(str(token_time)) handler = wsbapp.WebHost(self.test_dir) self.assertFalse(handler.token_validate(token))
def test_token_validate4(self): token = 'sampleToken' now = 30000 token_time = 29999 token_file = os.path.join(self.token_dir, token) with open(token_file, 'w', encoding='UTF-8') as f: f.write(str(token_time)) handler = wsbapp.WebHost(self.test_dir) self.assertFalse(handler.token_validate(token, now))
def test_token_acquire2(self, mock_check): now = 30000 expected_expire_time = int(now) + 30 handler = wsbapp.WebHost(self.test_dir) token = handler.token_acquire(now) token_file = os.path.join(self.token_dir, token) self.assertTrue(os.path.isfile(token_file)) with open(token_file, 'r', encoding='UTF-8') as f: self.assertEqual(int(f.read()), expected_expire_time) self.assertEqual(mock_check.call_args[0][0], now)