Example #1
0
def test_default_theme_render_macro_jade():
    webconfig.init_theme()
    ctx = {"macro_arg": "testvalue"}
    with app.test_request_context():
        html = webconfig.theme.render_macro("test.j2.jade", "testmacro", ctx)
    assert "macro_arg: testvalue" in html
    assert "macro_kwarg: default" in html
Example #2
0
def test_default_theme_render_macro_jade():
    webconfig.init_theme()
    ctx = {"macro_arg": "testvalue"}
    with app.test_request_context():
        html = webconfig.theme.render_macro("test.j2.jade", "testmacro", ctx)
    assert "macro_arg: testvalue" in html
    assert "macro_kwarg: default" in html
Example #3
0
def test_default_theme_render_template_jade():
    webconfig.init_theme()
    ctx = {"ctx_variable": "testvalue"}
    with app.test_request_context():
        html = webconfig.theme.render_template("test.j2.jade", ctx)
    assert "<html>" in html
    assert "testvalue" in html
Example #4
0
def test_default_theme_render_template_jade():
    webconfig.init_theme()
    ctx = {"ctx_variable": "testvalue"}
    with app.test_request_context():
        html = webconfig.theme.render_template("test.j2.jade", ctx)
    assert "<html>" in html
    assert "testvalue" in html
Example #5
0
def scheduled_tasks():

	ctx = app.test_request_context()
	ctx.push()


	now = datetime.now(timezone(app.config['TIMEZONE'])).replace(second=0, microsecond=0)

	tasks = ScheduledTask.list({'is_online': True})
	for task in tasks:
		
		if task['frequency'] == 'day':
			if task['frequency_hour'] == now.hour and task['frequency_minute'] == now.minute:
				execute_task.apply_async((task,), countdown=0)

		else:
			created_at = task['created_at'].replace(second=0, microsecond=0, tzinfo=now.tzinfo)

			if task['frequency'] == 'week':
				rule = rrule(WEEKLY, interval=task['frequency_count'], byminute=task['frequency_minute'], byhour=task['frequency_hour'], byweekday=task['frequency_day'], dtstart=created_at, until=now)

			elif task['frequency'] == 'month':
				rule = rrule(MONTHLY, interval=task['frequency_count'], byminute=task['frequency_minute'], byhour=task['frequency_hour'], bymonthday=task['frequency_day'], dtstart=created_at, until=now)

			elif task['frequency'] == 'year':
				rule = rrule(YEARLY, interval=task['frequency_count'], byminute=task['frequency_minute'], byhour=task['frequency_hour'], byyearday=task['frequency_day'], dtstart=created_at, until=now)


			if now in rule:
				execute_task.apply_async((task,), countdown=0)
Example #6
0
def test_default_theme_render_template_jade_without_extension_fail():
    webconfig.init_theme()
    ctx = {}
    with raises(TemplateNotFound) as excinfo:
        with app.test_request_context():
            webconfig.theme.render_template("test", ctx)
            
    assert "invalid" in excinfo.value.message
Example #7
0
def test_login_no_referer(req):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    with app.test_request_context():
        assert login.login(req) == 200
        assert req.session["return_after_login"] is False
Example #8
0
def test_login_no_referer(req):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    with app.test_request_context():
        assert login.login(req) == 200
        assert req.session["return_after_login"] is False
Example #9
0
def test_default_theme_render_macro_jade_without_extension_fail():
    webconfig.init_theme()
    ctx = {}
    with raises(TemplateNotFound) as excinfo:
        with app.test_request_context():
            webconfig.theme.render_macro("test", "testmacro", ctx)

    assert "invalid" in excinfo.value.message
Example #10
0
def test_login_login_from_edit(req):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    req.headers["Referer"] = "http://localhost/edit/edit_content?id=604993"
    req.headers["Host"] = "localhost"
    with app.test_request_context():
        assert login.login(req) == 200
        assert req.session["return_after_login"] == "http://localhost/edit?id=604993"
Example #11
0
def test_login_from_other(req):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    ref = "http://localhost/justatest"
    req.headers["Host"] = "localhost"
    req.headers["Referer"] = ref
    with app.test_request_context():
        assert login.login(req) == 200
        assert req.session["return_after_login"] == ref
Example #12
0
def trigger_tasks(trigger_code, data={}):

    ctx = app.test_request_context()
    ctx.push()

    tasks = TriggeredTask.list({
        'is_online': True,
        'trigger_code': trigger_code
    })
    for task in tasks:
        execute_task.apply_async((task, data), countdown=0)
Example #13
0
def test_pwdchange(pwdchange_patch, req, session, collections):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    add_template_globals()
    req.form["ChangeSubmit"] = True
    req.form["user"] = LOGIN_NAME
    req.form["password_old"] = PASSWORD
    req.form["password_new1"] = NEW_PASSWORD
    req.form["password_new2"] = NEW_PASSWORD_REPEATED
    with app.test_request_context():
        assert login.pwdchange(req) == pwdchange_patch
Example #14
0
def test_pwdchange(pwdchange_patch, req, session, collections):
    from core.webconfig import init_theme, add_template_globals
    from core import webconfig
    init_theme()
    webconfig.theme.make_jinja_loader()
    add_template_globals()
    req.form["ChangeSubmit"] = True
    req.form["user"] = LOGIN_NAME
    req.form["password_old"] = PASSWORD
    req.form["password_new1"] = NEW_PASSWORD
    req.form["password_new2"] = NEW_PASSWORD_REPEATED
    with app.test_request_context():
        assert login.pwdchange(req) == pwdchange_patch
Example #15
0
from core import app

app.config.from_object('core.config.TestingConfig')

ctx = app.test_request_context('/')
ctx.push()

import tests.word_test
from core import app, db, connection

import pymongo
from pymongo.database import Database

app.config.from_object('core.config.TestingConfig')
"""
Load test database
"""
db = Database(connection, app.config["MONGODB_DATABASE"])

ctx = app.test_request_context('/')
ctx.push()

import tests.model_tests
Example #17
0
def execute_task(task, data={}):

    ctx = app.test_request_context()
    ctx.push()

    compiler = Compiler()

    try:
        if task['needs_users']:
            from core.models.auth.user import User
            data['users'] = User.list()
    except KeyError:
        pass

    try:
        if task['has_email']:
            subject_template = compiler.compile(task['email_subject'])
            recipients_template = compiler.compile(task['email_to'])

            mandrill = Mandrill(app.config['MANDRILL_API_KEY'])
            body_template = compiler.compile(
                mandrill.templates.info(name=task['email_template'])['code'])

            message = mandrill.messages.send(message={
                'from_email':
                app.config['MANDRILL_FROM_EMAIL'],
                'from_name':
                app.config['MANDRILL_FROM_NAME'],
                'subject':
                subject_template(data),
                'html':
                body_template(data),
                'inline_css':
                True,
                'to': [{
                    'email': recipients_template(data),
                    'type': 'to'
                }]
            },
                                             async=False)

            print(message)

            # body_template = compiler.compile(task['email_body'])

            # message = Message(subject_template(data),
            # 	sender=sender_template(data),
            # 	recipients=recipients_template(data).split(','))
            # message.html = body_template(data)

            # app.mail.send(message)

    except KeyError:
        pass

    try:
        if task['has_webhook']:
            body_template = compiler.compile(task['webhook_body'])

            response = requests.request(task['webhook_method'].lower(),
                                        task['webhook_url'],
                                        data=body_template(data),
                                        headers=task['webhook_headers'])

    except KeyError:
        pass