Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: tests/git_cl_test.py

Issue 2007873002: Gerrit git cl upload: obey -s --send-mail option. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: shorter Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for git_cl.py.""" 6 """Unit tests for git_cl.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import stat 10 import stat
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 ((['git', 'config', 'user.email'],), 'me@example.com'), 751 ((['git', 'config', 'user.email'],), 'me@example.com'),
752 ((['git', 752 ((['git',
753 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 753 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
754 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), 754 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
755 '+dat'), 755 '+dat'),
756 ] 756 ]
757 757
758 @classmethod 758 @classmethod
759 def _gerrit_upload_calls(cls, description, reviewers, squash, 759 def _gerrit_upload_calls(cls, description, reviewers, squash,
760 expected_upstream_ref='origin/refs/heads/master', 760 expected_upstream_ref='origin/refs/heads/master',
761 ref_suffix='', 761 ref_suffix='', notify=False,
762 post_amend_description=None, issue=None): 762 post_amend_description=None, issue=None):
763 if post_amend_description is None: 763 if post_amend_description is None:
764 post_amend_description = description 764 post_amend_description = description
765 765
766 calls = [ 766 calls = [
767 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), 767 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'),
768 ] 768 ]
769 # If issue is given, then description is fetched from Gerrit instead. 769 # If issue is given, then description is fetched from Gerrit instead.
770 if issue is None: 770 if issue is None:
771 if squash: 771 if squash:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 ((['git', 'rev-list', 820 ((['git', 'rev-list',
821 expected_upstream_ref + '..' + ref_to_push],), ''), 821 expected_upstream_ref + '..' + ref_to_push],), ''),
822 ((['git', 'config', 'rietveld.cc'],), '') 822 ((['git', 'config', 'rietveld.cc'],), '')
823 ] 823 ]
824 # Add cc from watch list. 824 # Add cc from watch list.
825 # TODO(tandrii): bring this back after http://crbug.com/604377. 825 # TODO(tandrii): bring this back after http://crbug.com/604377.
826 # if ref_suffix == '': 826 # if ref_suffix == '':
827 # ref_suffix = '%cc=joe@example.com' 827 # ref_suffix = '%cc=joe@example.com'
828 # else: 828 # else:
829 # ref_suffix += ',cc=joe@example.com' 829 # ref_suffix += ',cc=joe@example.com'
830
831 notify_suffix = 'notify=%s' % ('ALL' if notify else 'NONE')
832 if ref_suffix:
833 ref_suffix += ',' + notify_suffix
834 else:
835 ref_suffix = '%' + notify_suffix
830 if reviewers: 836 if reviewers:
831 if ref_suffix: 837 ref_suffix += ',' + ','.join('r=%s' % email
832 ref_suffix += ',' 838 for email in sorted(reviewers))
833 else:
834 ref_suffix = '%'
835 ref_suffix += ','.join('r=%s' % email for email in sorted(reviewers))
836 calls += [ 839 calls += [
837 ((['git', 'push', 'origin', 840 ((['git', 'push', 'origin',
838 ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],), 841 ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],),
839 ('remote:\n' 842 ('remote:\n'
840 'remote: Processing changes: (\)\n' 843 'remote: Processing changes: (\)\n'
841 'remote: Processing changes: (|)\n' 844 'remote: Processing changes: (|)\n'
842 'remote: Processing changes: (/)\n' 845 'remote: Processing changes: (/)\n'
843 'remote: Processing changes: (-)\n' 846 'remote: Processing changes: (-)\n'
844 'remote: Processing changes: new: 1 (/)\n' 847 'remote: Processing changes: new: 1 (/)\n'
845 'remote: Processing changes: new: 1, done\n' 848 'remote: Processing changes: new: 1, done\n'
(...skipping 16 matching lines...) Expand all
862 return calls 865 return calls
863 866
864 def _run_gerrit_upload_test( 867 def _run_gerrit_upload_test(
865 self, 868 self,
866 upload_args, 869 upload_args,
867 description, 870 description,
868 reviewers=None, 871 reviewers=None,
869 squash=False, 872 squash=False,
870 expected_upstream_ref='origin/refs/heads/master', 873 expected_upstream_ref='origin/refs/heads/master',
871 ref_suffix='', 874 ref_suffix='',
875 notify=False,
872 post_amend_description=None, 876 post_amend_description=None,
873 issue=None): 877 issue=None):
874 """Generic gerrit upload test framework.""" 878 """Generic gerrit upload test framework."""
875 reviewers = reviewers or [] 879 reviewers = reviewers or []
876 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 880 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
877 self.mock(git_cl.gerrit_util, "CookiesAuthenticator", 881 self.mock(git_cl.gerrit_util, "CookiesAuthenticator",
878 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) 882 CookiesAuthenticatorMockFactory(same_cookie='same_cred'))
879 self.calls = self._gerrit_base_calls(issue=issue) 883 self.calls = self._gerrit_base_calls(issue=issue)
880 self.calls += self._gerrit_upload_calls( 884 self.calls += self._gerrit_upload_calls(
881 description, reviewers, squash, 885 description, reviewers, squash,
882 expected_upstream_ref=expected_upstream_ref, 886 expected_upstream_ref=expected_upstream_ref,
883 ref_suffix=ref_suffix, 887 ref_suffix=ref_suffix, notify=notify,
884 post_amend_description=post_amend_description, 888 post_amend_description=post_amend_description,
885 issue=issue) 889 issue=issue)
886 # Uncomment when debugging. 890 # Uncomment when debugging.
887 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) 891 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))
888 git_cl.main(['upload'] + upload_args) 892 git_cl.main(['upload'] + upload_args)
889 893
890 def test_gerrit_upload_without_change_id(self): 894 def test_gerrit_upload_without_change_id(self):
891 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) 895 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call)
892 self._run_gerrit_upload_test( 896 self._run_gerrit_upload_test(
893 [], 897 [],
894 'desc\n\nBUG=\n', 898 'desc\n\nBUG=\n',
895 [], 899 [],
896 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') 900 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx')
897 901
898 def test_gerrit_no_reviewer(self): 902 def test_gerrit_no_reviewer(self):
899 self._run_gerrit_upload_test( 903 self._run_gerrit_upload_test(
900 [], 904 [],
901 'desc\n\nBUG=\n\nChange-Id: I123456789\n', 905 'desc\n\nBUG=\n\nChange-Id: I123456789\n',
902 []) 906 [])
903 907
904 def test_gerrit_patch_title(self): 908 def test_gerrit_patch_title(self):
905 self._run_gerrit_upload_test( 909 self._run_gerrit_upload_test(
906 ['-t', 'Don\'t put under_scores as they become spaces'], 910 ['-t', 'Don\'t put under_scores as they become spaces'],
907 'desc\n\nBUG=\n\nChange-Id: I123456789', 911 'desc\n\nBUG=\n\nChange-Id: I123456789',
908 ref_suffix='%m=Don\'t_put_under_scores_as_they_become_spaces') 912 ref_suffix='%m=Don\'t_put_under_scores_as_they_become_spaces')
909 913
910 def test_gerrit_reviewers_cmd_line(self): 914 def test_gerrit_reviewers_cmd_line(self):
911 self._run_gerrit_upload_test( 915 self._run_gerrit_upload_test(
912 ['-r', 'foo@example.com'], 916 ['-r', 'foo@example.com', '--send-mail'],
913 'desc\n\nBUG=\n\nChange-Id: I123456789', 917 'desc\n\nBUG=\n\nChange-Id: I123456789',
914 ['foo@example.com']) 918 ['foo@example.com'],
919 notify=True)
915 920
916 def test_gerrit_reviewer_multiple(self): 921 def test_gerrit_reviewer_multiple(self):
917 self._run_gerrit_upload_test( 922 self._run_gerrit_upload_test(
918 [], 923 [],
919 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n\n' 924 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n\n'
920 'Change-Id: 123456789\n', 925 'Change-Id: 123456789\n',
921 ['reviewer@example.com', 'another@example.com']) 926 ['reviewer@example.com', 'another@example.com'])
922 927
923 def test_gerrit_upload_squash_first(self): 928 def test_gerrit_upload_squash_first(self):
924 # Mock Gerrit CL description to indicate the first upload. 929 # Mock Gerrit CL description to indicate the first upload.
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) 1452 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman'))
1448 1453
1449 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) 1454 self.assertEqual(0, git_cl.main(['description', '-n', '-']))
1450 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) 1455 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
1451 1456
1452 1457
1453 if __name__ == '__main__': 1458 if __name__ == '__main__':
1454 git_cl.logging.basicConfig( 1459 git_cl.logging.basicConfig(
1455 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1460 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1456 unittest.main() 1461 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698