def test_multiple_apps(self): app1 = flask.Flask(__name__) babel_ext.Babel(app1, default_locale='de_DE') app2 = flask.Flask(__name__) babel_ext.Babel(app2, default_locale='de_DE') with app1.test_request_context(): assert babel_ext.gettext('Yes') == 'Ja' assert 'de_DE' in app1.extensions["babel"].domain.cache with app2.test_request_context(): assert 'de_DE' not in app2.extensions["babel"].domain.cache
def test_default_domain(self): app = flask.Flask(__name__) domain = babel_ext.Domain(domain='test') babel_ext.Babel(app, default_locale='de_DE', default_domain=domain) with app.test_request_context(): assert babel_ext.gettext('first') == 'erste'
def test_get_timezone_vienna(self): app = flask.Flask(__name__) b = babel_ext.Babel(app) @b.timezoneselector def tz_vienna(): return timezone('Europe/Vienna') with app.test_request_context(): assert babel_ext.get_timezone() == timezone('Europe/Vienna')
def test_convert_timezone(self): app = flask.Flask(__name__) babel_ext.Babel(app) dt = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): dt_utc = babel_ext.to_utc(dt) assert dt_utc.tzinfo is None dt_usertz = babel_ext.to_user_timezone(dt_utc) assert dt_usertz is not None
def test_get_timezone_none(self): assert babel_ext.get_timezone() is None app = flask.Flask(__name__) b = babel_ext.Babel(app) @b.timezoneselector def tz_none(): return None with app.test_request_context(): assert babel_ext.get_timezone() == UTC
def test_get_state(self): # app = None; app.extensions = False; babel = False; silent = True; assert get_state(silent=True) is None app = flask.Flask(__name__) with pytest.raises(RuntimeError): with app.test_request_context(): # app = app; silent = False # babel not in app.extensions get_state() # same as above, just silent with app.test_request_context(): assert get_state(app=app, silent=True) is None babel_ext.Babel(app) with app.test_request_context(): # should use current_app assert get_state(app=None, silent=True) == app.extensions['babel']