Make --send-mail more useful by not requiring -r

Previously, --send-mail required -r to pass. Now it uses the R=|TBR= lines from
the description, which is much more useful.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/8735018

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@112221 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index f21e340..b2f3e19 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -6,6 +6,7 @@
 """Unit tests for git_cl.py."""
 
 import os
+import StringIO
 import sys
 import unittest
 
@@ -69,8 +70,12 @@
       self.assertEquals([], self.calls)
     super(TestGitCl, self).tearDown()
 
+  @classmethod
+  def _upload_calls(cls):
+    return cls._git_base_calls() + cls._git_upload_calls()
+
   @staticmethod
-  def _upload_calls():
+  def _git_base_calls():
     return [
         (['git', 'update-index', '--refresh', '-q'], ''),
         (['git', 'diff-index', 'HEAD'], ''),
@@ -89,6 +94,11 @@
         (['git', 'config', 'user.email'], 'me@example.com'),
         (['git', 'diff', '--no-ext-diff', '--stat', '-M', 'master...'], '+dat'),
         (['git', 'log', '--pretty=format:%s\n\n%b', 'master..'], 'desc\n'),
+    ]
+
+  @staticmethod
+  def _git_upload_calls():
+    return [
         (['git', 'config', 'rietveld.cc'], ''),
         (['git', 'config', '--get-regexp', '^svn-remote\\.'], (('', None), 0)),
         (['git', 'rev-parse', '--show-cdup'], ''),
@@ -177,6 +187,36 @@
         description,
         ['--reviewers', 'reviewer@example.com,another@example.com'])
 
+  def test_reviewer_send_mail(self):
+    # --send-mail can be used without -r if R= is used
+    description = 'Foo Bar\nR=reviewer@example.com\n'
+    self._run_reviewer_test(
+        ['--send-mail'],
+        'desc\n\nBUG=\nTEST=\n',
+        description.strip('\n'),
+        description,
+        ['--reviewers', 'reviewer@example.com', '--send_mail'])
+
+  def test_reviewer_send_mail_no_rev(self):
+    # Fails without a reviewer.
+    class FileMock(object):
+      buf = StringIO.StringIO()
+      def write(self, content):
+        self.buf.write(content)
+
+    mock = FileMock()
+    try:
+      self.calls = self._git_base_calls()
+      def RunEditor(desc, _):
+        return desc
+      self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
+      self.mock(sys, 'stderr', mock)
+      git_cl.main(['upload', '--send-mail'])
+      self.fail()
+    except SystemExit:
+      self.assertEquals(
+          'Must specify reviewers to send email.\n', mock.buf.getvalue())
+
 
 if __name__ == '__main__':
   unittest.main()