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


Python User.at方法代码示例

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


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

示例1: test_getone

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_getone(self):
        assert User.create(name='jack', email='[email protected]')
        assert User.create(name='amy', email='[email protected]')

        user = User.at(1).getone()
        assert user.name == 'jack' and user.id == 1

        user = User.at(10).getone()
        assert user is None
开发者ID:bopo,项目名称:skylark,代码行数:11,代码来源:tests.py

示例2: test_reset_data

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_reset_data(self):
     User.where(User.name == 'hello')
     assert User.runtime.data['where']
     User.where(User.name == 'x').select()
     for runtime_key, runtime_data in User.runtime.data.items():
         assert not runtime_data
     User.at(7).select()
     for runtime_key, runtime_data in User.runtime.data.items():
         assert not runtime_data
开发者ID:zhangjinglei,项目名称:skylark,代码行数:11,代码来源:tests.py

示例3: test_update

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_update(self):
        self.create_data(2, table=1)
        assert User.at(1).update(User.name == 'newname1').execute() == 1
        assert User.at(2).update(name='newname2').execute() == 1

        user = User.getone()
        assert user.name == 'newname1'

        query = User.update(email='newemail')
        assert query.execute() == 2
开发者ID:zhangjinglei,项目名称:skylark,代码行数:12,代码来源:tests.py

示例4: test_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_delete(self):
     User.create(name='jack', email='[email protected]')
     User.create(name='amy', email='[email protected]')
     query = User.at(3).delete()
     rows_affected = query.execute()
     assert rows_affected == 0
     query = User.at(1).delete()
     rows_affected = query.execute()
     assert rows_affected == 1
     assert User.count() == 1
开发者ID:bopo,项目名称:skylark,代码行数:12,代码来源:tests.py

示例5: test_create

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_create(self):
     user1 = User.create(name='name1', email='email1')
     user2 = User.create(name='name2', email='email2')
     user3 = User.create(name='name3', email='email3')
     assert user1 and user2 and user3
     assert user1._id == 1 and user2._id == 2 and user3._id == 3
     assert user1 in User and user2 in User and user3 in User
     assert User.at(1).getone().name == 'name1'
     assert User.at(2).getone().name == 'name2'
     assert User.at(3).getone().name == 'name3'
开发者ID:zhangjinglei,项目名称:skylark,代码行数:12,代码来源:tests.py

示例6: test_concat

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_concat(self):
        self.create_data(4, table=1)
        query = User.select(fn.concat(User.name, '+', User.email))

        idx = 0
        for func in query:
            idx = idx + 1
            assert func.concat == 'name%d+email%d' % (idx, idx)

        query = User.at(1).update(name=fn.concat(User.email, User.id))
        assert query.execute() == 1
        assert User.at(1).getone().name == 'email11'
开发者ID:zhangjinglei,项目名称:skylark,代码行数:14,代码来源:tests.py

示例7: test_instance_destroy

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_instance_destroy(self):
        self.create_data(3, table=1)
        user = User.at(1).getone()
        assert user.destroy()
        assert user._in_db is False
        assert User.at(1).getone() is None

        user = User.at(2).select(User.name).execute().one()
        try:
            user.destroy()
        except PrimaryKeyValueNotFound:
            pass
开发者ID:zhangjinglei,项目名称:skylark,代码行数:14,代码来源:tests.py

示例8: test_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_delete(self):
     self.create_data(4, table=1)
     assert User.at(1).delete().execute() == 1
     assert User.where(
         (User.name == 'name1') | (User.name == 'name2')
     ).delete().execute() == 1
     assert User.count() == 2
开发者ID:zhangjinglei,项目名称:skylark,代码行数:9,代码来源:tests.py

示例9: test_func_only

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_func_only(self):
        self.create_data(3, table=1)
        query = User.select(fn.count(User.id))
        results = query.execute()
        func = results.one()
        assert func.count == 3
        assert results.count == 1

        query = User.at(2).select(fn.ucase(User.name).alias('uname'))
        results = query.execute()
        func = results.one()
        assert func.uname == 'NAME2'

        query = User.at(3).select(fn.concat(User.name, ' + ', 'hello'))
        results = query.execute()
        func = results.one()
        assert func.concat == 'name3 + hello'
