def test_preferred_address_without_preferred(self): field = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_ADDRESS, value='1600 Pennsylvania Ave.', ) self.assertEqual(self.contact.preferred_address, field.value)
def test_preferred_email_with_preferred(self): field = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_EMAIL, value='1600 Pennsylvania Ave.', preferred=True, ) self.assertEqual(self.contact.preferred_email, field.value)
def test_form_deleted_fields(self): field1 = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_URL, value='http://www.logtacts.com', ) field2 = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_URL, value='http://www.logtacts.com', ) field3 = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_URL, value='http://www.logtacts.com', ) form_data = { 'name': 'Philip James', 'deleted_fields': '{},{},{}'.format(field1.id, field2.id, 20) } form = forms.ContactForm( book=self.book, data=form_data, tag_choices=self.tag_choices, instance=self.contact, ) form.is_valid() form.save() self.assertEquals( len(models.ContactField.objects.filter(contact=self.contact)), 1, ) self.assertEquals( models.ContactField.objects.get(contact=self.contact), field3, )
def test_form_save_existing_field_email(self): field = factories.ContactFieldFactory(contact=self.contact) field.save() form_data = { 'name': 'Philip James', 'document_email_{}'.format(field.id): '*****@*****.**', 'document_email_{}_label'.format(field.id): 'New email', 'document_email_{}_pref'.format(field.id): '[on]', } form = forms.ContactForm( book=self.book, data=form_data, tag_choices=self.tag_choices, instance=self.contact, ) self.assert_(form.is_valid()) form.save() field = models.ContactField.objects.get(id=field.id) self.assertEqual(field.value, '*****@*****.**') self.assertEqual(field.label, 'New email')
def test_form_save_existing_field_email(self): field = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_DATE, value='2015-01-01', ) field.save() form_data = { 'name': 'Philip James', 'document_date_{}'.format(field.id): '2016-01-01', 'document_date_{}_label'.format(field.id): 'New date', 'document_date_{}_pref'.format(field.id): '[on]', } form = forms.ContactForm( book=self.book, data=form_data, tag_choices=self.tag_choices, instance=self.contact, ) self.assert_(form.is_valid()) form.save() field = models.ContactField.objects.get(id=field.id) self.assertEqual(field.value, '2016-01-01') self.assertEqual(field.label, 'New date')
def test_form_save_existing_field_url(self): field = factories.ContactFieldFactory( contact=self.contact, kind=contact_constants.FIELD_TYPE_URL, value='http://www.logtacts.com', ) field.save() form_data = { 'name': 'Philip James', 'document_url_{}'.format(field.id): 'http://www.contactotter.com', 'document_url_{}_label'.format(field.id): 'New URL', 'document_url_{}_pref'.format(field.id): '[on]', } form = forms.ContactForm( book=self.book, data=form_data, tag_choices=self.tag_choices, instance=self.contact, ) self.assert_(form.is_valid()) form.save() field = models.ContactField.objects.get(id=field.id) self.assertEqual(field.value, 'http://www.contactotter.com') self.assertEqual(field.label, 'New URL')