def test_correct_hash(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_urls("/") mode = 1 @app.route("/") def main(): if mode == 1: return "yay" else: return "yay1" hash, updated = appcache.hash() self.assertEquals(hashlib.sha1("yay").hexdigest(), hash) h, updated_again = appcache.hash() self.assertEquals(updated, updated_again) mode = 2 h, updated_again = appcache.hash() self.assertEquals(hashlib.sha1("yay1").hexdigest(), h) self.assertNotEquals(updated, updated_again)
def test_all_together(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_folder("static") appcache.add_urls("/") appcache.add_urls("/test") @app.route("/") def main(): return "yay" @app.route("/test") def test(): return "yay!!" urls = appcache.urls self.assertEquals(4, len(urls)) self.assertTrue("/" in urls) self.assertTrue("/test" in urls) self.assertTrue("/static/static1.js" in urls) self.assertTrue("/static/static2.css" in urls) # so there is a hash.. hash, updated = appcache.hash() self.assertTrue(hash) self.assertTrue(updated)
def test_finalize(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_urls("/static/static1.js") appcache.finalize() with self.assertRaises(RuntimeError): appcache.add_urls("/") # these exists.. # should never be recomputed. hash, updated = appcache.hash() self.assertTrue(hash) self.assertTrue(updated)