Exemple #1
0
    def test_theme_include_static(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            data = render_template('static_parent.html').strip()
            url = static_file_url('plain', 'style.css')
            assert data == 'Application, Plain, %s' % url
Exemple #2
0
    def test_theme_static(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            coolurl = static_file_url('cool', 'style.css')
            cooldata = render_theme_template('cool', 'static.html').strip()
            assert cooldata == 'Cool Blue v2, %s' % coolurl
Exemple #3
0
    def test_template_exists(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            assert template_exists('hello.html')
            assert template_exists('_themes/cool/hello.html')
            assert not template_exists('_themes/plain/hello.html')
Exemple #4
0
    def test_render_theme_template(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            coolsrc = render_theme_template('cool', 'hello.html').strip()
            plainsrc = render_theme_template('plain', 'hello.html').strip()
            assert coolsrc == 'Hello from Cool Blue v2.'
            assert plainsrc == 'Hello from the application'
Exemple #5
0
    def test_static_file_url(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            url = static_file_url('cool', 'style.css')
            genurl = url_for('_themes.static', themeid='cool',
                             filename='style.css')
            assert url == genurl
Exemple #6
0
    def test_setup_themes(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        assert hasattr(app, 'theme_manager')
        if USING_BLUEPRINTS:
            assert '_themes' in app.blueprints
        else:
            assert '_themes' in app.modules
        assert 'theme' in app.jinja_env.globals
        assert 'theme_static' in app.jinja_env.globals
Exemple #7
0
    def test_active_theme(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            appdata = render_template('active.html').strip()
            cooldata = render_theme_template('cool', 'active.html').strip()
            plaindata = render_theme_template('plain', 'active.html').strip()
            assert appdata == 'Application, Active theme: none'
            assert cooldata == 'Cool Blue v2, Active theme: cool'
            assert plaindata == 'Application, Active theme: plain'
Exemple #8
0
    def test_theme_static_outside(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            try:
                render_template('static.html')
            except RuntimeError:
                pass
            else:
                raise AssertionError("Rendering static.html should have "
                                     "caused a RuntimeError")
Exemple #9
0
    def test_loader(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            if USING_BLUEPRINTS:
                src = themes_blueprint.jinja_loader.get_source(
                    app.jinja_env, '_themes/cool/hello.html'
                )
            else:
                src = themes_mod.jinja_loader.get_source(
                    app.jinja_env, 'cool/hello.html'
                )
            assert src[0].strip() == 'Hello from Cool Blue v2.'
Exemple #10
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        setup_themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raised KeyError")
Exemple #11
0
from flask import (Flask, url_for, redirect, session, Markup, abort)
from spirits import (setup_themes, render_theme_template,
                             get_themes_list)
from operator import attrgetter

# default settings

DEFAULT_THEME = 'calmblue'
SECRET_KEY = 'not really secret'


# application

app = Flask(__name__)
app.config.from_object(__name__)
setup_themes(app, app_identifier='themesandbox')


# data

class Post(object):
    def __init__(self, data):
        self.slug = data['slug']
        self.body = data['body']
        self.title = data['title']
        self.created = data['created']
    
    @property
    def content(self):
        return Markup('\n\n'.join(
            '<p>%s</p>' % line for line in self.body.splitlines()