Source

flask-creole-main / tests / test_creole.py

Full commit

from flask import Flask, render_template_string

from flaskext.creole import Creole_CP, Creole_PC

markup = u'This is **creole //markup//**'
macro_markup = "<<hello some_arg='ali'>>"
html = u'<p>This is <strong>creole <em>markup</em></strong></p>\n'
html_pc = u'<p>This is <strong>creole <i>markup</i></strong></p>\n'
macro_html = '<p>Hello World ali</p>\n'


def create_client(Creole):
    app = Flask(__name__)
    app.debug = True
    creole = Creole(app)

    @app.route('/c2h')
    def view_creole2html():
        return render_template_string('{{ markup|creole2html }}', markup=markup)

    @app.route('/h2c')
    def view_html2creole():
        return render_template_string('{{ html|html2creole }}', html=html_pc)

    @app.route('/m')
    def view_creole_macro():
        return render_template_string('{{ markup|creole2html }}',
                                      markup=macro_markup)

    if hasattr(creole, 'macro'):
        @creole.macro
        def hello(name, environ, body, is_block, some_arg):
            return 'Hello World %s' % (some_arg)

    return app.test_client()


def test_creole_to_html_cp():
    client = create_client(Creole_CP)
    resp = client.open('/c2h')
    assert resp.data == html

def test_creole_to_html_pc():
    client = create_client(Creole_PC)
    resp = client.open('/c2h')
    assert resp.data == html_pc

def test_html_to_creole():
    client = create_client(Creole_PC)
    resp = client.open('/h2c')
    assert resp.data == markup

def test_macro():
    client = create_client(Creole_CP)
    resp = client.open('/m')
    assert resp.data == macro_html