def _find_content(self, project, mail): for part in mail.walk(): if part.get_content_maintype() != 'text': continue payload = part.get_payload(decode=True) charset = part.get_content_charset() subtype = part.get_content_subtype() # if we don't have a charset, assume utf-8 if charset is None: charset = 'utf-8' if not isinstance(payload, unicode): payload = unicode(payload, charset) if subtype in ['x-patch', 'x-diff']: self.patch = payload elif subtype == 'plain': c = payload if not self.patch: (self.patch, c) = parse_patch(payload) if not self.pull_url: self.pull_url = self._find_pull_request(payload) if c is not None: self.comment += c.strip() + '\n' self.comment = self._clean_content(self.comment)
def test_parse_comment_after_patch(self): (patch, comment) = parse_patch(self.comment_after_patch) self.assertEqual("""Nice patch, eh?""", comment.strip())
def test_parse_comment_before_patch(self): (patch, comment) = parse_patch(self.comment_before_patch) self.assertEqual("""I send you my beautiful patch. I hope you like it""", comment.strip())
def test_parse_patch_after_patch(self): (patch, comment) = parse_patch(self.comment_before_patch) self.assertEqual(self.patch, patch)