示例#1
0
def db(test_client, non_admin_user, admin_user, unconfirmed_user):
    """
    creates and returns the initial testing database
    """
    # Create the database and the database table
    _db.app = test_client
    _db.create_all()

    # Insert admin, non admin, and unconfirmed
    _db.session.add(non_admin_user)
    _db.session.add(admin_user)
    _db.session.add(unconfirmed_user)

    # add the default settings
    with open("config.json", "r") as config:
        config = json.load(config)
    for name, value in config["settings"].items():
        s = Settings(setting=name, value=value)
        _db.session.add(s)

    # Commit the changes for the users
    _db.session.commit()

    yield _db  # this is where the testing happens!

    _db.drop_all()
示例#2
0
    def tearDown(self):
        """teardown all initialized variables."""
        self.driver.quit()

        with self.app.app_context():
            # drop all tables
            db.session.remove()
            db.drop_all()
示例#3
0
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    password = db.Column(db.String(120))

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def as_dict(self):
        return {
            col.name: getattr(self, col.name)
            for col in self.__table__.columns
        }


db.drop_all()
db.create_all()
for calc_type in ["add", "minus"]:
    db.session.add(
        Rule(
            calc_type, "A1", "多退少补法 - 自左向右计算", "\
    例子: 58 + 65 = ?<br><br>\
    1. 5 + 6 = 11,<br><br> \
    2. 8 + 5 = 13, 因为大于10, 所以前面的 11 加 1,得 12,再取 13 的个位数 3,<br><br>\
    结果是 58 + 65 = 123\
    "))
for calc_type in ["multiply", "divide"]:
    db.session.add(
        Rule(
            calc_type, "M1", "两位数 * 一位数", "\
    例子: 58 * 7 = ?<br><br>\
示例#4
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
示例#5
0
def resetDb():
    db.drop_all()
    db.create_all()
示例#6
0
 def setUp(self):
     # http://kronosapiens.github.io/blog/2014/07/29/setting-up-unit-tests-with-flask.html
     app.config.from_pyfile('settings.py')
     db.session.close()
     db.drop_all()
     db.create_all()
示例#7
0
 def setUp(self):
     # http://kronosapiens.github.io/blog/2014/07/29/setting-up-unit-tests-with-flask.html
     app.config.from_pyfile('settings.py')
     db.session.close()
     db.drop_all()
     db.create_all()