OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Unit tests for verification/authors_white_list.py.""" | |
7 | |
8 import os | |
9 import sys | |
10 import unittest | |
11 | |
12 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
13 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) | |
14 | |
15 from verification import base | |
16 from verification import authors_white_list | |
17 | |
18 # From tests/ | |
19 import mocks | |
20 | |
21 | |
22 class AuthorTest(mocks.TestCase): | |
23 def test_rejected(self): | |
24 self.pending.owner = 'georges@micro.com' | |
25 self._check( | |
26 'Can\'t commit because the owner %s not in whitelist' % | |
27 self.pending.owner) | |
28 | |
29 def test_allowed(self): | |
30 self.pending.owner = 'georges@example.com' | |
31 self._check(None) | |
32 | |
33 def _check(self, error_message): | |
34 ver = authors_white_list.AuthorVerifier([r'^[\-\w]+\@example\.com$']) | |
35 ver.verify(self.pending) | |
36 ver.update_status([self.pending]) | |
37 name = authors_white_list.AuthorVerifier.name | |
38 self.assertEqual(self.pending.verifications.keys(), [name]) | |
39 self.assertEqual( | |
40 self.pending.verifications[name].error_message, error_message) | |
41 if error_message: | |
42 self.assertEqual( | |
43 self.pending.verifications[name].get_state(), base.FAILED) | |
44 else: | |
45 self.assertEqual( | |
46 self.pending.verifications[name].get_state(), base.SUCCEEDED) | |
47 | |
48 | |
49 if __name__ == '__main__': | |
50 unittest.main() | |
OLD | NEW |