def test_subject(self): """ Tests the get_email_value function for the 'Subject' field. """ actual = accessors.get_email_value('Subject', self.msg) expected = self.msg['Subject'] self.assertEqual(actual, expected)
def test_date(self): """ Tests the get_email_value function for the 'Date' field. """ actual = accessors.get_email_value('Date', self.msg) expected = '2015-09-08T16:08:59-04:00' self.assertEqual(actual, expected)
def _get_string(self, data): """ Takes an email Message object and returns the Message component indicated by the MailRule's field_name. """ value = accessors.get_email_value(self.field_name, data) return str(value)
def test_no_attachment(self): """ Tests the get_email_value function for the 'Attachment' field when there is no attachment. """ actual = accessors.get_email_value('Attachment', self.msg) expected = None self.assertEqual(actual, expected)
def test_attachments(self): """ Tests the get_email_value function for the 'Attachments' field. """ self.msg.attach(self.image) self.msg.attach(self.pdf) actual = accessors.get_email_value('Attachments', self.msg) expected = [self.image, self.pdf] self.assertEqual(actual, expected)
def test_content(self): """ Tests the get_email_value function for the 'Content' field. """ self.msg.attach(self.part1) self.msg.attach(self.part2) actual = accessors.get_email_value('Content', self.msg) expected = self.text self.assertEqual(actual, expected)
def process(self, email, company=None): """ Takes a value and returns a parsed result. """ value = get_email_value(self.source_field, email) if self._has_attachment() and value: value = self._save_attachments(value, company) result = self._parse(value) if self.formatter: return self._apply_template(result) else: return result