1058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# Copyright (C) 2009 Google Inc. All rights reserved.
2058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#
3058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# Redistribution and use in source and binary forms, with or without
4058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# modification, are permitted provided that the following conditions are
5058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# met:
6058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#
7058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#    * Redistributions of source code must retain the above copyright
8058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# notice, this list of conditions and the following disclaimer.
9058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#    * Redistributions in binary form must reproduce the above
10058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# copyright notice, this list of conditions and the following disclaimer
11058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# in the documentation and/or other materials provided with the
12058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# distribution.
13058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#    * Neither the name of Google Inc. nor the names of its
14058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# contributors may be used to endorse or promote products derived from
15058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# this software without specific prior written permission.
16058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu#
17058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
29058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescuimport unittest
30dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.common.config.committers import CommitterList, Committer, Reviewer
31058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
32058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescuclass CommittersTest(unittest.TestCase):
33058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
34058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu    def test_committer_lookup(self):
35dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        committer = Committer('Test One', 'one@test.com', 'one')
36643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        reviewer = Reviewer('Test Two', ['two@test.com', 'two@rad.com', 'so_two@gmail.com'])
37058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu        committer_list = CommitterList(committers=[committer], reviewers=[reviewer])
38058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
39058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu        # Test valid committer and reviewer lookup
40643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.committer_by_email('one@test.com'), committer)
41643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.reviewer_by_email('two@test.com'), reviewer)
42643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.committer_by_email('two@test.com'), reviewer)
43643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.committer_by_email('two@rad.com'), reviewer)
44643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.reviewer_by_email('so_two@gmail.com'), reviewer)
45058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
46dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        # Test valid committer and reviewer lookup
47dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        self.assertEqual(committer_list.committer_by_name("Test One"), committer)
48dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        self.assertEqual(committer_list.committer_by_name("Test Two"), reviewer)
49dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        self.assertEqual(committer_list.committer_by_name("Test Three"), None)
50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
51d0825bca7fe65beaee391d30da42e937db621564Steve Block        # Test that the first email is assumed to be the Bugzilla email address (for now)
52d0825bca7fe65beaee391d30da42e937db621564Steve Block        self.assertEqual(committer_list.committer_by_email('two@rad.com').bugzilla_email(), 'two@test.com')
53d0825bca7fe65beaee391d30da42e937db621564Steve Block
54058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu        # Test that a known committer is not returned during reviewer lookup
55643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.reviewer_by_email('one@test.com'), None)
56058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
57058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu        # Test that unknown email address fail both committer and reviewer lookup
58643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.committer_by_email('bar@bar.com'), None)
59643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.reviewer_by_email('bar@bar.com'), None)
60643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
61643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        # Test that emails returns a list.
62643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer.emails, ['one@test.com'])
63643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
64dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        self.assertEqual(committer.irc_nickname, 'one')
65dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
66643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        # Test that committers returns committers and reviewers and reviewers() just reviewers.
67643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.committers(), [committer, reviewer])
68643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        self.assertEqual(committer_list.reviewers(), [reviewer])
69643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
70058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu
71058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescuif __name__ == '__main__':
72058ccc7ba0a4d59b9f6e92808332aa9895425fc7Andrei Popescu    unittest.main()
73