Beispiel #1
0
from urllib.parse import urlencode
import json

# Third-party imports
# -------------------
import pytest
from flask import url_for

# Local imports
# -------------
from runestone import create_app

# Tests
# =====
# Create a testing application.
app = create_app('testing')


# Utilities
# ---------
# Create a URL based on a prefix (defined by a blueprint), an optional string (appended to the prefix), and any arguments (as keywords) to accompany a GET or POST request.
def url_joiner(url_prefix, _str, **kwargs):
    return '?'.join((url_prefix + '/' + _str, urlencode(dict(kwargs))))


# Define a `context manger <https://docs.python.org/3/reference/datamodel.html#context-managers>`_ which sandwiches its body with a ``login``/``logout``.
class LoginContext:
    def __init__(self, test_class, username, *args):
        self.test_class = test_class
        self.username = username
        self.args = args
Beispiel #2
0
#!/usr/bin/env python

import os
from runestone import create_app, db
from runestone.model import Course, LogInfo
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context():
    return dict(app=app, db=db, Course=Course, LogInfo=LogInfo)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
Beispiel #3
0
# Standard library
# ----------------
import os

# Third-party imports
# -------------------
# None.

# Local imports
# -------------
from runestone import create_app, db
from runestone.model import AuthUser

# Create application
# ==================
app = create_app(os.getenv('FLASK_CONFIG') or 'development')


# TODO: This is duplicated in `tests/conftest.py`. Factor it out.
def make_user(app, username, password):
    u = AuthUser[username].q
    if not u.count():
        user = AuthUser(
            username=username,
            password=app.user_manager.hash_password(password),
            active=True,
        )
        db.session.add(user)
        db.session.commit()
    else:
        user = u.one()