def setUp(self): super(TestingModeTestCase, self).setUp() self.person1 = PopoloPerson.objects.get(id=1) self.owner = User.objects.get(id=1) self.owner.email = "*****@*****.**" self.owner.save() self.writeitinstance = WriteItInstance.objects.create( name='instance 1', slug='instance-1', owner=self.owner) InstanceMembership.objects.create(writeitinstance=self.writeitinstance, person=self.person1) self.channel = MailChannel() self.contact = Contact.objects.create( person=self.person1, contact_type=self.channel.get_contact_type(), value='*****@*****.**', writeitinstance=self.writeitinstance, ) self.message = Message.objects.create( content="The content", subject="the subject", writeitinstance=self.writeitinstance, persons=[self.person1], author_name="Felipe", author_email="*****@*****.**", )
def create_contact(cls, obj, doc, writeitinstance): contact_type = MailChannel().get_contact_type() created_emails = [] enable_contacts = cls.determine_if_person_is_current(doc) if 'contact_details' in doc: for contact_detail in doc['contact_details']: if contact_detail['type'] == 'email': contact, created = Contact.objects.get_or_create( popit_identifier=contact_detail['id'], contact_type=contact_type, writeitinstance=writeitinstance, person=obj) contact.value = contact_detail['value'] contact.enabled = enable_contacts contact.save() created_emails.append(contact.value) if 'email' in doc and doc['email'] is not None and doc[ 'email'] not in created_emails: contact, created = Contact.objects.get_or_create( contact_type=contact_type, writeitinstance=writeitinstance, person=obj) contact.value = doc['email'] contact.enabled = enable_contacts contact.save()
def create_contactos(person_object, writeitinstance): """Update Contact objects from contactos from the django-popolo Person""" # This replicates the logic from nuntium/popit_api_instance.py to # create these contacts, complete with its bugs, e.g. not removing # old Contacts that are no longer current (FIXME) contact_type = MailChannel().get_contact_type() created_emails = set() enable_contacts = determine_if_person_is_current(person_object) for contact_detail in person_object.contact_details.all(): if contact_detail.contact_type == 'email': contact, created = Contact.objects.get_or_create( contact_type=contact_type, writeitinstance=writeitinstance, person=person_object) contact.value = contact_detail.value contact.enabled = enable_contacts contact.save() created_emails.add(contact.value) if person_object.email and person_object.email not in created_emails: contact, created = Contact.objects.get_or_create( contact_type=contact_type, writeitinstance=writeitinstance, person=person_object) contact.value = person_object.email contact.enabled = enable_contacts contact.save()
def setUp(self): super(TestingModeTestCase, self).setUp() self.person1 = Person.objects.get(id=1) self.owner = User.objects.get(id=1) self.owner.email = "*****@*****.**" self.owner.save() self.writeitinstance = WriteItInstance.objects.create( name='instance 1', slug='instance-1', owner=self.owner) Membership.objects.create(writeitinstance=self.writeitinstance, person=self.person1) self.channel = MailChannel() self.contact = Contact.objects.create( person=self.person1, contact_type=self.channel.get_contact_type(), value='*****@*****.**', writeitinstance=self.writeitinstance, ) self.message = Message.objects.create( content="The content", subject="the subject", writeitinstance=self.writeitinstance, persons=[self.person1], author_name="Felipe", author_email="*****@*****.**", )
class TestingModeTestCase(TestCase): def setUp(self): super(TestingModeTestCase, self).setUp() self.person1 = PopoloPerson.objects.get(id=1) self.owner = User.objects.get(id=1) self.owner.email = "*****@*****.**" self.owner.save() self.writeitinstance = WriteItInstance.objects.create( name='instance 1', slug='instance-1', owner=self.owner) InstanceMembership.objects.create(writeitinstance=self.writeitinstance, person=self.person1) self.channel = MailChannel() self.contact = Contact.objects.create( person=self.person1, contact_type=self.channel.get_contact_type(), value='*****@*****.**', writeitinstance=self.writeitinstance, ) self.message = Message.objects.create( content="The content", subject="the subject", writeitinstance=self.writeitinstance, persons=[self.person1], author_name="Felipe", author_email="*****@*****.**", ) def test_testing_mode_send_mail(self): '''When testing mode is on the messages are sent to the owner's email''' outbound_message = self.message.outboundmessage_set.all()[0] self.writeitinstance.config.testing_mode = True self.writeitinstance.config.save() self.channel.send(outbound_message) self.assertEquals(len(mail.outbox[0].to), 1) self.assertIn(self.owner.email, mail.outbox[0].to)
class TestingModeTestCase(TestCase): def setUp(self): super(TestingModeTestCase, self).setUp() self.person1 = Person.objects.get(id=1) self.owner = User.objects.get(id=1) self.owner.email = "*****@*****.**" self.owner.save() self.writeitinstance = WriteItInstance.objects.create( name='instance 1', slug='instance-1', owner=self.owner) Membership.objects.create(writeitinstance=self.writeitinstance, person=self.person1) self.channel = MailChannel() self.contact = Contact.objects.create( person=self.person1, contact_type=self.channel.get_contact_type(), value='*****@*****.**', writeitinstance=self.writeitinstance, ) self.message = Message.objects.create( content="The content", subject="the subject", writeitinstance=self.writeitinstance, persons=[self.person1], author_name="Felipe", author_email="*****@*****.**", ) def test_testing_mode_send_mail(self): '''When testing mode is on the messages are sent to the owner's email''' outbound_message = self.message.outboundmessage_set.all()[0] self.writeitinstance.config.testing_mode = True self.writeitinstance.config.save() self.channel.send(outbound_message) self.assertEquals(len(mail.outbox[0].to), 1) self.assertIn(self.owner.email, mail.outbox[0].to)
def __init__(self, *args, **kwargs): self.writeitinstance = kwargs.pop('writeitinstance') self.person = kwargs.pop('person') self.contact_type = MailChannel().contact_type super(ContactCreateForm, self).__init__(*args, **kwargs)