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


Python ContactFactory.delete方法代码示例

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


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

示例1: MyPartnerTests

# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import delete [as 别名]
class MyPartnerTests(MyJobsBase):
    def setUp(self):
        super(MyPartnerTests, self).setUp()
        self.company = CompanyFactory()
        self.partner = PartnerFactory(owner=self.company)
        self.contact = ContactFactory(partner=self.partner)

    def test_contact_to_partner_relationship(self):
        """
        Tests adding a contact to partner's contacts list and tests
        primary_contact. Also tests if the contact gets deleted the partner
        stays and turns primary_contact to None.

        """
        self.assertEqual(Contact.objects.filter(partner=self.partner).count(),
                         1)

        self.partner.primary_contact = self.contact
        self.partner.save()
        self.assertIsNotNone(self.partner.primary_contact)

        # making sure contact is the contact obj vs a factory object.
        contact = Contact.objects.get(name=self.contact.name)
        contact.delete()

        partner = Partner.objects.get(name=self.partner.name)
        self.assertFalse(Contact.objects.filter(
            partner=partner, archived_on__isnull=True))
        self.assertIsNone(partner.primary_contact)

    def test_contact_user_relationship(self):
        """
        Tests adding a User to Contact. Then tests to make sure User cascading
        delete doesn't delete the Contact and instead turns Contact.user to
        None.
        """
        self.contact.user = UserFactory(email=self.contact.email)
        self.contact.save()

        self.assertIsNotNone(self.contact.user)
        self.assertEqual(self.contact.name, self.contact.__unicode__())

        user = User.objects.get(email=self.contact.email)
        user.delete()

        contact = Contact.objects.get(name=self.contact.name)
        self.assertIsNone(contact.user)

    def test_location_to_contact_relationship(self):
        """
        Tests adding a Location to Contact. 
        """
        location = LocationFactory()

        # make sure that we can add a location to a contact
        self.contact.locations.add(location)
        self.contact.save()
        self.assertTrue(len(self.contact.locations.all()) > 0)

        # ensure that we can remove a location
        self.contact.locations.remove(location)
        self.assertTrue(len(self.contact.locations.all()) == 0)

        # make sure that removing a location from a contact doesn't delete that
        # location entirely
        self.assertIn(location, Location.objects.all())

    def test_bad_filename(self):
        """
        Confirms that non-alphanumeric or underscore characters are being
        stripped from file names.

        """
        actual_file = path.join(path.abspath(path.dirname(__file__)), 'data',
                                'test.txt')
        f = File(open(actual_file))
        filenames = [
            ('zz\\x80\\xff*file(copy)na.me.htm)_-)l',
             'zzx80xfffilecopyname.htm_l'),
            ('...', 'unnamed_file'),
            ('..', 'unnamed_file'),
            ('../../file.txt', 'file.txt'),
            ('../..', 'unnamed_file'),
            ('\.\./file.txt', 'file.txt'),
            ('fiяыle.txt', 'file.txt')
        ]

        for filename, expected_filename in filenames:
            f.name = filename
            prm_attachment = PRMAttachment(attachment=f)
            setattr(prm_attachment, 'partner', self.partner)
            prm_attachment.save()
            result = PRMAttachment.objects.get(
                attachment__contains=expected_filename)
            result.delete()

    def test_partner_saved_search_delete_contact(self):
        """
        When a contact gets deleted, we should log it and disable any partner
        saved searches for that contact
#.........这里部分代码省略.........
开发者ID:zeus911,项目名称:MyJobs,代码行数:103,代码来源:test_models.py

示例2: MyPartnerTests

# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import delete [as 别名]
class MyPartnerTests(MyJobsBase):
    def setUp(self):
        super(MyPartnerTests, self).setUp()
        self.company = CompanyFactory()
        self.partner = PartnerFactory(owner=self.company)
        self.contact = ContactFactory(partner=self.partner)

    def test_contact_to_partner_relationship(self):
        """
        Tests adding a contact to partner's contacts list and tests
        primary_contact. Also tests if the contact gets deleted the partner
        stays and turns primary_contact to None.  
        """
        self.assertEqual(Contact.objects.filter(partner=self.partner).count(),
                         1)

        self.partner.primary_contact = self.contact
        self.partner.save()
        self.assertIsNotNone(self.partner.primary_contact)

        # making sure contact is the contact obj vs a factory object.
        contact = Contact.objects.get(name=self.contact.name)
        contact.delete()

        partner = Partner.objects.get(name=self.partner.name)
        self.assertFalse(Contact.objects.filter(
            partner=partner, archived_on__isnull=True))
        self.assertIsNone(partner.primary_contact)

    def test_contact_user_relationship(self):
        """
        Tests adding a User to Contact. Then tests to make sure User cascading
        delete doesn't delete the Contact and instead turns Contact.user to
        None.
        """
        self.contact.user = UserFactory(email=self.contact.email)
        self.contact.save()

        self.assertIsNotNone(self.contact.user)
        self.assertEqual(self.contact.name, self.contact.__unicode__())

        user = User.objects.get(email=self.contact.email)
        user.delete()

        contact = Contact.objects.get(name=self.contact.name)
        self.assertIsNone(contact.user)

    def test_location_to_contact_relationship(self):
        """
        Tests adding a Location to Contact. 
        """
        location = LocationFactory()

        # make sure that we can add a location to a contact
        self.contact.locations.add(location)
        self.contact.save()
        self.assertTrue(len(self.contact.locations.all()) > 0)

        # ensure that we can remove a location
        self.contact.locations.remove(location)
        self.assertTrue(len(self.contact.locations.all()) == 0)

        # make sure that removing a location from a contact doesn't delete that
        # location entirely
        self.assertIn(location, Location.objects.all())

    def test_bad_filename(self):
        """
        Confirms that non-alphanumeric or underscore characters are being
        stripped from file names.

        """
        actual_file = path.join(path.abspath(path.dirname(__file__)), 'data',
                                'test.txt')
        f = File(open(actual_file))
        filenames = [
            ('zz\\x80\\xff*file(copy)na.me.htm)_-)l',
             'zzx80xfffilecopyname.htm_l'),
            ('...', 'unnamed_file'),
            ('..', 'unnamed_file'),
            ('../../file.txt', 'file.txt'),
            ('../..', 'unnamed_file'),
            ('\.\./file.txt', 'file.txt'),
            ('fiяыle.txt', 'file.txt')
        ]

        for filename, expected_filename in filenames:
            f.name = filename
            prm_attachment = PRMAttachmentFactory(attachment=f)
            result = PRMAttachment.objects.get(
                attachment__contains=expected_filename)
            result.delete()

    def test_partner_saved_search_delete_contact(self):
        """
        When a contact gets deleted, we should log it and disable any partner
        saved searches for that contact
        """
        user = UserFactory(email='[email protected]')
        self.contact.user = user
#.........这里部分代码省略.........
开发者ID:wejhink,项目名称:MyJobs,代码行数:103,代码来源:test_models.py

示例3: MyPartnerTests

# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import delete [as 别名]
class MyPartnerTests(MyJobsBase):
    def setUp(self):
        super(MyPartnerTests, self).setUp()
        self.company = CompanyFactory()
        self.partner = PartnerFactory(owner=self.company)
        self.contact = ContactFactory(partner=self.partner)

    def test_contact_to_partner_relationship(self):
        """
        Tests adding a contact to partner's contacts list and tests
        primary_contact. Also tests if the contact gets deleted the partner
        stays and turns primary_contact to None.

        """
        self.assertEqual(Contact.objects.filter(partner=self.partner).count(),
                         1)

        self.partner.primary_contact = self.contact
        self.partner.save()
        self.assertIsNotNone(self.partner.primary_contact)

        # making sure contact is the contact obj vs a factory object.
        contact = Contact.objects.get(name=self.contact.name)
        contact.delete()

        partner = Partner.objects.get(name=self.partner.name)
        self.assertFalse(Contact.objects.filter(
            partner=partner, archived_on__isnull=True))
        self.assertIsNone(partner.primary_contact)

    def test_contact_user_relationship(self):
        """
        Tests adding a User to Contact. Then tests to make sure User cascading
        delete doesn't delete the Contact and instead turns Contact.user to
        None.
        """
        self.contact.user = UserFactory(email=self.contact.email)
        self.contact.save()

        self.assertIsNotNone(self.contact.user)
        self.assertEqual(self.contact.name, self.contact.__unicode__())

        user = User.objects.get(email=self.contact.email)
        user.delete()

        contact = Contact.objects.get(name=self.contact.name)
        self.assertIsNone(contact.user)

    def test_location_to_contact_relationship(self):
        """
        Tests adding a Location to Contact. 
        """
        location = LocationFactory()

        # make sure that we can add a location to a contact
        self.contact.locations.add(location)
        self.contact.save()
        self.assertTrue(len(self.contact.locations.all()) > 0)

        # ensure that we can remove a location
        self.contact.locations.remove(location)
        self.assertTrue(len(self.contact.locations.all()) == 0)

        # make sure that removing a location from a contact doesn't delete that
        # location entirely
        self.assertIn(location, Location.objects.all())

    def test_bad_filename(self):
        """
        Confirms that non-alphanumeric or underscore characters are being
        stripped from file names.

        """
        actual_file = path.join(path.abspath(path.dirname(__file__)), 'data',
                                'test.txt')
        f = File(open(actual_file))
        filenames = [
            ('zz\\x80\\xff*file(copy)na.me.htm)_-)l',
             'zzx80xfffilecopyname.htm_l'),
            ('...', 'unnamed_file'),
            ('..', 'unnamed_file'),
            ('../../file.txt', 'file.txt'),
            ('../..', 'unnamed_file'),
            ('\.\./file.txt', 'file.txt'),
            ('fiяыle.txt', 'file.txt')
        ]

        for filename, expected_filename in filenames:
            f.name = filename
            prm_attachment = PRMAttachmentFactory(attachment=f)
            result = PRMAttachment.objects.get(
                attachment__contains=expected_filename)
            result.delete()

    def test_partner_saved_search_delete_contact(self):
        """
        When a contact gets deleted, we should log it and disable any partner
        saved searches for that contact
        """
        user = UserFactory(email='[email protected]')
#.........这里部分代码省略.........
开发者ID:kepinae,项目名称:MyJobs,代码行数:103,代码来源:test_models.py


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