当前位置: 首页>>代码示例>>Python>>正文


Python SQLAlchemy.create_all方法代码示例

本文整理汇总了Python中sqlalchemy_wrapper.SQLAlchemy.create_all方法的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemy.create_all方法的具体用法?Python SQLAlchemy.create_all怎么用?Python SQLAlchemy.create_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy_wrapper.SQLAlchemy的用法示例。


在下文中一共展示了SQLAlchemy.create_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_flask_app

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def _get_flask_app(roles=False, **kwargs):
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(
        SECRET_KEY, db=db, roles=roles, password_minlen=3, **kwargs)
    User = auth.User

    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.add(user)

    user2 = User(login=u'foo', password='bar')
    db.add(user2)
    db.commit()

    app = Flask('test')
    app.secret_key = os.urandom(32)
    app.testing = True

    @app.route('/protected/')
    @auth.protected()
    def protected():
        return u'Welcome'

    authcode.setup_for_flask(auth, app)
    auth.session = {}
    return auth, app, user
开发者ID:jpscaletti,项目名称:authcode,代码行数:28,代码来源:test_views.py

示例2: test_authenticate_with_token

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_authenticate_with_token():
    from time import time
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db, token_life=3 * 60)

    User = auth.User

    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.session.add(user)
    db.session.commit()

    token = user.get_token()
    auth_user = auth.authenticate({'token': token})
    assert auth_user

    token = '555' + user.get_token()
    auth_user = auth.authenticate({'token': token})
    assert not auth_user

    auth_user = auth.authenticate({'token': ''})
    assert not auth_user

    timestamp = int(time()) - auth.token_life + 1
    token = user.get_token(timestamp)
    auth_user = auth.authenticate({'token': token})
    assert auth_user

    timestamp = int(time()) - auth.token_life - 1
    token = user.get_token(timestamp)
    auth_user = auth.authenticate({'token': token})
    assert not auth_user
开发者ID:jpscaletti,项目名称:authcode,代码行数:34,代码来源:test_auth.py

示例3: test_models_mixins

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_models_mixins():
    db = SQLAlchemy('sqlite:///:memory:')

    class UserMixin(object):
        email = db.Column(db.Unicode(300))

        def __repr__(self):
            return 'overwrited'

    class RoleMixin(object):
        description = db.Column(db.UnicodeText)

    auth = authcode.Auth(SECRET_KEY, db=db, UserMixin=UserMixin, RoleMixin=RoleMixin)
    User = auth.User
    Role = auth.Role

    db.create_all()
    user = User(login=u'meh', password='foobar', email=u'[email protected]')
    db.session.add(user)
    db.flush()

    assert User.__tablename__ == 'users'
    assert user.login == u'meh'
    assert user.email == u'[email protected]'
    assert hasattr(user, 'password')
    assert hasattr(user, 'last_sign_in')
    assert repr(user) == 'overwrited'

    assert hasattr(Role, 'description')
开发者ID:jpscaletti,项目名称:authcode,代码行数:31,代码来源:test_models.py

示例4: test_replace_hash_password_method

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_replace_hash_password_method():
    """Can the library work the same with custom ``has_password`` and
    ``password_is_valid`` methods?
    """

    class CustomAuth(authcode.Auth):
        def hash_password(self, secret):
            secret = self.prepare_password(secret)
            return secret[::-1]

        def password_is_valid(self, secret, hashed):
            secret = self.prepare_password(secret)
            if secret is None or hashed is None:
                return False
            return self.hash_password(secret) == hashed

    db = SQLAlchemy('sqlite:///:memory:')
    auth = CustomAuth(SECRET_KEY, db=db)
    User = auth.User
    db.create_all()

    credentials = {'login': u'meh', 'password': 'foobar'}
    user = User(**credentials)
    db.session.add(user)
    db.session.commit()

    assert user.password == 'foobar'[::-1]
    assert user.has_password('foobar')

    auth_user = auth.authenticate(credentials)
    assert user.login == auth_user.login

    auth_user = auth.authenticate({})
    assert not auth_user
开发者ID:jpscaletti,项目名称:authcode,代码行数:36,代码来源:test_auth.py

示例5: test_authenticate_with_password

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_authenticate_with_password():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db)

    User = auth.User

    db.create_all()
    credentials = {'login': u'meh', 'password': 'foobar'}
    user = User(**credentials)
    db.session.add(user)
    db.session.commit()

    auth_user = auth.authenticate(credentials)
    assert user.login == auth_user.login

    auth_user = auth.authenticate({})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'meh'})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'wtf', 'password': 'foobar'})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'meh', 'password': 'lalala'})
    assert not auth_user
开发者ID:jpscaletti,项目名称:authcode,代码行数:28,代码来源:test_auth.py

示例6: test_user_has_empty_password

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_user_has_empty_password():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db, password_minlen=0)

    User = auth.User

    db.create_all()
    user = User(login=u'meh', password=u'')
    db.session.add(user)
    db.session.commit()

    assert user.password != u''

    auth_user = auth.authenticate({'login': u'meh', 'password': u''})
    assert auth_user

    auth_user = auth.authenticate({})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'meh', 'password': None})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'meh'})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'wtf', 'password': ''})
    assert not auth_user

    auth_user = auth.authenticate({'login': u'meh', 'password': 'lalala'})
    assert not auth_user
