def test_02_verify_cache(self):
        # Verify if no entry in cache
        r = verify_in_cache(self.username, self.realm, self.resolver,
                            self.password)
        self.assertFalse(r)

        # Add Entry to cache
        r = add_to_cache(self.username, self.realm, self.resolver,
                         self.password)
        update_cache_last_auth(r)
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        last_auth1 = auth.last_auth

        first_auth = datetime.datetime.utcnow() - datetime.timedelta(hours=4)
        last_auth = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)

        r = verify_in_cache(self.username,
                            self.realm,
                            self.resolver,
                            self.password,
                            first_auth=first_auth,
                            last_auth=last_auth)
        self.assertTrue(r)

        # The last_auth was increased!
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        last_auth2 = auth.last_auth
        self.assertTrue(last_auth2 > last_auth1)
    def test_02_verify_cache(self):
        # Verify if no entry in cache
        r = verify_in_cache(self.username, self.realm, self.resolver,
                            self.password)
        self.assertFalse(r)

        # Add Entry to cache
        r = add_to_cache(self.username, self.realm, self.resolver,
                     auth_hash=self.pw_hash)
        update_cache_last_auth(r)
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        last_auth1 = auth.last_auth

        first_auth = datetime.datetime.utcnow() - datetime.timedelta(hours=4)
        last_auth = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)

        r = verify_in_cache(self.username, self.realm, self.resolver,
                            self.password, first_auth=first_auth,
                            last_auth=last_auth)
        self.assertTrue(r)

        # The last_auth was increased!
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        last_auth2 = auth.last_auth
        self.assertTrue(last_auth2 > last_auth1)
    def test_01_write_update_delete_cache(self):
        teststart = datetime.datetime.utcnow()

        r = add_to_cache(self.username, self.realm, self.resolver,
                         self.password)

        self.assertTrue(r > 0)

        auth = AuthCache.query.filter(AuthCache.id == r).first()
        self.assertEqual(auth.username, self.username)
        self.assertEqual(auth.authentication, _hash_password(self.password))

        self.assertTrue(auth.first_auth > teststart)
        self.assertEqual(auth.last_auth, auth.first_auth)

        update_cache_last_auth(r)
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        self.assertTrue(auth.last_auth > teststart)

        r_delete = delete_from_cache(self.username, self.realm, self.resolver,
                                     self.password)
        self.assertEqual(r, r_delete)

        auth = AuthCache.query.filter(
            AuthCache.username == self.username).first()
        self.assertEqual(auth, None)
    def test_01_write_update_delete_cache(self):
        teststart = datetime.datetime.utcnow()

        r = add_to_cache(self.username, self.realm, self.resolver,
                         auth_hash=self.pw_hash)

        self.assertTrue(r > 0)

        auth = AuthCache.query.filter(AuthCache.id == r).first()
        self.assertEqual(auth.username, self.username)
        self.assertEqual(auth.authentication, self.pw_hash)

        self.assertTrue(auth.first_auth > teststart)
        self.assertEqual(auth.last_auth, None)

        update_cache_last_auth(r)
        auth = AuthCache.query.filter(AuthCache.id == r).first()
        self.assertTrue(auth.last_auth > teststart)

        r_delete = delete_from_cache(self.username, self.realm, self.resolver,
                                     self.pw_hash)
        self.assertEqual(r, r_delete)

        auth = AuthCache.query.filter(AuthCache.username ==
                                      self.username).first()
        self.assertEqual(auth, None)