Ejemplo n.º 1
0
def test_false_input(client):
    """ testing false input for raise coverage """
    try:
        Minify(app=None)
    except Exception as e:
        assert type(e) is AttributeError
    try:
        Minify(app, "nothing", "nothing")
    except Exception as e:
        assert type(e) is TypeError
Ejemplo n.º 2
0
async def test_fail_safe_false_input(client):
    """testing fail safe disabled with false input """
    Minify(app=app, fail_safe=False, cache=False)
    try:
        await client.get("/cssless_false")
    except Exception as e:
        assert "CompilationError" == e.__class__.__name__
Ejemplo n.º 3
0
async def test_javascript_minify(client):
    """ testing JavaScript minify option """
    Minify(app=app, html=False, cssless=False, js=True)

    resp = await client.get("/js")
    data = await resp.get_data()

    assert b'<script>["J","S"].reduce(function(a,r){return a+r})</script>' == data
Ejemplo n.º 4
0
async def test_html_minify(client):
    """ testing HTML minify option """
    Minify(app=app, html=True, cssless=False, js=False)

    resp = await client.get("/html")
    data = await resp.get_data()

    assert b"<html> <body> <h1> HTML </h1> </body> </html>" == data
Ejemplo n.º 5
0
async def test_html_bypassing(client):
    """ testing HTML route bypassing """
    Minify(app=app, html=True, cssless=False, js=False, bypass=["/html"])

    resp = await client.get("/html")
    data = await resp.get_data()

    assert b"<html> <body> <h1> HTML </h1> </body> </html>" != data
Ejemplo n.º 6
0
async def test_lesscss_minify(client):
    """ testing css and less minify option """
    Minify(app=app, html=False, cssless=True, js=False)

    resp = await client.get("/cssless")
    data = await resp.get_data()

    assert b"<style>body{color:red;}</style>" == data
Ejemplo n.º 7
0
async def test_fail_safe(client):
    """ testing fail safe enabled with false input """
    Minify(app=app, fail_safe=True)

    resp = await client.get("/cssless_false")
    data = await resp.get_data()

    assert (b"""<style>
        body {
            color: red;;
        }
    </style>""" == data)
Ejemplo n.º 8
0
async def test_minify_cache(client):
    """ testing caching minifed response """
    minify_store = Minify(app=app, js=False, cssless=True, cache=True)

    first_resp = await client.get("/cssless")
    # to cover hashing return
    first_resp_data = await first_resp.get_data()  # noqa: F841

    resp = await client.get("/cssless")
    second_resp_data = await resp.get_data()

    assert (second_resp_data.decode("utf8").replace("<style>", "").replace(
        "</style>", "") in minify_store.history.values())
Ejemplo n.º 9
0
"""Web controller for motorized screen"""
import asyncio
import logging

import redis
from quart import Quart, request, jsonify, render_template
from quart_minify.minify import Minify

from screen import MotorizedScreen

app = Quart(__name__)
Minify(app=app)
logging.basicConfig(format="[%(asctime)s] %(message)s", level=logging.INFO)

SCREEN = MotorizedScreen()


@app.route("/")
async def _landing():  # pylint: disable=unused-variable
    """Landing Page"""
    moving = SCREEN.running_task is not None
    if moving:
        status = "moving"
    else:
        remote_state = redis.Redis(host='localhost', port=6379,
                                   db=0).get("state")
        status = remote_state.decode("utf-8")
    template = await render_template("index.html", status=status)
    return template