OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Unit tests for the component_helpers module.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from proto import tracker_pb2 |
| 11 from services import service_manager |
| 12 from testing import fake |
| 13 from tracker import component_helpers |
| 14 from tracker import tracker_bizobj |
| 15 |
| 16 |
| 17 class ComponentHelpersTest(unittest.TestCase): |
| 18 |
| 19 def setUp(self): |
| 20 self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) |
| 21 self.cd1 = tracker_bizobj.MakeComponentDef( |
| 22 1, 789, 'FrontEnd', 'doc', False, [], [111L], 0, 0) |
| 23 self.cd2 = tracker_bizobj.MakeComponentDef( |
| 24 2, 789, 'FrontEnd>Splash', 'doc', False, [], [222L], 0, 0) |
| 25 self.cd3 = tracker_bizobj.MakeComponentDef( |
| 26 3, 789, 'BackEnd', 'doc', True, [], [111L, 333L], 0, 0) |
| 27 self.config.component_defs = [self.cd1, self.cd2, self.cd3] |
| 28 self.services = service_manager.Services( |
| 29 user=fake.UserService()) |
| 30 self.services.user.TestAddUser('a@example.com', 111L) |
| 31 self.services.user.TestAddUser('b@example.com', 222L) |
| 32 self.services.user.TestAddUser('c@example.com', 333L) |
| 33 self.mr = fake.MonorailRequest() |
| 34 self.mr.cnxn = fake.MonorailConnection() |
| 35 |
| 36 def testParseComponentRequest_Empty(self): |
| 37 post_data = fake.PostData(admins=[''], cc=['']) |
| 38 parsed = component_helpers.ParseComponentRequest( |
| 39 self.mr, post_data, self.services.user) |
| 40 self.assertEqual('', parsed.leaf_name) |
| 41 self.assertEqual('', parsed.docstring) |
| 42 self.assertEqual([], parsed.admin_usernames) |
| 43 self.assertEqual([], parsed.cc_usernames) |
| 44 self.assertEqual([], parsed.admin_ids) |
| 45 self.assertEqual([], parsed.cc_ids) |
| 46 self.assertFalse(self.mr.errors.AnyErrors()) |
| 47 |
| 48 def testParseComponentRequest_Normal(self): |
| 49 post_data = fake.PostData( |
| 50 leaf_name=['FrontEnd'], |
| 51 docstring=['The server-side app that serves pages'], |
| 52 deprecated=[False], |
| 53 admins=['a@example.com'], |
| 54 cc=['b@example.com, c@example.com']) |
| 55 parsed = component_helpers.ParseComponentRequest( |
| 56 self.mr, post_data, self.services.user) |
| 57 self.assertEqual('FrontEnd', parsed.leaf_name) |
| 58 self.assertEqual('The server-side app that serves pages', parsed.docstring) |
| 59 self.assertEqual(['a@example.com'], parsed.admin_usernames) |
| 60 self.assertEqual(['b@example.com', 'c@example.com'], parsed.cc_usernames) |
| 61 self.assertEqual([111L], parsed.admin_ids) |
| 62 self.assertEqual([222L, 333L], parsed.cc_ids) |
| 63 self.assertFalse(self.mr.errors.AnyErrors()) |
| 64 |
| 65 def testParseComponentRequest_InvalidUser(self): |
| 66 post_data = fake.PostData( |
| 67 leaf_name=['FrontEnd'], |
| 68 docstring=['The server-side app that serves pages'], |
| 69 deprecated=[False], |
| 70 admins=['a@example.com, invalid_user'], |
| 71 cc=['b@example.com, c@example.com']) |
| 72 parsed = component_helpers.ParseComponentRequest( |
| 73 self.mr, post_data, self.services.user) |
| 74 self.assertEqual('FrontEnd', parsed.leaf_name) |
| 75 self.assertEqual('The server-side app that serves pages', parsed.docstring) |
| 76 self.assertEqual(['a@example.com', 'invalid_user'], parsed.admin_usernames) |
| 77 self.assertEqual(['b@example.com', 'c@example.com'], parsed.cc_usernames) |
| 78 self.assertEqual([111L], parsed.admin_ids) |
| 79 self.assertEqual([222L, 333L], parsed.cc_ids) |
| 80 self.assertTrue(self.mr.errors.AnyErrors()) |
| 81 self.assertEqual('invalid_user unrecognized', self.mr.errors.member_admins) |
| 82 |
| 83 def testGetComponentCcIDs(self): |
| 84 issue = tracker_pb2.Issue() |
| 85 issues_components_cc_ids = component_helpers.GetComponentCcIDs( |
| 86 issue, self.config) |
| 87 self.assertEqual(set(), issues_components_cc_ids) |
| 88 |
| 89 issue.component_ids = [1, 2] |
| 90 issues_components_cc_ids = component_helpers.GetComponentCcIDs( |
| 91 issue, self.config) |
| 92 self.assertEqual({111L, 222L}, issues_components_cc_ids) |
| 93 |
| 94 def testGetCcIDsForComponentAndAncestors(self): |
| 95 components_cc_ids = component_helpers.GetCcIDsForComponentAndAncestors( |
| 96 self.config, self.cd1) |
| 97 self.assertEqual({111L}, components_cc_ids) |
| 98 |
| 99 components_cc_ids = component_helpers.GetCcIDsForComponentAndAncestors( |
| 100 self.config, self.cd2) |
| 101 self.assertEqual({111L, 222L}, components_cc_ids) |
| 102 |
| 103 components_cc_ids = component_helpers.GetCcIDsForComponentAndAncestors( |
| 104 self.config, self.cd3) |
| 105 self.assertEqual({111L, 333L}, components_cc_ids) |
| 106 |
| 107 |
| 108 if __name__ == '__main__': |
| 109 unittest.main() |
OLD | NEW |