def test_app_with_template(self): from empty import app_factory, Empty app = app_factory('some-name', None, template_folder="templates") home_env = os.getenv('HOME') self.assertTrue(isinstance(app, Empty)) self.assertTrue(home_env in app.template_folder) self.assertTrue('templates' in app.template_folder)
def test_date_output_format(self): app = app_factory( 'myapp', EmptyConfig(), base_application=EmptyWithDateFilter) today = date(year=2015, month=10, day=5) with app.app_context(): text = render_template_string("{{today|date}}", today=today) assert text == "2015/10/05"
def test_date_filter(): from datetime import date from flask import render_template_string today = date(year=2015, month=10, day=5) app = app_factory(object, 'myapp') with app.app_context(): text = render_template_string("{{today|date}}", today=today) assert text == "2015/10/05"
def test_datetime_filter(): from datetime import datetime from flask import render_template_string now = datetime(year=2015, month=10, day=5, hour=5, minute=8, second=10) app = app_factory(object, 'myapp') with app.app_context(): text = render_template_string("{{now|datetime}}", now=now) assert text == "2015/10/05 05:08"
def test_date_output_with_settings(self): from datetime import date today = date(year=2015, month=10, day=5) app = app_factory( 'myapp', EmptyConfig(date_format='%d/%m/%Y'), base_application=EmptyWithDateFilter) with app.app_context(): text = render_template_string("{{today|date}}", today=today) assert text == "05/10/2015"
def test_datetime_filter_with_settings(): from datetime import datetime from flask import render_template_string class Config: DATETIME_FORMAT = '%d/%m/%Y %H:%M' now = datetime(year=2015, month=10, day=5, hour=5, minute=8, second=10) app = app_factory(Config, 'myapp') with app.app_context(): text = render_template_string("{{now|datetime}}", now=now) assert text == "05/10/2015 05:08"
def test_date_filter_with_settings(): from datetime import date from flask import render_template_string class Config: DATE_FORMAT = '%d/%m/%Y' today = date(year=2015, month=10, day=5) app = app_factory(Config, 'myapp') with app.app_context(): text = render_template_string("{{today|date}}", today=today) assert text == "05/10/2015"
def test_datetime_filter_with_settings(self): now = datetime( year=2015, month=10, day=5, hour=5, minute=8, second=10) app = app_factory( 'myapp', EmptyConfig(datetime_format='%d/%m/%Y %H:%M'), base_application=EmptyWithDatetimeFilter) with app.app_context(): text = render_template_string("{{now|datetime}}", now=now) assert text == "05/10/2015 05:08"
def test_datetime_output_format(self): app = app_factory( 'myapp', EmptyConfig(), base_application=EmptyWithDatetimeFilter) now = datetime( year=2015, month=10, day=5, hour=5, minute=8, second=10 ) with app.app_context(): text = render_template_string("{{now|datetime}}", now=now) assert text == "2015/10/05 05:08"
from empty import app_factory from main import App import config import traceback import logging try: # SPA setup; template_folder ignored; app = app_factory('app', config, template_folder=None, base_application=App) except Exception as e: logging.error(traceback.format_exc()) raise e
from empty import EmptyConfig from empty import app_factory app = app_factory('myapp', EmptyConfig())
def test_app_without_template(self): from empty import app_factory, Empty app = app_factory('some-name', None, template_folder=None) self.assertTrue(isinstance(app, Empty)) self.assertEqual(app.template_folder, None)
from empty import app_factory class Config: pass app = app_factory(Config, 'myapp')