コード例 #1
0
 def test_fromEmail_always_creates(self):
     """Even when messages are identical, fromEmail creates a new one."""
     email = self.factory.makeEmailMessage()
     orig_message = MessageSet().fromEmail(email.as_string())
     transaction.commit()
     dupe_message = MessageSet().fromEmail(email.as_string())
     self.assertNotEqual(orig_message.id, dupe_message.id)
コード例 #2
0
 def test_fromEmail_decodes_macintosh_encoding(self):
     """"macintosh encoding is equivalent to MacRoman."""
     high_decoded = self.high_characters.decode('macroman')
     email = self.makeEncodedEmail('macintosh', 'macroman')
     message = MessageSet().fromEmail(email.as_string())
     self.assertEqual(high_decoded, message.subject)
     self.assertEqual(high_decoded, message.text_contents)
コード例 #3
0
 def test_fromEmail_decodes_booga_encoding(self):
     """"'booga' encoding is decoded as latin-1."""
     high_decoded = self.high_characters.decode('latin-1')
     email = self.makeEncodedEmail('booga', 'latin-1')
     message = MessageSet().fromEmail(email.as_string())
     self.assertEqual(high_decoded, message.subject)
     self.assertEqual(high_decoded, message.text_contents)
コード例 #4
0
 def test_fromEmail_restricted_attachments(self):
     """fromEmail creates restricted attachments correctly."""
     msg = self._makeMessageWithAttachment()
     message = MessageSet().fromEmail(msg.as_string(), restricted=True)
     text, diff = message.chunks
     self.assertEqual('review.diff', diff.blob.filename)
     self.assertTrue('review.diff', diff.blob.restricted)
コード例 #5
0
 def _makeCommentFromEmailWithAttachment(self, filename, content_type):
     # Make an email message with an attachment, and create a code
     # review comment from it.
     msg = self.factory.makeEmailMessage(
         body='This is the body of the email.',
         attachments=[
             (filename, content_type, 'Attachment body')])
     message = MessageSet().fromEmail(msg.as_string())
     return self.bmp.createCommentFromMessage(message, None, None, msg)
コード例 #6
0
 def test_process(self):
     """Processing an email creates an appropriate CodeReviewComment."""
     mail = self.factory.makeSignedMessage('<my-id>')
     bmp = self.factory.makeBranchMergeProposal()
     email_addr = bmp.address
     switch_dbuser(config.processmail.dbuser)
     self.assertTrue(self.code_handler.process(
         mail, email_addr, None), "Succeeded, but didn't return True")
     # if the message has not been created, this raises SQLObjectNotFound
     MessageSet().get('<my-id>')
コード例 #7
0
 def test_oops_in_messagechunk(self):
     oopsid = "OOPS-abcdef1234"
     MessageSet().fromText('foo', "foo %s bar" % oopsid)
     self.store.flush()
     now = datetime.now(tz=utc)
     day = timedelta(days=1)
     self.failUnlessEqual(set([oopsid]),
                          referenced_oops(now - day, now, "product=1", {}))
     self.failUnlessEqual(
         set(), referenced_oops(now + day, now + day, "product=1", {}))
コード例 #8
0
 def test_fromEmail_restricted_reuploads(self):
     """fromEmail will re-upload the email to the restricted librarian if
     restricted is True."""
     filealias = self.factory.makeLibraryFileAlias()
     transaction.commit()
     email = self.factory.makeEmailMessage()
     message = MessageSet().fromEmail(email.as_string(),
                                      filealias=filealias,
                                      restricted=True)
     self.assertTrue(message.raw.restricted)
     self.assertNotEqual(message.raw.id, filealias.id)
コード例 #9
0
 def test_oops_in_messagesubject(self):
     oopsid = "OOPS-abcdef1234"
     self.factory.makeEmailMessage()
     MessageSet().fromText("Crash with %s" % oopsid, "body")
     self.store.flush()
     now = datetime.now(tz=utc)
     day = timedelta(days=1)
     self.failUnlessEqual(set([oopsid]),
                          referenced_oops(now - day, now, "product=1", {}))
     self.failUnlessEqual(
         set(), referenced_oops(now + day, now + day, "product=1", {}))
コード例 #10
0
 def test_fromEmail_strips_attachment_paths(self):
     # Build a simple multipart message with a plain text first part
     # and an text/x-diff attachment.
     msg = self._makeMessageWithAttachment(filename='/tmp/foo/review.diff')
     # Now create the message from the MessageSet.
     message = MessageSet().fromEmail(msg.as_string())
     text, diff = message.chunks
     self.assertEqual('This is the body of the email.', text.content)
     self.assertEqual('review.diff', diff.blob.filename)
     self.assertEqual('text/x-diff', diff.blob.mimetype)
     # Need to commit in order to read back out of the librarian.
     transaction.commit()
     self.assertEqual('This is the diff, honest.', diff.blob.read())
コード例 #11
0
 def test_addNotification_without_recipients(self):
     # We can call BugNotificationSet.addNotification() with a empty
     # recipient list.
     #
     # No explicit assertion is necessary in this test -- we just want
     # to be sure that calling BugNotificationSet.addNotification()
     # does not lead to an exception caused by an SQL syntax error for
     # a command that ends with "VALUES ;"
     bug = self.factory.makeBug()
     message = MessageSet().fromText(subject='subject', content='content')
     BugNotificationSet().addNotification(bug=bug,
                                          is_comment=False,
                                          message=message,
                                          recipients=[],
                                          activity=None)