开发者ID:jpscaletti,项目名称:authcode,代码行数:32,代码来源:test_auth.py

示例7: test_define_table

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_define_table():
    db = SQLAlchemy(URI1)
    db.Table('foobar',
             db.Column('foo', db.UnicodeText),
             db.Column('bar', db.UnicodeText))
    db.Table('fizzbuzz', db.metadata,
             db.Column('fizz', db.Integer),
             db.Column('buzz', db.Integer))
    db.create_all()
开发者ID:aadu,项目名称:sqlalchemy-wrapper,代码行数:11,代码来源:test_main.py

示例8: test_automatic_case_insensitiveness

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_automatic_case_insensitiveness():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db)
    User = auth.User
    db.create_all()
    user = User(login=u'MeH', password='foobar')
    db.session.add(user)
    db.session.commit()

    assert user.login == u'meh'
    assert User.by_login(u'MEH') == User.by_login(u'MeH') == user
开发者ID:jpscaletti,项目名称:authcode,代码行数:13,代码来源:test_auth.py

示例9: test_role_model

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_role_model():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db, roles=True)
    Role = auth.Role
    db.create_all()
    role = Role(name=u'admin')
    db.session.add(role)
    db.commit()

    assert role.name == u'admin'
    assert repr(role) == '<Role admin>'
开发者ID:jpscaletti,项目名称:authcode,代码行数:13,代码来源:test_models.py

示例10: test_user_model_to_dict

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_user_model_to_dict():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db, roles=True)
    User = auth.User
    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.session.add(user)
    db.commit()

    user_dict = user.to_dict()
    assert user_dict
开发者ID:jpscaletti,项目名称:authcode,代码行数:13,代码来源:test_models.py

示例11: test_formset_missing_objs

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_formset_missing_objs():
    db = SQLAlchemy()

    class User(db.Model):
        __tablename__ = 'users'
        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String)

    class Address(db.Model):
        __tablename__ = 'addresses'
        id = db.Column(db.Integer, primary_key=True)
        email = db.Column(db.String)
        user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
        user = db.relationship('User',
            backref=db.backref('addresses', lazy='dynamic'))

        def __repr__(self):
            return self.email

    db.create_all()

    class FormAddress(f.Form):
        _model = Address
        email = f.Text(validate=[f.ValidEmail])

        def __repr__(self):
            return '<FormAddress %s>' % (self.email.value,)

    class FormUser(f.Form):
        _model = User
        name = f.Text()
        addresses = f.FormSet(FormAddress, parent='user')

    user = User(name=u'John Doe')
    db.add(user)
    a1 = Address(email=u'[email protected]', user=user)
    db.add(a1)
    a2 = Address(email=u'[email protected]', user=user)
    db.add(a2)
    a3 = Address(email=u'[email protected]', user=user)
    db.add(a3)
    db.commit()
    print([(a.id, a.email) for a in user.addresses])

    data = {
        'name': u'Jane Doe',
        'formaddress.1-email': u'[email protected]',
        'formaddress.3-email': u'[email protected]',
        'formaddress.4-email': u'[email protected]',
    }
    form = FormUser(data, user)
    assert form.is_valid()
    assert form.addresses.missing_objs == [a2]
开发者ID:PuercoPop,项目名称:solution,代码行数:55,代码来源:test_forms.py

示例12: test_backwards_compatibility

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_backwards_compatibility():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db)
    User = auth.User
    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.session.add(user)
    db.commit()

    assert user._password == user.password
    user._password = 'raw'
    assert user.password == 'raw'
开发者ID:jpscaletti,项目名称:authcode,代码行数:14,代码来源:test_models.py

示例13: test_set_raw_password

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_set_raw_password():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db, roles=True)
    User = auth.User
    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.session.add(user)
    db.session.commit()

    assert user.password != 'foobar'
    user.set_raw_password('foobar')
    assert user.password == 'foobar'
开发者ID:jpscaletti,项目名称:authcode,代码行数:14,代码来源:test_models.py

示例14: test_get_uhmac

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_get_uhmac():
    db = SQLAlchemy('sqlite:///:memory:')
    auth = authcode.Auth(SECRET_KEY, db=db)

    User = auth.User

    db.create_all()
    user = User(login=u'meh', password='foobar')
    db.session.add(user)
    db.session.commit()

    assert user.get_uhmac()
    assert user.get_uhmac() == user.get_uhmac()
开发者ID:jpscaletti,项目名称:authcode,代码行数:15,代码来源:test_auth.py

示例15: test_id_mixin

# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import create_all [as 别名]
def test_id_mixin():
    db = SQLAlchemy(URI1)

    class IDMixin(object):
        id = db.Column(db.Integer, primary_key=True)

    class Model(db.Model, IDMixin):
        field = db.Column(db.String)

    db.create_all()

    assert Model.__tablename__ == 'models'
    assert hasattr(Model, 'id')
开发者ID:aadu,项目名称:sqlalchemy-wrapper,代码行数:15,代码来源:test_main.py


注:本文中的sqlalchemy_wrapper.SQLAlchemy.create_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。