當前位置: 首頁>>代碼示例>>Python>>正文


Python Entity.delete_instance方法代碼示例

本文整理匯總了Python中mhvdb2.models.Entity.delete_instance方法的典型用法代碼示例。如果您正苦於以下問題:Python Entity.delete_instance方法的具體用法?Python Entity.delete_instance怎麽用?Python Entity.delete_instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mhvdb2.models.Entity的用法示例。


在下文中一共展示了Entity.delete_instance方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: EntitiesTestCases

# 需要導入模塊: from mhvdb2.models import Entity [as 別名]
# 或者: from mhvdb2.models.Entity import delete_instance [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)
開發者ID:theswitch,項目名稱:mhvdb2,代碼行數:80,代碼來源:test_entities.py

示例2: MembersTestCases

# 需要導入模塊: from mhvdb2.models import Entity [as 別名]
# 或者: from mhvdb2.models.Entity import delete_instance [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",
#.........這裏部分代碼省略.........
開發者ID:cmrn,項目名稱:mhvdb2,代碼行數:103,代碼來源:test_members.py

示例3: MembersTestCases

# 需要導入模塊: from mhvdb2.models import Entity [as 別名]
# 或者: from mhvdb2.models.Entity import delete_instance [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)
#.........這裏部分代碼省略.........
開發者ID:theswitch,項目名稱:mhvdb2,代碼行數:103,代碼來源:test_members.py


注:本文中的mhvdb2.models.Entity.delete_instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。