本文整理汇总了Python中mypartners.tests.factories.ContactFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python ContactFactory.save方法的具体用法?Python ContactFactory.save怎么用?Python ContactFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypartners.tests.factories.ContactFactory
的用法示例。
在下文中一共展示了ContactFactory.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyPartnerTests
# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import save [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
#.........这里部分代码省略.........
示例2: MyPartnerTests
# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import save [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
#.........这里部分代码省略.........
示例3: MyPartnerTests
# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import save [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]')
#.........这里部分代码省略.........