OLD | NEW |
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 presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 # pylint: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 |
9 | 9 |
10 import StringIO | 10 import StringIO |
(...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2718 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2718 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2719 gerrit_response=response, | 2719 gerrit_response=response, |
2720 is_committing=True, | 2720 is_committing=True, |
2721 expected_output='') | 2721 expected_output='') |
2722 | 2722 |
2723 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2723 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2724 is_committing=False, | 2724 is_committing=False, |
2725 gerrit_response=response, | 2725 gerrit_response=response, |
2726 expected_output='') | 2726 expected_output='') |
2727 | 2727 |
| 2728 # Testing configuration with on -1..+1. |
| 2729 response = { |
| 2730 "owner": {"email": "john@example.com"}, |
| 2731 "labels": {"Code-Review": { |
| 2732 u'all': [ |
| 2733 { |
| 2734 u'email': u'ben@example.com', |
| 2735 u'value': 1 |
| 2736 }, |
| 2737 ], |
| 2738 u'approved': {u'email': u'ben@example.org'}, |
| 2739 u'default_value': 0, |
| 2740 u'values': {u' 0': u'No score', |
| 2741 u'+1': u'Looks good to me', |
| 2742 u'-1': u"I would prefer that you didn't submit this"} |
| 2743 }}, |
| 2744 } |
| 2745 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
| 2746 gerrit_response=response, |
| 2747 is_committing=True, |
| 2748 expected_output='') |
| 2749 |
| 2750 |
2728 def testCannedCheckOwners_Approved(self): | 2751 def testCannedCheckOwners_Approved(self): |
2729 response = { | 2752 response = { |
2730 "owner_email": "john@example.com", | 2753 "owner_email": "john@example.com", |
2731 "messages": [ | 2754 "messages": [ |
2732 { | 2755 { |
2733 "sender": "ben@example.com", "text": "foo", "approval": True, | 2756 "sender": "ben@example.com", "text": "foo", "approval": True, |
2734 }, | 2757 }, |
2735 ], | 2758 ], |
2736 "reviewers": ["ben@example.com"], | 2759 "reviewers": ["ben@example.com"], |
2737 } | 2760 } |
2738 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2761 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2739 rietveld_response=response, | 2762 rietveld_response=response, |
2740 expected_output='') | 2763 expected_output='') |
2741 | 2764 |
2742 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2765 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2743 is_committing=False, | 2766 is_committing=False, |
2744 rietveld_response=response, | 2767 rietveld_response=response, |
2745 expected_output='') | 2768 expected_output='') |
2746 | 2769 |
| 2770 def testCannedCheckOwners_NotApproved_Gerrit(self): |
| 2771 response = { |
| 2772 "owner": {"email": "john@example.com"}, |
| 2773 "labels": {"Code-Review": { |
| 2774 u'all': [ |
| 2775 { |
| 2776 u'email': u'john@example.com', # self +1 :) |
| 2777 u'value': 1 |
| 2778 }, |
| 2779 { |
| 2780 u'email': u'ben@example.com', |
| 2781 u'value': 1 |
| 2782 }, |
| 2783 ], |
| 2784 u'approved': {u'email': u'ben@example.org'}, |
| 2785 u'default_value': 0, |
| 2786 u'values': {u' 0': u'No score', |
| 2787 u'+1': u'Looks good to me, but someone else must approve', |
| 2788 u'+2': u'Looks good to me, approved', |
| 2789 u'-1': u"I would prefer that you didn't submit this", |
| 2790 u'-2': u'Do not submit'} |
| 2791 }}, |
| 2792 } |
| 2793 self.AssertOwnersWorks( |
| 2794 approvers=set(), |
| 2795 reviewers=set(["ben@example.com"]), |
| 2796 gerrit_response=response, |
| 2797 is_committing=True, |
| 2798 expected_output= |
| 2799 'Missing LGTM from someone other than john@example.com\n') |
| 2800 |
| 2801 self.AssertOwnersWorks( |
| 2802 approvers=set(), |
| 2803 reviewers=set(["ben@example.com"]), |
| 2804 is_committing=False, |
| 2805 gerrit_response=response, |
| 2806 expected_output='') |
| 2807 |
| 2808 # Testing configuration with on -1..+1. |
| 2809 response = { |
| 2810 "owner": {"email": "john@example.com"}, |
| 2811 "labels": {"Code-Review": { |
| 2812 u'all': [ |
| 2813 { |
| 2814 u'email': u'ben@example.com', |
| 2815 u'value': 0 |
| 2816 }, |
| 2817 ], |
| 2818 u'approved': {u'email': u'ben@example.org'}, |
| 2819 u'default_value': 0, |
| 2820 u'values': {u' 0': u'No score', |
| 2821 u'+1': u'Looks good to me', |
| 2822 u'-1': u"I would prefer that you didn't submit this"} |
| 2823 }}, |
| 2824 } |
| 2825 self.AssertOwnersWorks( |
| 2826 approvers=set(), |
| 2827 reviewers=set(["ben@example.com"]), |
| 2828 gerrit_response=response, |
| 2829 is_committing=True, |
| 2830 expected_output= |
| 2831 'Missing LGTM from someone other than john@example.com\n') |
| 2832 |
2747 def testCannedCheckOwners_NotApproved(self): | 2833 def testCannedCheckOwners_NotApproved(self): |
2748 response = { | 2834 response = { |
2749 "owner_email": "john@example.com", | 2835 "owner_email": "john@example.com", |
2750 "messages": [ | 2836 "messages": [ |
2751 { | 2837 { |
2752 "sender": "ben@example.com", "text": "foo", "approval": False, | 2838 "sender": "ben@example.com", "text": "foo", "approval": False, |
2753 }, | 2839 }, |
2754 ], | 2840 ], |
2755 "reviewers": ["ben@example.com"], | 2841 "reviewers": ["ben@example.com"], |
2756 } | 2842 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2964 owners_check=False) | 3050 owners_check=False) |
2965 self.assertEqual(2, len(results)) | 3051 self.assertEqual(2, len(results)) |
2966 self.assertEqual( | 3052 self.assertEqual( |
2967 'Found line ending with white spaces in:', results[0]._message) | 3053 'Found line ending with white spaces in:', results[0]._message) |
2968 self.checkstdout('') | 3054 self.checkstdout('') |
2969 | 3055 |
2970 | 3056 |
2971 if __name__ == '__main__': | 3057 if __name__ == '__main__': |
2972 import unittest | 3058 import unittest |
2973 unittest.main() | 3059 unittest.main() |
OLD | NEW |