def test_06_implicit_cache_population(self): self._create_realm() # testing `get_username` self.assertEquals(UserCache.query.count(), 0) # the cache is empty, so the username is read from the resolver u_name = get_username(self.uid, self.resolvername1) self.assertEqual(self.username, u_name) # it should be part of the cache now r = UserCache.query.filter( UserCache.user_id == self.uid, UserCache.resolver == self.resolvername1).one() self.assertEqual(self.username, r.username) # Apart from that, the cache should be empty. self.assertEqual(UserCache.query.count(), 1) r = delete_user_cache() # testing `User()`, but this time we add an already-expired entry to the cache self.assertEquals(UserCache.query.count(), 0) UserCache(self.username, self.username, self.resolvername1, 'fake_uid', datetime.now() - timedelta(weeks=50)).save() # cache contains an expired entry, uid is read from the resolver (we can verify # that the cache entry is indeed not queried as it contains 'fake_uid' instead of the correct uid) user = User(self.username, self.realm1, self.resolvername1) self.assertEqual(user.uid, self.uid) # a new entry should have been added to the cache now r = retrieve_latest_entry((UserCache.username == self.username) & (UserCache.resolver == self.resolvername1)) self.assertEqual(self.uid, r.user_id) # But the expired entry is also still in the cache self.assertEqual(UserCache.query.count(), 2) r = delete_user_cache() self._delete_realm()
def test_06_implicit_cache_population(self): self._create_realm() # testing `get_username` self.assertEquals(UserCache.query.count(), 0) # the cache is empty, so the username is read from the resolver u_name = get_username(self.uid, self.resolvername1) self.assertEqual(self.username, u_name) # it should be part of the cache now r = UserCache.query.filter(UserCache.user_id == self.uid, UserCache.resolver == self.resolvername1).one() self.assertEqual(self.username, r.username) # Apart from that, the cache should be empty. self.assertEqual(UserCache.query.count(), 1) r = delete_user_cache() # testing `User()`, but this time we add an already-expired entry to the cache self.assertEquals(UserCache.query.count(), 0) UserCache(self.username, self.resolvername1, 'fake_uid', datetime.now() - timedelta(weeks=50)).save() # cache contains an expired entry, uid is read from the resolver (we can verify # that the cache entry is indeed not queried as it contains 'fake_uid' instead of the correct uid) user = User(self.username, self.realm1, self.resolvername1) self.assertEqual(user.uid, self.uid) # a new entry should have been added to the cache now r = retrieve_latest_entry((UserCache.username == self.username) & (UserCache.resolver == self.resolvername1)) self.assertEqual(self.uid, r.user_id) # But the expired entry is also still in the cache self.assertEqual(UserCache.query.count(), 2) r = delete_user_cache() self._delete_realm()