def testFormatURLWithKeywordArgsAndID(self): params = {} query_pairs = [] query_pairs.append('id=200') # id should be the first parameter. for name in framework_helpers.RECOGNIZED_PARAMS: params[name] = name if name != 'can' and name != 'start': query_pairs.append('%s=%s' % (name, 123)) path = '/dude/wheres/my/car' mr = testing_helpers.MakeMonorailRequest(path='%s?%s' % (path, '&'.join(query_pairs))) query_pairs.append('can=yep') query_pairs.append('start=486') query_string = '&'.join(query_pairs) expected = '%s?%s' % (path, query_string) recognized_params = [(name, mr.GetParam(name)) for name in framework_helpers.RECOGNIZED_PARAMS] url = framework_helpers.FormatURL(recognized_params, path, can='yep', start=486, id=200) self.assertEqual(expected, url)
def testNotifyBlockingChangeTask_Spam(self): issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1, is_spam=True) self.services.issue.TestAddIssue(issue2) task = notify.NotifyBlockingChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': issue2.issue_id, 'seq': 0, 'delta_blocker_iids': self.issue1.issue_id, 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertEquals(0, len(result['notified']))
def testProcessFormData_Bad(self): mr = testing_helpers.MakeMonorailRequest( hotlist=self.hotlist, path='/u/111/hotlists/%s/details' % (self.hotlist.hotlist_id), services=service_manager.Services(user=self.user_service)) post_data = fake.PostData(summary=['hotlist summary'], name=['2badName'], description=['fake description'], default_col_spec=['test default col spec']) self.mox.StubOutWithMock(self.servlet, 'PleaseCorrect') self.servlet.PleaseCorrect( mr, initial_summary='hotlist summary', initial_description='fake description', initial_name='2badName', initial_default_col_spec='test default col spec') self.mox.ReplayAll() url = self.servlet.ProcessFormData(mr, post_data) self.mox.VerifyAll() self.assertEqual(hotlistdetails._MSG_INVALID_HOTLIST_NAME, mr.errors.name) self.assertIsNone(url)
def testProcessFormData_DuplicateStatus_MergeMissingIssue(self): """Test PFD processes null/cleared status values.""" local_id_1 = self.services.issue.CreateIssue( self.cnxn, self.services, self.project.project_id, 'issue summary', 'New', 111L, [], [], [], [], 111L, 'test issue') local_id_2 = self.services.issue.CreateIssue( self.cnxn, self.services, self.project.project_id, 'issue summary2', 'New', 112L, [], [], [], [], 112L, 'test issue2') mr = testing_helpers.MakeMonorailRequest( project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET, user_info={'user_id': 111}) mr.local_id_list = [local_id_1, local_id_2] mr.project_name = 'proj' post_data = fake.PostData(status=['Duplicate'], merge_into=['non existant id'], owner=['*****@*****.**'], can=[1], q=[''], colspec=[''], sort=[''], groupby=[''], start=[0], num=[100]) self._MockMethods() self.servlet.ProcessFormData(mr, post_data) self.assertEquals('Please enter an issue ID', mr.errors.merge_into_id)
def testHandleBackendSearchResponse_500(self): response_str = 'There was a problem processing the query.' rpc = testing_helpers.Blank(get_result=lambda: testing_helpers.Blank( content=response_str, status_code=500)) rpc_tuple = (NOW, 2, rpc) rpc_tuples = [] # Nothing should be added for this case. filtered_iids = {} # Search results should accumlate here, per-shard. search_limit_reached = {} # Booleans accumulate here, per-shard. processed_invalidations_up_to = 12345 mr = testing_helpers.MakeMonorailRequest( path='/p/proj/issues/list?q=foo') mr.me_user_id = 111L error_responses = set() self.mox.StubOutWithMock(frontendsearchpipeline, '_StartBackendSearchCall') frontendsearchpipeline._HandleBackendSearchResponse( mr, ['proj'], rpc_tuple, rpc_tuples, 0, filtered_iids, search_limit_reached, processed_invalidations_up_to, error_responses) self.assertEqual([], rpc_tuples) self.assertIn(2, error_responses)
def testNotifyBlockingChangeTask_Normal(self): issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1) self.services.issue.TestAddIssue(issue2) task = notify.NotifyBlockingChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': issue2.issue_id, 'seq': 0, 'delta_blocker_iids': self.issue1.issue_id, 'commenter_id': 1, 'hostport': 'bugs.chromium.org' } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.VerifyParams(result, params)
def testProcessFormData_CustomFields(self): """Test PFD processes edits to custom fields.""" local_id_1 = self.services.issue.CreateIssue( self.cnxn, self.services, 789, 'issue summary', 'New', 111L, [], [], [], [], 111L, 'test issue') mr = testing_helpers.MakeMonorailRequest( project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET, user_info={'user_id': 111}) mr.local_id_list = [local_id_1] fd = tracker_bizobj.MakeFieldDef( 12345, 789, 'CPU', tracker_pb2.FieldTypes.INT_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False) self.config.field_defs.append(fd) post_data = fake.PostData( custom_12345=['111'], owner=['*****@*****.**'], can=[1], q=[''], colspec=[''], sort=[''], groupby=[''], start=[0], num=[100]) self._MockMethods() self.servlet.ProcessFormData(mr, post_data) self.assertTrue(self.VerifyIssueUpdated(789, local_id_1))
def testGatherPageData_MissingDefaultTemplates(self): """If the default templates were deleted, pick the first template.""" mr = testing_helpers.MakeMonorailRequest( path='/p/proj/issues/entry', services=self.services) mr.auth.user_view = framework_views.StuffUserView(100, 'user@invalid', True) user = self.services.user.TestAddUser('user@invalid', 100) self.services.template.GetTemplateSetForProject = Mock( return_value=[(1, 'one', False), (2, 'two', True)]) self.services.template.GetTemplateById.return_value = None self.services.template.GetProjectTemplates.return_value = [ tracker_pb2.TemplateDef(members_only=True), tracker_pb2.TemplateDef(members_only=False)] self.mox.StubOutWithMock(self.services.user, 'GetUser') self.services.user.GetUser( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user) self.mox.ReplayAll() page_data = self.servlet.GatherPageData(mr) self.mox.VerifyAll() self.assertTrue(self.services.template.GetProjectTemplates.called) self.assertTrue(page_data['config'].template_view.members_only)
def testNotifyBulkChangeTask_AlsoNotify(self): """We generate email tasks for also-notify addresses.""" self.issue1.derived_notify_addrs = [ '*****@*****.**', '*****@*****.**' ] task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'seq': 0, 'issue_ids': '%d' % (self.issue1.issue_id), 'old_owner_ids': '1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(3, len(tasks)) self.assertItemsEqual([ '*****@*****.**', '*****@*****.**', '*****@*****.**' ], result['notified']) for task in tasks: task_params = json.loads(task.payload) # obfuscated email for non-members if 'user' in task_params['to']: self.assertIn(u'\u2026', task_params['from_addr']) # Full email for members if 'member' in task_params['to']: self.assertNotIn(u'\u2026', task_params['from_addr'])
def testGatherProjects(self): self.services.user.TestAddUser('testuser', 1L) self.services.user.TestAddUser('otheruser', 2L) self.services.project.TestAddProject('memberof-proj', project_id=1, owner_ids=[2], committer_ids=[1]) self.services.project.TestAddProject('ownerof-proj', project_id=2, owner_ids=[1]) self.services.project.TestAddProject('contributorto-proj', project_id=3, owner_ids=[2], contrib_ids=[1]) self.services.project.TestAddProject('starred-proj', project_id=4) self.services.project_star.SetStar(None, 4, 1, True) mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1L}, services=self.services) result = self.projects_json_feed.HandleRequest(mr) self.assertEqual(['memberof-proj'], result['memberof']) self.assertEqual(['contributorto-proj'], result['contributorto']) self.assertEqual(['starred-proj'], result['starred_projects']) self.assertEqual(['ownerof-proj'], result['ownerof'])
def testProcessRemoveSelf(self): hotlist = self.servlet.services.features.TestAddHotlist( 'HotlistName', 'self removing 222, monica', [111], [222]) mr = testing_helpers.MakeMonorailRequest( path='/u/[email protected]/hotlists/HotlistName/people', hotlist=hotlist) mr.hotlist_id = hotlist.hotlist_id mr.cnxn = 'fake cnxn' # The owner cannot be removed using ProcessRemoveSelf(); this is enforced # by permission in ProcessFormData, not in the function itself; # nor may a random user... mr.auth.user_id = 333 mr.auth.effective_ids = {333} url = self.servlet.ProcessRemoveSelf(mr, '/u/111/hotlists/HotlistName') self.assertTrue('/u/111/hotlists/HotlistName/people' in url) self.assertEqual(hotlist.owner_ids, [111]) self.assertEqual(hotlist.editor_ids, [222]) # ...but an editor can. mr.auth.user_id = 222 mr.auth.effective_ids = {222} url = self.servlet.ProcessRemoveSelf(mr, '/u/111/hotlists/HotlistName') self.assertTrue('/u/111/hotlists/HotlistName/people' in url) self.assertEqual(hotlist.owner_ids, [111]) self.assertEqual(hotlist.editor_ids, [])
def testProcessFormData_ClearStatus(self): """Test PFD processes null/cleared status values.""" local_id_1, _ = self.services.issue.CreateIssue( self.cnxn, self.services, 789, 'issue summary', 'New', 111, [], [], [], [], 111, 'test issue') mr = testing_helpers.MakeMonorailRequest( project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET, user_info={'user_id': 111}) mr.local_id_list = [local_id_1] post_data = fake.PostData(op_statusenter=['clear'], owner=['*****@*****.**'], can=[1], q=[''], colspec=[''], sort=[''], groupby=[''], start=[0], num=[100]) self._MockMethods() self.servlet.ProcessFormData(mr, post_data) self.assertEquals((tracker_pb2.FieldID.STATUS, ''), self.GetFirstAmendment(789, local_id_1))
def testGatherHelpData(self): project = project_pb2.Project() mr = testing_helpers.MakeMonorailRequest(project=project) # Users not near the lifetime limit see no cue card. help_data = self.servlet.GatherHelpData(mr, {}) self.assertEqual(None, help_data['cue_remaining_projects']) # User who is near the lifetime limit will see a cue card. mr.auth.user_pb.project_creation_limit.lifetime_count = 20 help_data = self.servlet.GatherHelpData(mr, {}) self.assertEqual(5, help_data['cue_remaining_projects']) # User far under custom lifetime limit won't see a cue card. mr.auth.user_pb.project_creation_limit.lifetime_limit = 100 mr.auth.user_pb.project_creation_limit.lifetime_count = 20 help_data = self.servlet.GatherHelpData(mr, {}) self.assertEqual(None, help_data['cue_remaining_projects']) # User near custom lifetime limit will see a cue card. mr.auth.user_pb.project_creation_limit.lifetime_limit = 100 mr.auth.user_pb.project_creation_limit.lifetime_count = 91 help_data = self.servlet.GatherHelpData(mr, {}) self.assertEqual(9, help_data['cue_remaining_projects'])
def testProcessFormData_okSomeIssues(self): mr = testing_helpers.MakeMonorailRequest(path=urls.BAN_SPAMMER_TASK + '.do', method='POST', params={ 'spammer_id': 111, 'reporter_id': 222 }) for i in range(0, 10): issue = fake.MakeTestIssue(1, i, 'issue_summary', 'New', 111, project_name='project-name') self.servlet.services.issue.TestAddIssue(issue) self.servlet.HandleRequest(mr) self.assertEqual(self.res.body, json.dumps({ 'comments': 0, 'issues': 10 }))
def testGatherPageData(self): mr = testing_helpers.MakeMonorailRequest(hotlist=self.public_hotlist) mr.auth.user_id = 111L mr.auth.effective_ids = {111L} mr.cnxn = 'fake cnxn' page_data = self.servlet.GatherPageData(mr) self.assertEqual(ezt.boolean(True), page_data['offer_membership_editing']) self.assertEqual(page_data['total_num_owners'], 1) self.assertEqual(page_data['newly_added_views'], []) self.assertEqual(len(page_data['pagination'].visible_results), 2) # non-owners cannot edit people list mr.auth.user_id = 222L mr.auth.effective_ids = {222L} page_data = self.servlet.GatherPageData(mr) self.assertEqual(ezt.boolean(False), page_data['offer_membership_editing']) mr.auth.user_id = 333L mr.auth.effective_ids = {333L} page_data = self.servlet.GatherPageData(mr) self.assertEqual(ezt.boolean(False), page_data['offer_membership_editing'])
def testGatherPageData(self): user = self.services.user.TestAddUser('user@invalid', 100) mr = testing_helpers.MakeMonorailRequest( path='/p/proj/issues/entry', services=self.services) mr.auth.user_view = framework_views.MakeUserView( 'cnxn', self.services.user, 100) mr.template_name = 'rutabaga' self.mox.StubOutWithMock(self.services.user, 'GetUser') self.services.user.GetUser( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user) self.mox.ReplayAll() config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id) config.field_defs = [ tracker_bizobj.MakeFieldDef( 24, mr.project_id, 'NotEnum', tracker_pb2.FieldTypes.STR_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False), tracker_bizobj.MakeFieldDef( 24, mr.project_id, 'Choices', tracker_pb2.FieldTypes.ENUM_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False)] self.services.config.StoreConfig(mr.cnxn, config) template = tracker_pb2.TemplateDef( labels=['NotEnum-Not-Masked', 'Choices-Masked']) self.services.template.GetTemplateByName.return_value = template page_data = self.servlet.GatherPageData(mr) self.mox.VerifyAll() self.assertEqual(page_data['initial_owner'], 'user@invalid') self.assertEqual(page_data['initial_status'], 'New') self.assertTrue(page_data['clear_summary_on_click']) self.assertTrue(page_data['must_edit_summary']) self.assertEqual(page_data['labels'], ['NotEnum-Not-Masked'])
def testProcessFormData_RejectTemplate(self): mr = testing_helpers.MakeMonorailRequest( hotlist=self.hotlist, path='/u/111L/hotlists/%s/details' % self.hotlist.hotlist_id) mr.auth.user_id = 111L post_data = fake.PostData(summary=[''], name=[''], description=['fake description'], default_col_spec=['test default col spec']) self.mox.StubOutWithMock(self.servlet, 'PleaseCorrect') self.servlet.PleaseCorrect( mr, initial_summary='', initial_description='fake description', initial_name='', initial_default_col_spec='test default col spec') self.mox.ReplayAll() url = self.servlet.ProcessFormData(mr, post_data) self.mox.VerifyAll() self.assertEqual(hotlistdetails._MSG_NAME_MISSING, mr.errors.name) self.assertEqual(hotlistdetails._MSG_SUMMARY_MISSING, mr.errors.summary) self.assertIsNone(url)
def testParsePersonData(self): mr = testing_helpers.MakeMonorailRequest( path='/p/proj/people/detail?u=111', project=self.project) post_data = fake.PostData(role=['owner'], extra_perms=['ViewQuota', 'EditIssue']) u, r, ac, n, _ = self.servlet.ParsePersonData(mr, post_data) self.assertEquals(111, u) self.assertEquals('owner', r) self.assertEquals(['ViewQuota', 'EditIssue'], ac) self.assertEquals('', n) post_data = fake.PostData({ 'role': ['owner'], 'extra_perms': [' ', ' \t'], 'notes': [''], }) u, r, ac, n, ac_exclusion = self.servlet.ParsePersonData(mr, post_data) self.assertEquals(111, u) self.assertEquals('owner', r) self.assertEquals([], ac) self.assertEquals('', n) self.assertFalse(ac_exclusion) post_data = fake.PostData({ 'username': ['jrobbins'], 'role': ['owner'], 'extra_perms': ['_ViewQuota', ' __EditIssue'], 'notes': [' Our local Python expert '], 'ac_exclude': [123], }) u, r, ac, n, ac_exclusion = self.servlet.ParsePersonData(mr, post_data) self.assertEquals(111, u) self.assertEquals('owner', r) self.assertEquals(['ViewQuota', 'EditIssue'], ac) self.assertEquals('Our local Python expert', n) self.assertTrue(ac_exclusion)
def testNotifyRulesDeletedTask(self): self.services.project.TestAddProject('proj', owner_ids=[777, 888], project_id=789) self.services.user.TestAddUser('*****@*****.**', 777) self.services.user.TestAddUser('*****@*****.**', 888) task = notify.NotifyRulesDeletedTask(request=None, response=None, services=self.services) params = { 'project_id': 789, 'filter_rules': 'if green make yellow,if orange make blue' } mr = testing_helpers.MakeMonorailRequest(params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertEqual(len(result['tasks']), 2) body = result['tasks'][0]['body'] self.assertTrue('if green make yellow' in body) self.assertTrue('if green make yellow' in body) self.assertTrue('/p/proj/adminRules' in body) self.assertItemsEqual(['*****@*****.**', '*****@*****.**'], result['notified'])
def testNotifyBulkChangeTask_Spam(self): """A spam issue is excluded from notification emails.""" issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1, is_spam=True) self.services.issue.TestAddIssue(issue2) task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_ids': '%d,%d' % (self.issue1.issue_id, issue2.issue_id), 'seq': 0, 'old_owner_ids': '1,1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertEquals(1, len(result['notified']))
def testNotifyBulkChangeTask_Normal(self): """We generate email tasks for each user involved in the issues.""" issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1) issue2.cc_ids = [3] self.services.issue.TestAddIssue(issue2) task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'seq': 0, 'issue_ids': '%d,%d' % (self.issue1.issue_id, issue2.issue_id), 'old_owner_ids': '1,1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(2, len(tasks)) for task in tasks: task_params = json.loads(task.payload) # obfuscated email for non-members if 'user' in task_params['to']: self.assertIn(u'\u2026', task_params['from_addr']) # Full email for members if 'member' in task_params['to']: self.assertNotIn(u'\u2026', task_params['from_addr'])
def setUpCreateHotlistTableDataTestMR(self, **kwargs): self.mr = testing_helpers.MakeMonorailRequest(**kwargs) self.services.user.TestAddUser('*****@*****.**', 148) self.mr.auth.effective_ids = {148} self.mr.col_spec = 'ID Summary Modified'
def testHandleRequest_NoIssue(self): mr = testing_helpers.MakeMonorailRequest() self.assertRaises(monorailrequest.InputException, self.servlet.HandleRequest, mr)
def testSameAppOnly_ExternallyAccessible(self): feed = TestableJsonFeed() feed.mr = testing_helpers.MakeMonorailRequest() # Note that request has no X-Appengine-Inbound-Appid set. feed.get() feed.post()
def testSecurityTokenChecked_AnonUserDoesNotNeedToken(self): feed = TestableJsonFeed() feed.mr = testing_helpers.MakeMonorailRequest() # Note that feed.mr has no token set, but also no auth.user_id. feed.get() feed.post()
def testGatherPageData(self): mr = testing_helpers.MakeMonorailRequest() page_data = self.servlet.GatherPageData(mr) self.assertEqual(settings.learn_more_link, page_data['learn_more_link'])
def testVirtualPagination(self): # Paginating 0 results on a page that can hold 100. mr = testing_helpers.MakeMonorailRequest(path='/issues/list') vp = paginate.VirtualPagination(mr, 0, 100) self.assertEquals(vp.num, 100) self.assertEquals(vp.start, 1) self.assertEquals(vp.last, 0) self.assertFalse(vp.visible) # Paginationg 12 results on a page that can hold 100. mr = testing_helpers.MakeMonorailRequest(path='/issues/list') vp = paginate.VirtualPagination(mr, 12, 100) self.assertEquals(vp.num, 100) self.assertEquals(vp.start, 1) self.assertEquals(vp.last, 12) self.assertTrue(vp.visible) # Paginationg 12 results on a page that can hold 10. mr = testing_helpers.MakeMonorailRequest(path='/issues/list?num=10') vp = paginate.VirtualPagination(mr, 12, 100) self.assertEquals(vp.num, 10) self.assertEquals(vp.start, 1) self.assertEquals(vp.last, 10) self.assertTrue(vp.visible) # Paginationg 12 results starting at 5 on page that can hold 10. mr = testing_helpers.MakeMonorailRequest( path='/issues/list?start=5&num=10') vp = paginate.VirtualPagination(mr, 12, 100) self.assertEquals(vp.num, 10) self.assertEquals(vp.start, 6) self.assertEquals(vp.last, 12) self.assertTrue(vp.visible) # Paginationg 123 results on a page that can hold 100. mr = testing_helpers.MakeMonorailRequest(path='/issues/list') vp = paginate.VirtualPagination(mr, 123, 100) self.assertEquals(vp.num, 100) self.assertEquals(vp.start, 1) self.assertEquals(vp.last, 100) self.assertTrue(vp.visible) # Paginationg 123 results on second page that can hold 100. mr = testing_helpers.MakeMonorailRequest(path='/issues/list?start=100') vp = paginate.VirtualPagination(mr, 123, 100) self.assertEquals(vp.num, 100) self.assertEquals(vp.start, 101) self.assertEquals(vp.last, 123) self.assertTrue(vp.visible) # Paginationg a huge number of objects will show at most 5000 per page. mr = testing_helpers.MakeMonorailRequest(path='/issues/list?num=9999') vp = paginate.VirtualPagination(mr, 12345, 100) self.assertEquals(vp.num, 1000) self.assertEquals(vp.start, 1) self.assertEquals(vp.last, 1000) self.assertTrue(vp.visible) # Test urls for a hotlist pagination mr = testing_helpers.MakeMonorailRequest( path='/hotlists/17?num=5&start=4') mr.hotlist_id = 17 mr.auth.user_id = 112 vp = paginate.VirtualPagination(mr, 12, 5, list_page_url='/u/112/hotlists/17') self.assertEquals(vp.num, 5) self.assertEquals(vp.start, 5) self.assertEquals(vp.last, 9) self.assertTrue(vp.visible) self.assertEqual('/u/112/hotlists/17?num=5&start=9', vp.next_url) self.assertEqual('/u/112/hotlists/17?num=5&start=0', vp.prev_url)
def testNotifyApprovalChangeTask_Normal(self): config = self.services.config.GetProjectConfig('cnxn', 12345) config.field_defs = [ # issue's User field with any_comment is notified. tracker_bizobj.MakeFieldDef( 121, 12345, 'TL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL, notified on everything', False), # issue's User field with never is not notified. tracker_bizobj.MakeFieldDef( 122, 12345, 'silentTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'TL, notified on nothing', False), # approval's User field with any_comment is notified. tracker_bizobj.MakeFieldDef(123, 12345, 'otherapprovalTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL on the approvers team', False, approval_id=3), # another approval's User field with any_comment is not notified. tracker_bizobj.MakeFieldDef(124, 12345, 'otherapprovalTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL on another approvers team', False, approval_id=4), tracker_bizobj.MakeFieldDef(3, 12345, 'Goat-Approval', tracker_pb2.FieldTypes.APPROVAL_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'Get Approval from Goats', False) ] self.services.config.StoreConfig('cnxn', config) # Custom user_type field TLs self.services.user.TestAddUser('*****@*****.**', 111) self.services.user.TestAddUser('*****@*****.**', 222) self.services.user.TestAddUser('*****@*****.**', 333) self.services.user.TestAddUser('*****@*****.**', 444) # Approvers self.services.user.TestAddUser('*****@*****.**', 777) self.services.user.TestAddUser('*****@*****.**', 888) self.services.user.TestAddUser('*****@*****.**', 999) self.services.user.TestAddUser('*****@*****.**', 666) self.services.user.TestAddUser('*****@*****.**', 661) self.services.user.TestAddUser('*****@*****.**', 662) self.services.user.TestAddUser('*****@*****.**', 663) self.services.usergroup.TestAddGroupSettings( 666, '*****@*****.**') self.services.usergroup.TestAddMembers(666, [661, 662, 663]) canary_phase = tracker_pb2.Phase(name='Canary', phase_id=1, rank=1) approval_values = [ tracker_pb2.ApprovalValue(approval_id=3, approver_ids=[888, 999, 666, 661]) ] approval_issue = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1, is_spam=True) approval_issue.phases = [canary_phase] approval_issue.approval_values = approval_values approval_issue.field_values = [ tracker_bizobj.MakeFieldValue(121, None, None, 111, None, None, False), tracker_bizobj.MakeFieldValue(122, None, None, 222, None, None, False), tracker_bizobj.MakeFieldValue(123, None, None, 333, None, None, False), tracker_bizobj.MakeFieldValue(124, None, None, 444, None, None, False), ] self.services.issue.TestAddIssue(approval_issue) amend = tracker_bizobj.MakeApprovalApproversAmendment([888], [777]) comment = tracker_pb2.IssueComment(project_id=12345, user_id=999, issue_id=approval_issue.issue_id, amendments=[amend], timestamp=1234567890, content='just a comment.') attach = tracker_pb2.Attachment(attachment_id=4567, filename='sploot.jpg', mimetype='image/png', gcs_object_id='/pid/attachments/abcd', filesize=(1024 * 1023)) comment.attachments.append(attach) self.services.issue.TestAddComment(comment, approval_issue.local_id) self.services.issue.TestAddAttachment(attach, comment.id, approval_issue.issue_id) task = notify.NotifyApprovalChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': approval_issue.issue_id, 'approval_id': 3, 'comment_id': comment.id, } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertTrue('just a comment' in result['tasks'][0]['body']) self.assertTrue('Approvers: -approver' in result['tasks'][0]['body']) self.assertTrue('sploot.jpg' in result['tasks'][0]['body']) self.assertTrue( '/issues/attachment?aid=4567' in result['tasks'][0]['body']) self.assertItemsEqual([ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ], result['notified']) # Test no approvers/groups notified # Status change to NEED_INFO does not email approvers. amend2 = tracker_bizobj.MakeApprovalStatusAmendment( tracker_pb2.ApprovalStatus.NEED_INFO) comment2 = tracker_pb2.IssueComment(project_id=12345, user_id=999, issue_id=approval_issue.issue_id, amendments=[amend2], timestamp=1234567891, content='') self.services.issue.TestAddComment(comment2, approval_issue.local_id) task = notify.NotifyApprovalChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': approval_issue.issue_id, 'approval_id': 3, 'comment_id': comment2.id, } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertTrue('Status: need_info' in result['tasks'][0]['body']) self.assertItemsEqual( ['*****@*****.**', '*****@*****.**', '*****@*****.**'], result['notified'])
def testFormatURL(self): mr = testing_helpers.MakeMonorailRequest() path = '/dude/wheres/my/car' url = framework_helpers.FormatURL(mr, path) self.assertEqual(path, url)
def testGatherHelpData_Anon(self): mr = testing_helpers.MakeMonorailRequest(path='/p/proj/people/list', project=self.project) help_data = self.servlet.GatherHelpData(mr, {}) self.assertEqual({'account_cue': None, 'cue': None}, help_data)