本文整理汇总了Python中mypartners.tests.factories.ContactFactory.archive方法的典型用法代码示例。如果您正苦于以下问题:Python ContactFactory.archive方法的具体用法?Python ContactFactory.archive怎么用?Python ContactFactory.archive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypartners.tests.factories.ContactFactory
的用法示例。
在下文中一共展示了ContactFactory.archive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestContactsDataSource
# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import archive [as 别名]
class TestContactsDataSource(MyJobsBase):
def setUp(self):
super(TestContactsDataSource, self).setUp()
# A company to work with
self.company = CompanyFactory(name='right')
self.company.save()
# A separate company that should not show up in results.
self.other_company = CompanyFactory(name='wrong')
self.other_company.save()
self.partner = PartnerFactory(
owner=self.company)
self.other_partner = PartnerFactory(
owner=self.other_company)
self.partner_a = PartnerFactory(owner=self.company, name="aaa")
self.partner_b = PartnerFactory(owner=self.company, name="bbb")
# An unapproved parther. Associated data should be filtered out.
self.partner_unapp = PartnerFactory(
owner=self.company,
name="unapproved",
approval_status__code=Status.UNPROCESSED)
# An archived parther. Associated data should be filtered out.
self.partner_archived = PartnerFactory(owner=self.company)
self.east_tag = TagFactory.create(
company=self.company, name='east', hex_color="aaaaaa")
self.west_tag = TagFactory.create(
company=self.company, name='west', hex_color="bbbbbb")
self.left_tag = TagFactory.create(
company=self.company, name='left', hex_color="cccccc")
self.right_tag = TagFactory.create(
company=self.company, name='right', hex_color="dddddd")
self.bad_tag = TagFactory.create(
company=self.company, name='bad', hex_color="cccccc")
self.partner_a.tags.add(self.left_tag)
self.partner_b.tags.add(self.right_tag)
self.john_user = UserFactory(email="[email protected]")
self.john = ContactFactory(
partner=self.partner_a,
name='john adams',
user=self.john_user,
email="[email protected]",
last_action_time='2015-10-03')
self.john.locations.add(
LocationFactory.create(
city="Indianapolis",
state="IN"))
self.john.locations.add(
LocationFactory.create(
city="Chicago",
state="IL"))
self.john.tags.add(self.east_tag)
self.sue_user = UserFactory(email="[email protected]")
self.sue = ContactFactory(
partner=self.partner_b,
name='Sue Baxter',
user=self.sue_user,
email="[email protected]",
last_action_time='2015-09-30 13:23')
self.sue.locations.add(
LocationFactory.create(
address_line_one="123",
city="Los Angeles",
state="CA"))
self.sue.locations.add(
LocationFactory.create(
address_line_one="234",
city="Los Angeles",
state="CA"))
self.sue.tags.add(self.west_tag)
# Poision data. Should never show up.
self.archived_partner_user = (
UserFactory(email="[email protected]"))
self.archived_partner = ContactFactory(
partner=self.partner_archived,
name='Archived Partner Contact',
user=self.archived_partner_user,
email="[email protected]",
last_action_time='2015-09-30 13:23')
self.archived_partner.locations.add(
LocationFactory.create(
address_line_one="123",
city="Nowhere",
state="NO"))
self.archived_partner.locations.add(
LocationFactory.create(
address_line_one="234",
city="Nowhere",
state="NO"))
self.archived_partner.tags.add(self.west_tag)
# Poision data. Should never show up.
self.archived_contact_user = (
#.........这里部分代码省略.........
示例2: MyPartnerTests
# 需要导入模块: from mypartners.tests.factories import ContactFactory [as 别名]
# 或者: from mypartners.tests.factories.ContactFactory import archive [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
#.........这里部分代码省略.........