Пример #1
0
  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)
Пример #2
0
    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)
Пример #3
0
  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)
Пример #4
0
    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)
Пример #5
0
  def test_route(self):
    app = Flask(__name__)
    appcache = Appcache(app)
    appcache.add_urls("/static/static1.js")

    client = app.test_client()

    response = client.get("/manifest.appcache", follow_redirects=True)
    self.assertEquals(200, response.status_code)
    data = response.data.split("\n")
    self.assertEquals(4, len(data))
    self.assertEquals(hashlib.sha1("Test").hexdigest(), data[1])
    self.assertEquals("/static/static1.js", data[2])
Пример #6
0
    def test_route(self):
        app = Flask(__name__)
        appcache = Appcache(app)
        appcache.add_urls("/static/static1.js")

        client = app.test_client()

        response = client.get("/manifest.appcache", follow_redirects=True)
        self.assertEquals(200, response.status_code)
        data = response.data.split("\n")
        self.assertEquals(4, len(data))
        self.assertEquals(hashlib.sha1("Test").hexdigest(), data[1])
        self.assertEquals("/static/static1.js", data[2])
Пример #7
0
  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)
Пример #8
0
    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)
Пример #9
0
    def test_excluded_urls(self):
        app = Flask(__name__)
        appcache = Appcache(app)

        appcache.add_excluded_urls("/static/develop")
        appcache.add_urls("/static/develop/js.js")
        self.assertEquals(0, len(appcache.urls))

        appcache.add_urls("/static/js.js")
        self.assertEquals(1, len(appcache.urls))

        app = Flask(__name__)
        appcache = Appcache(app)

        appcache.add_excluded_urls("/static/ignored")
        appcache.add_folder("test_ignore", base="/static")
        urls = list(appcache.urls)
        self.assertEquals(1, len(urls))
        self.assertEquals("/static/not_ignored", urls[0])
Пример #10
0
  def test_excluded_urls(self):
    app = Flask(__name__)
    appcache = Appcache(app)

    appcache.add_excluded_urls("/static/develop")
    appcache.add_urls("/static/develop/js.js")
    self.assertEquals(0, len(appcache.urls))

    appcache.add_urls("/static/js.js")
    self.assertEquals(1, len(appcache.urls))

    app = Flask(__name__)
    appcache = Appcache(app)

    appcache.add_excluded_urls("/static/ignored")
    appcache.add_folder("test_ignore", base="/static")
    urls = list(appcache.urls)
    self.assertEquals(1, len(urls))
    self.assertEquals("/static/not_ignored", urls[0])
Пример #11
0
  def test_cache_control(self):
    app = Flask(__name__)
    app.config["DEBUG"] = True
    appcache = Appcache(app)
    appcache.add_urls("/static/static1.js")

    client = app.test_client()
    response = client.get("/static/static1.js", follow_redirects=True)
    self.assertTrue("no-cache" in response.headers["Cache-Control"])
    self.assertTrue("Expires" not in response.headers)

    app = Flask(__name__)
    app.config["DEBUG"] = False
    appcache = Appcache(app)
    appcache.add_urls("/static/static1.js")

    client = app.test_client()
    response = client.get("/static/static1.js", follow_redirects=True)
    self.assertTrue("must-revalidate" in response.headers["Cache-Control"])
    self.assertTrue("Expires" not in response.headers)
Пример #12
0
    def test_cache_control(self):
        app = Flask(__name__)
        app.config["DEBUG"] = True
        appcache = Appcache(app)
        appcache.add_urls("/static/static1.js")

        client = app.test_client()
        response = client.get("/static/static1.js", follow_redirects=True)
        self.assertTrue("no-cache" in response.headers["Cache-Control"])
        self.assertTrue("Expires" not in response.headers)

        app = Flask(__name__)
        app.config["DEBUG"] = False
        appcache = Appcache(app)
        appcache.add_urls("/static/static1.js")

        client = app.test_client()
        response = client.get("/static/static1.js", follow_redirects=True)
        self.assertTrue("must-revalidate" in response.headers["Cache-Control"])
        self.assertTrue("Expires" not in response.headers)
Пример #13
0
                                                  content=content)

# Sets up Appcache
appcache = Appcache(app)
if app.debug:
    appcache.add_excluded_urls('/static/js/app.min.js',
                               '/static/css/app.min.css')
else:
    appcache.add_excluded_urls('/static/js/develop')
    appcache.add_excluded_urls('/static/css/develop')
    appcache.add_excluded_urls('/static/partials')

appcache.add_excluded_urls('/static/js/tests')
appcache.add_excluded_urls('/static/.webassets-cache')
appcache.add_folder('static')
appcache.add_urls('/meta.js', '/')


@app.before_request
def before_request():
    app.jinja_env.globals['partials'] = PARTIALS


@app.route('/manifest.webapp')
def manifest_webapp():
    return send_file('manifest.webapp',
                     mimetype='application/x-web-app-manifest+json')


@app.route('/images')
def images():
Пример #14
0
                                                  content=content)

# Sets up Appcache
appcache = Appcache(app)
if app.debug:
    appcache.add_excluded_urls('/static/js/app.min.js',
                               '/static/css/app.min.css')
else:
    appcache.add_excluded_urls('/static/js/develop')
    appcache.add_excluded_urls('/static/css/develop')
    appcache.add_excluded_urls('/static/partials')

appcache.add_excluded_urls('/static/js/tests')
appcache.add_excluded_urls('/static/.webassets-cache')
appcache.add_folder('static')
appcache.add_urls('/meta.js', '/')


@app.before_request
def before_request():
    app.jinja_env.globals['partials'] = PARTIALS


@app.route('/manifest.webapp')
def manifest_webapp():
    return send_file('manifest.webapp',
                     mimetype='application/x-web-app-manifest+json')


@app.route('/images')
def images():
Пример #15
0
  def test_add_cached_urls(self):
    app = Flask(__name__)
    appcache = Appcache(app)

    appcache.add_urls("/")
    self.assertTrue("/" in appcache.urls)
Пример #16
0
    def test_add_cached_urls(self):
        app = Flask(__name__)
        appcache = Appcache(app)

        appcache.add_urls("/")
        self.assertTrue("/" in appcache.urls)
            else:
                tuner.power_off()
                logger.info("  tuner off {}")

    return str(status)


def exit_handler():
    print('Flask is exiting')
    mqttc.loop_stop()
    if os.uname()[4].startswith("arm"):
        print('cleanup')
        GPIO.cleanup()


appcache.add_urls("/")
appcache.add_folder(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static'), base="/static")

mqttc = mosquitto.Mosquitto()
mosquittoHandler = MosquittoHandler(projector, tuner)
mqttc.on_message = mosquittoHandler.on_message
mqttc.on_connect = mosquittoHandler.on_connect
mqttc.connect("127.0.0.1", 1883, 60)

if __name__ == '__main__':
    # app.run()

    atexit.register(exit_handler)
    port = 5000
    if os.uname()[4].startswith("arm"):
        port = 80