本文整理汇总了Python中mhvdb2.models.Entity.save方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.save方法的具体用法?Python Entity.save怎么用?Python Entity.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mhvdb2.models.Entity
的用法示例。
在下文中一共展示了Entity.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
def create(name, email, phone):
entity = Entity()
entity.is_member = False
entity.name = name
entity.email = email
entity.phone = phone
entity.save()
return entity.id
示例2: create
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
def create(name, email, phone, joined_date=None, agreement_date=None):
if joined_date is None:
joined_date = date.today()
if agreement_date is None:
agreement_date = date.today()
member = Entity()
member.is_member = True
member.name = name
member.email = email
member.phone = phone
member.joined_date = joined_date
member.agreement_date = agreement_date
member.save()
return member.id
示例3: create
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
def create(name, email, phone):
member = Entity()
member.is_member = True
member.joined_date = date.today()
member.name = name
member.email = email
member.phone = phone
member.agreement_date = date.today()
return member.save()
示例4: MembersTestCases
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
class MembersTestCases(unittest.TestCase):
def setUp(self):
self.test_member = Entity()
self.test_member.is_member = True
self.test_member.name = "Jane Smith"
self.test_member.email = "[email protected]"
self.test_member.phone = "+61 (02) 1234 5678"
self.test_member.joined_date = date.today()-timedelta(days=1)
self.test_member.agreement_date = date.today()
self.test_member.is_keyholder = False
self.test_member.save()
self.joined_date = "2014-12-24"
self.agreement_date = "2014-12-25"
def tearDown(self):
self.test_member.delete_instance()
def test_get(self):
member = members.get(self.test_member.id)
self.assertEqual(member, self.test_member)
def test_get_bad_id(self):
member = members.get(12345)
self.assertIsNone(member)
def test_validate(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 0)
def test_validate_name(self):
errors = members.validate("",
self.test_member.email,
self.test_member.phone,
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 1)
def test_validate_email(self):
errors = members.validate(self.test_member.name,
"",
self.test_member.phone,
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 1)
errors = members.validate(self.test_member.name,
"not-an-email.com",
self.test_member.phone,
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 1)
errors = members.validate(self.test_member.name,
"[email protected]",
self.test_member.phone,
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 1)
def test_validate_phone(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
"",
self.joined_date,
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 0)
def test_validate_joined_date(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
"2014-12-25",
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 0)
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
"The 25th of December, Stardate 21020",
self.agreement_date,
self.test_member.is_keyholder)
self.assertEqual(len(errors), 1)
def test_validate_agreement_date(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
self.joined_date,
"2014-12-25",
#.........这里部分代码省略.........
示例5: EntitiesTestCases
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
class EntitiesTestCases(unittest.TestCase):
def setUp(self):
self.test_entity = Entity()
self.test_entity.is_member = False
self.test_entity.name = "Jane Smith"
self.test_entity.email = "[email protected]"
self.test_entity.phone = "+61 (02) 1234 5678"
self.test_entity.save()
def tearDown(self):
self.test_entity.delete_instance()
def test_get(self):
entity = entities.get(self.test_entity.id)
self.assertEqual(entity, self.test_entity)
def test_get_bad_id(self):
entity = entities.get(12345)
self.assertIsNone(entity)
def test_validate(self):
errors = entities.validate(self.test_entity.name,
self.test_entity.email,
self.test_entity.phone)
self.assertEqual(len(errors), 0)
def test_validate_name(self):
errors = entities.validate("",
self.test_entity.email,
self.test_entity.phone)
self.assertEqual(len(errors), 1)
def test_validate_email(self):
errors = entities.validate(self.test_entity.name,
"",
self.test_entity.phone)
self.assertEqual(len(errors), 0)
errors = entities.validate(self.test_entity.name,
"not-an-email.com",
self.test_entity.phone)
self.assertEqual(len(errors), 1)
errors = entities.validate(self.test_entity.name,
"[email protected]",
self.test_entity.phone)
self.assertEqual(len(errors), 1)
def test_validate_phone(self):
errors = entities.validate(self.test_entity.name,
self.test_entity.email,
"")
self.assertEqual(len(errors), 0)
def test_create(self):
entity_id = entities.create(self.test_entity.name,
self.test_entity.email,
self.test_entity.phone)
entity = Entity.get(Entity.id == entity_id)
self.assertNotEqual(entity.id, self.test_entity.id)
self.assertEqual(entity.name, self.test_entity.name)
self.assertEqual(entity.email, self.test_entity.email)
self.assertEqual(entity.phone, self.test_entity.phone)
entity.delete_instance()
def test_update(self):
new_name = "Joe Flanders"
new_email = "[email protected]"
new_phone = "(04) 9876 5432"
entities.update(self.test_entity.id,
new_name,
new_email,
new_phone)
entity = Entity.get(Entity.id == self.test_entity.id)
self.assertEqual(entity.name, new_name)
self.assertEqual(entity.email, new_email)
self.assertEqual(entity.phone, new_phone)
示例6: MembersTestCases
# 需要导入模块: from mhvdb2.models import Entity [as 别名]
# 或者: from mhvdb2.models.Entity import save [as 别名]
class MembersTestCases(unittest.TestCase):
def setUp(self):
self.test_member = Entity()
self.test_member.is_member = True
self.test_member.name = "Jane Smith"
self.test_member.email = "[email protected]"
self.test_member.phone = "+61 (02) 1234 5678"
self.test_member.joined_date = date.today()-timedelta(days=1)
self.test_member.agreement_date = date.today()
self.test_member.save()
self.joined_date = "2014-12-24"
self.agreement_date = "2014-12-25"
def tearDown(self):
self.test_member.delete_instance()
def test_get(self):
member = members.get(self.test_member.id)
self.assertEqual(member, self.test_member)
def test_get_bad_id(self):
member = members.get(12345)
self.assertIsNone(member)
def test_validate(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 0)
def test_validate_name(self):
errors = members.validate("",
self.test_member.email,
self.test_member.phone,
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 1)
def test_validate_email(self):
errors = members.validate(self.test_member.name,
"",
self.test_member.phone,
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 1)
errors = members.validate(self.test_member.name,
"not-an-email.com",
self.test_member.phone,
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 1)
errors = members.validate(self.test_member.name,
"[email protected]",
self.test_member.phone,
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 1)
def test_validate_phone(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
"",
self.joined_date,
self.agreement_date)
self.assertEqual(len(errors), 0)
def test_validate_joined_date(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
"2014-12-25",
self.agreement_date)
print(errors)
self.assertEqual(len(errors), 0)
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
"The 25th of December, Stardate 21020",
self.agreement_date)
self.assertEqual(len(errors), 1)
def test_validate_agreement_date(self):
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
self.joined_date,
"2014-12-25")
self.assertEqual(len(errors), 0)
errors = members.validate(self.test_member.name,
self.test_member.email,
self.test_member.phone,
"The 25th of December, Stardate 21020",
self.agreement_date)
self.assertEqual(len(errors), 1)
#.........这里部分代码省略.........