def testGatherPageData_IncorrectTemplate(self): """The handler shouldn't error out if passed a non-existent template.""" mr = testing_helpers.MakeMonorailRequest( path='/p/proj/issues/entry', services=self.services) mr.auth.user_view = framework_views.StuffUserView(100, 'user@invalid', True) mr.template_name = 'rutabaga' user = self.services.user.TestAddUser('user@invalid', 100) config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id) config.default_template_for_users = 456 config.default_template_for_developers = 789 self.services.config.StoreConfig(mr.cnxn, config) self.services.template.GetTemplateSetForProject.return_value = [ (1, 'one', False), (2, 'two', True)] self.services.template.GetTemplateByName.return_value = None self.services.template.GetTemplateById.return_value = \ tracker_pb2.TemplateDef(template_id=123, labels=['yo']) self.services.template.GetProjectTemplates.return_value = [ tracker_pb2.TemplateDef(labels=['no']), tracker_pb2.TemplateDef(labels=['maybe'])] 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.GetTemplateByName.called) self.assertTrue(self.services.template.GetTemplateById.called) self.assertFalse(self.services.template.GetProjectTemplates.called) self.assertEqual(page_data['config'].template_view.label0, 'yo')
def testGatherPageData_Approvals(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, 'UXReview', tracker_pb2.FieldTypes.APPROVAL_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() template.phases = [tracker_pb2.Phase( phase_id=1, rank=4, name='Stable')] template.approval_values = [tracker_pb2.ApprovalValue( approval_id=24, phase_id=1, status=tracker_pb2.ApprovalStatus.NEEDS_REVIEW)] self.services.template.GetTemplateByName.return_value = template page_data = self.servlet.GatherPageData(mr) self.mox.VerifyAll() self.assertEqual(page_data['approvals'][0].field_name, 'UXReview') self.assertEqual(page_data['initial_phases'][0], tracker_pb2.Phase(phase_id=1, name='Stable', rank=4)) self.assertEqual(page_data['prechecked_approvals'], ['24_phase_0']) self.assertEqual(page_data['required_approval_ids'], [24]) # phase fields row shown when config contains phase fields. config.field_defs.append(tracker_bizobj.MakeFieldDef( 26, mr.project_id, 'GateTarget', tracker_pb2.FieldTypes.INT_TYPE, None, '', False, False, False, None, None, '', False, '', '', tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False, is_phase_field=True)) self.services.config.StoreConfig(mr.cnxn, config) page_data = self.servlet.GatherPageData(mr) self.assertEqual(page_data['issue_phase_names'], ['stable']) # approval subfields in config hidden when chosen template does not contain # its parent approval template = tracker_pb2.TemplateDef() self.services.template.GetTemplateByName.return_value = template page_data = self.servlet.GatherPageData(mr) self.assertEqual(page_data['approvals'], []) # phase fields row hidden when template has no phases self.assertEqual(page_data['issue_phase_names'], [])
def testGetProjectTemplates_Normal(self): template_set = [(1, 'one', 0), (2, 'two', 1)] result_dict = {789: template_set} self.template_service.template_set_2lc.GetAll.return_value = ( result_dict, None) self.template_service.template_def_2lc.GetAll.return_value = ({ 1: tracker_pb2.TemplateDef() }, None) self.assertEqual([tracker_pb2.TemplateDef()], self.template_service.GetProjectTemplates( self.cnxn, 789)) self.template_service.template_set_2lc.GetAll.assert_called_once_with( self.cnxn, [789])
def testGetTemplatesById_Normal(self): """GetTemplatesById_Normal returns a template that exists.""" template = tracker_pb2.TemplateDef(template_id=1, name='one') self.template_service.template_def_2lc.GetAll.return_value = ({ 1: template }, None) actual = self.template_service.GetTemplatesById(self.cnxn, 1) self.assertEqual(actual[0].template_id, template.template_id)
def MakeTemplate(prefix): return tracker_pb2.TemplateDef( name='%s-template' % prefix, content='%s-content' % prefix, summary='%s-summary' % prefix, summary_must_be_edited=True, status='New', labels=['%s-label1' % prefix, '%s-label2' % prefix], members_only=True, owner_defaults_to_member=True, component_required=True, )
def testGetTemplateByName_Normal(self): """GetTemplateByName returns a template that exists.""" result_dict = {789: [(1, 'one', 0)]} template = tracker_pb2.TemplateDef(name='one') self.template_service.template_set_2lc.GetAll.return_value = ( result_dict, None) self.template_service.template_def_2lc.GetAll.return_value = ({ 1: template }, None) actual = self.template_service.GetTemplateByName(self.cnxn, 'one', 789) self.assertEqual(actual.template_id, template.template_id)
def testProcessFormData_TemplateNameMissing(self): """POST doesn't fail if no template_name is passed.""" mr = testing_helpers.MakeMonorailRequest( path='/p/proj/issues/entry', project=self.project) mr.auth.user_view = framework_views.StuffUserView(100, 'user@invalid', True) mr.auth.effective_ids = set([100]) self.services.template.GetTemplateById.return_value = None self.services.template.GetProjectTemplates.return_value = [ tracker_pb2.TemplateDef(members_only=True, content=''), tracker_pb2.TemplateDef(members_only=False, content='')] post_data = fake.PostData( summary=['fake summary'], comment=['fake comment'], status=['New']) self.mox.ReplayAll() url = self.servlet.ProcessFormData(mr, post_data) self.mox.VerifyAll() self.assertTrue('/p/proj/issues/detail?id=' in url)
def testListProjectTemplates_Normal(self, mockListProjectTemplates): mockListProjectTemplates.return_value = [tracker_pb2.TemplateDef( name='chicken')] mc = monorailcontext.MonorailContext( self.services, cnxn=self.cnxn, requester='*****@*****.**') request = projects_pb2.ListProjectTemplatesRequest(project_name='proj') response = self.CallWrapped( self.projects_svcr.ListProjectTemplates, mc, request) self.assertEqual( response, projects_pb2.ListProjectTemplatesResponse( templates=[ project_objects_pb2.TemplateDef(template_name='chicken')]))
def testGetTemplateByName_NotFound(self): """When GetTemplateByName is given the name of a template that does not exist.""" result_dict = {789: [(1, 'one', 0)]} template = tracker_pb2.TemplateDef(name='one') self.template_service.template_set_2lc.GetAll.return_value = ( result_dict, None) self.template_service.template_def_2lc.GetAll.return_value = ({ 1: template }, None) actual = self.template_service.GetTemplateByName(self.cnxn, 'two', 789) self.assertEqual(actual, None)
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 testNormal(self): row = (1, 2, 'name', 'content', 'summary', False, 3, 'status', False, False, False) self.assertEqual( tracker_pb2.TemplateDef(template_id=1, name='name', content='content', summary='summary', summary_must_be_edited=False, owner_id=3, status='status', members_only=False, owner_defaults_to_member=False, component_required=False), template_svc.UnpackTemplate(row))
def UnpackTemplate(template_row): """Partially construct a template object using info from a DB row.""" (template_id, _project_id, name, content, summary, summary_must_be_edited, owner_id, status, members_only, owner_defaults_to_member, component_required) = template_row template = tracker_pb2.TemplateDef() template.template_id = template_id template.name = name template.content = content template.summary = summary template.summary_must_be_edited = bool( summary_must_be_edited) template.owner_id = owner_id or 0 template.status = status template.members_only = bool(members_only) template.owner_defaults_to_member = bool(owner_defaults_to_member) template.component_required = bool(component_required) return template
def MakeIssueTemplate(name, summary, status, owner_id, content, labels, field_values, admin_ids, component_ids, summary_must_be_edited=None, owner_defaults_to_member=None, component_required=None, members_only=None): """Make an issue template PB.""" template = tracker_pb2.TemplateDef() template.name = name if summary: template.summary = summary if status: template.status = status if owner_id: template.owner_id = owner_id template.content = content template.field_values = field_values template.labels = labels or [] template.admin_ids = admin_ids template.component_ids = component_ids or [] if summary_must_be_edited is not None: template.summary_must_be_edited = summary_must_be_edited if owner_defaults_to_member is not None: template.owner_defaults_to_member = owner_defaults_to_member if component_required is not None: template.component_required = component_required if members_only is not None: template.members_only = members_only return template
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'])