Esempio n. 1
0
class TestGoogleCharts(unittest.TestCase):
    def setUp(self):
        app = Flask(__name__)
        app.debug = True
        self.charts = GoogleCharts(app)
        self.app = app
        self.client = app.test_client()

    def tearDown(self):
        self.app = None

    def test(self):
        assert "GOOGLECHARTS_VERSION" in self.app.config
        assert "charts_init_js" in [
            x.endpoint for x in self.app.url_map.iter_rules()
        ]
        assert "drawCharts()" in self.client.get(
            "/charts.init.js").data.decode("utf8")

    def test_init_app(self):
        with self.assertRaises(TypeError):
            self.charts.init_app(1)

    def test_packages(self):
        chart = BarChart("test01_bar")
        self.charts.register(chart)
        chart = LineChart("test01_line")
        self.charts.register(chart)
        chart1 = MaterialLineChart("test01_mline")
        self.charts.register(chart1)
        assert set(json.loads(self.charts.packages())) == set(
            ["corechart", "line"])

    def test_register(self):
        chart = BarChart("test")
        self.charts.register(chart)
        assert 'test' in self.charts.charts

        chart2 = LineChart("test")
        with self.assertRaises(KeyError):
            self.charts.register(chart2)

        with self.assertRaises(TypeError):
            self.charts.register(1)

    def test_template_variables(self):
        assert self.charts.template_variables() == {}
        self.charts.register(BarChart("test"))
        assert "charts" in self.charts.template_variables()
        assert "test" in self.charts.template_variables()["charts"]
Esempio n. 2
0
from werkzeug.exceptions import default_exceptions, HTTPException, InternalServerError
from werkzeug.security import check_password_hash, generate_password_hash
from datetime import datetime
from flask_googlecharts import GoogleCharts
from flask_googlecharts import PieChart
from flask_sqlalchemy import SQLAlchemy
#import commands

from helpers import apology, login_required, lookup, usd

# Configure application

charts = GoogleCharts()
app = Flask(__name__)
#charts = GoogleCharts(app)
charts.init_app(app)

# Import pie chart and decalre in view

stocks_chart = PieChart("stocks_pie_chart", options={'title': 'Portfolio'})

# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True


# Ensure responses aren't cached
@app.after_request
def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"