开发者ID:zhangjinglei,项目名称:skylark,代码行数:19,代码来源:tests.py

示例10: test_func_and_inst

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_func_and_inst(self):
        self.create_data(3, table=1)
        query = User.at(1).select(User.name, fn.ucase(User.name))
        results = query.execute()
        user, func = results.one()
        assert user.name == 'name1', func.ucase == 'NAME1'

        for user, func in User.select(User.name, fn.ucase(User.name)):
            assert user.name.upper() == func.ucase
开发者ID:zhangjinglei,项目名称:skylark,代码行数:11,代码来源:tests.py

示例11: test_one

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_one(self):
        self.create_data(3, table=1)
        query = User.orderby(User.id).select()
        results = query.execute()
        user = results.one()
        assert user.id == 1

        query = User.at(3).select()
        results = query.execute()
        user = results.one()
        assert user.id == 3
开发者ID:zhangjinglei,项目名称:skylark,代码行数:13,代码来源:tests.py

示例12: test_concat

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_concat(self):
     assert User.create(name='jack', email='[email protected]')
     if db_type != 'sqlite':  # in sqlite, `||` is concat
         query = User.select(fn.concat(User.name, ' + ', User.email))
         result = query.execute()
         assert result.tuples()[0][0] == 'jack + [email protected]'
         query = User.at(1).update(name=fn.concat(User.name, ':'))
         result = query.execute()
         assert result == 1
         jack = User.at(1).getone()
         assert jack.name == 'jack:'
     else:
         query = User.select(User.name.op('||')(' + ').op('||')(User.email))
         result = query.execute()
         assert result.tuples()[0][0] == 'jack + [email protected]'
         query = User.at(1).update(name=User.name.op('||')(':'))
         result = query.execute()
         assert result == 1
         jack = User.at(1).getone()
         assert jack.name == 'jack:'
开发者ID:bopo,项目名称:skylark,代码行数:22,代码来源:tests.py

示例13: test_update

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_update(self):
        user = User.create(name='jack', email='[email protected]')
        assert user.id == 1
        assert user.name == 'jack'
        assert user.email == '[email protected]'
        assert User.count() == 1

        query = User.at(1).update(email='[email protected]')
        rows_affected = query.execute()
        assert rows_affected == 1
        user = User.getone()
        assert user.id == 1 and user.email == '[email protected]'
开发者ID:bopo,项目名称:skylark,代码行数:14,代码来源:tests.py

示例14: test_select

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
 def test_select(self):
     self.create_data(4, table=4)
     query = User.at(1).select()
     results = query.execute()
     assert results.count == 1
     user = results.one()
     assert user.id == 1 and user._in_db is True
     query = User.where(User.id < 3).select(User.name)
     results = query.execute()
     for user in results.all():
         assert user.name
     assert results.count == 2
开发者ID:zhangjinglei,项目名称:skylark,代码行数:14,代码来源:tests.py

示例15: test_model_inst_save

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import at [as 别名]
    def test_model_inst_save(self):
        user = User(name='jack', email='[email protected]')
        assert user.save() == 1
        assert User.count() == 1
        assert User.getone().name == 'jack'
        user.name = 'amy'
        assert user.save() == 1
        assert User.findone(id=1).name == 'amy'

        user = User(name='test!', email='[email protected]')
        id = user.save()
        assert id == 2
        assert User.at(2).getone().name == 'test!'
        user.name = 'run a test!'
        rows_affected = user.save()
        assert rows_affected == 1
        query = User.at(2).select(User.name)
        results = query.execute()
        user = results.one()
        try:
            user.name = 'hello'
            user.save()
        except PrimaryKeyValueNotFound:
            pass
开发者ID:zhangjinglei,项目名称:skylark,代码行数:26,代码来源:tests.py


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