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


Python Member.create方法代码示例

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


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

示例1: testBorderValues

# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import create [as 别名]
    def testBorderValues(self):
        azusa = Member.create(first_name="Azusa", last_name="Nakano", part="Gt2", age=16)
        self.assert_(azusa)

        def _age_exceeded(): azusa.age = 19
        def _age_underrun(): azusa.age = 14
        self.assertRaises(macaron.ValidationError, _age_exceeded)
        self.assertRaises(macaron.ValidationError, _age_underrun)

        def _too_long_part_name(): azusa.part = "1234567890A"
        self.assertRaises(macaron.ValidationError, _too_long_part_name)

        def _name_is_not_set(): Member.create(first_name="Azusa")
        self.assertRaises(macaron.ValidationError, _name_is_not_set)
开发者ID:FrViPofm,项目名称:macaron,代码行数:16,代码来源:test_query.py

示例2: _name_is_not_set

# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import create [as 别名]
 def _name_is_not_set(): Member.create(first_name="Azusa")
 self.assertRaises(macaron.ValidationError, _name_is_not_set)
开发者ID:FrViPofm,项目名称:macaron,代码行数:4,代码来源:test_query.py

示例3: testCRUDObject

# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import create [as 别名]
    def testCRUDObject(self):
        # Test for creating, reading, updating, deleteing
        # Create team
        name = "Houkago Tea Time"
        team = Team.create(name=name)
        self.assertEqual(str(team), "<Team '%s'>" % name)
        self.assertEqual(team.id, 1)

        # Create members
        for idx, n in enumerate(self.names):
            member = Member.create(band=team, first_name=n[0], last_name=n[1], part=n[2])
            self.assertEqual(str(member), "<Member '%s'>" % n[3])
            self.assertEqual(member.id, idx + 1)

        # Get member with primary key
        ritsu = Member.get(1)
        self.assertEqual(str(ritsu), "<Member 'Ritsu Tainaka : Dr'>")

        # Get team the member Ritsu belongs to is Houkago Tea Time
        team = ritsu.band
        self.assertEqual(str(team), "<Team 'Houkago Tea Time'>")

        # Get members with iterator
        for idx, m in enumerate(team.members):
            self.assertEqual(str(m), "<Member '%s'>" % self.names[idx][3])

        # Yui changes instrument to castanets
        macaron.bake()  # Commit before changes
        yui = Member.get(first_name="Yui", last_name="Hirasawa")
        self.assert_(yui)
        yui.part = "Castanets"
        self.assertEqual(yui.part, "Castanets")
        yui.save()

        # Re-fetch Yui
        member = Member.get(3)
        self.assertEqual(member.part, "Castanets")

        # Delete all members
        self.assertEqual(team.members.count(), 4)
        team.members.select(first_name="Ritsu").delete()
        self.assertEqual(team.members.count(), 3)
        team.members.delete()
        self.assertEqual(team.members.count(), 0)

        # Test for rollback
        # Cancel the changes
        macaron.rollback()
        team = Team.get(1)
        self.assertEqual(team.members.count(), 4)

        # Add another member 'Sawako' as Gt1
        member = Member.create(band=team, first_name="Sawako", last_name="Yamanaka", part="Gt1")
        self.assertEqual(str(member), "<Member 'Sawako Yamanaka : Gt1'>")

        # Re-fetch Sawako with index
        sawako = team.members[4]
        self.assertEqual(str(sawako), "<Member 'Sawako Yamanaka : Gt1'>")

        # But, Sawako is not a member of the team
        sawako.delete()

        # Add another member Azusa through reverse relation of ManyToOne
        team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2")
        azu = Member.get(first_name="Azusa")
        self.assertEqual(str(azu), "<Member 'Azusa Nakano : Gt2'>")

        # Okay, Yui changes part to Gt1
        yui = Member.get(first_name="Yui")
        yui.part = "Gt1"
        yui.save()
        self.assertEqual(yui.part, "Gt1")

        # At last, there are five menbers
        nm = self.names[:]
        nm[2] = ("Yui", "Hirasawa", "Gt1", "Yui Hirasawa : Gt1")
        nm.append(("Azusa", "Nakano", "Gt2", "Azusa Nakano : Gt2"))
        for idx, m in enumerate(team.members):
            self.assertEqual(str(m), "<Member '%s'>" % nm[idx][3])

        # Foreign key constraint works on sqlite3 >= 3.6.19
        ver = macaron.sqlite_version_info
        if ver >= (3, 6, 19):
            # Test for ON CASCADE
            team = Team.get(1)
            team.id = 2
            team.save()
            cnt = 0
            for member in Member.all():
                cnt += 1
                self.assertEqual(member.band_id, 2)
            self.assertEqual(cnt, Member.all().count())

            # Test for ON DELETE
            team.delete()
            cnt = 0
            for member in Member.all():
                self.assertEqual(member.band, None)
                cnt += 1
            self.assertEqual(cnt, Member.all().count())
#.........这里部分代码省略.........
开发者ID:imxiaohui,项目名称:macaron,代码行数:103,代码来源:test_basic.py


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