示例#1
0
    def testEditSheriff_EditPatternsList(self):
        self._AddSampleTestData()
        self._AddSheriff('Sheriff', patterns=['*/*/*/*'])
        self.testapp.post(
            '/edit_sheriffs', {
                'add-edit': 'edit',
                'edit-name': 'Sheriff',
                'patterns': '*/*/*/ddd\n\n*/*/*/ccc',
                'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
            })
        sheriff_entity = sheriff.Sheriff.query().fetch()[0]
        self.assertEqual(['*/*/*/ccc', '*/*/*/ddd'], sheriff_entity.patterns)

        # After the tasks get executed, the TestMetadata entities should also be
        # updated.
        self.ExecuteDeferredTasks('default')
        self.ExecuteTaskQueueTasks('/put_entities_task',
                                   edit_config_handler._TASK_QUEUE_NAME)
        aaa = utils.TestKey('TheMaster/TheBot/Suite1/aaa').get()
        bbb = utils.TestKey('TheMaster/TheBot/Suite1/bbb').get()
        ccc = utils.TestKey('TheMaster/TheBot/Suite2/ccc').get()
        ddd = utils.TestKey('TheMaster/TheBot/Suite2/ddd').get()
        self.assertIsNone(aaa.sheriff)
        self.assertIsNone(bbb.sheriff)
        self.assertEqual(sheriff_entity.key, ccc.sheriff)
        self.assertEqual(sheriff_entity.key, ddd.sheriff)
示例#2
0
 def testPost_WithInvalidAddEditParameter_ShowsErrorMessage(self):
   response = self.testapp.post('/edit_sheriffs', {
       'add-edit': '',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   expected_message = 'Invalid value'
   self.assertIn(expected_message, response.body)
 def testPost_InvalidTests(self):
     self._AddInternalBotsToDataStore()
     _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
         users.get_current_user())
     response = self.testapp.post(
         '/create_health_report', {
             'tableName': 'myName',
             'tableBots': 'ChromiumPerf/linux',
             'tableTests': 'someTests',
             'tableLayout': '{"Alayout":"isHere"}',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     self.assertIn('someTests is not a valid test.', response)
     query = table_config.TableConfig.query()
     table_values = query.fetch()
     self.assertEqual(len(table_values), 0)
示例#4
0
    def testPost_EditExistingSheriff(self):
        self._AddSampleTestData()
        self._AddSheriff('Old Sheriff')
        self.testapp.post(
            '/edit_sheriffs', {
                'add-edit': 'edit',
                'edit-name': 'Old Sheriff',
                'email': '*****@*****.**',
                'url': 'http://perf.com/mysheriff',
                'internal-only': 'false',
                'summarize': 'true',
                'patterns': '*/*/Suite1/*\n',
                'labels': '',
                'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
            })
        sheriff_entity = sheriff.Sheriff.query().fetch()[0]
        self.assertEqual('*****@*****.**', sheriff_entity.email)
        self.assertEqual('http://perf.com/mysheriff', sheriff_entity.url)
        self.assertEqual(['*/*/Suite1/*'], sheriff_entity.patterns)
        self.assertEqual([], sheriff_entity.labels)
        self.assertTrue(sheriff_entity.summarize)

        # After the tasks get executed, the TestMetadata entities should also be
        # updated.
        self.ExecuteTaskQueueTasks('/put_entities_task',
                                   edit_config_handler._TASK_QUEUE_NAME)
        aaa = utils.TestKey('TheMaster/TheBot/Suite1/aaa').get()
        bbb = utils.TestKey('TheMaster/TheBot/Suite1/bbb').get()
        ccc = utils.TestKey('TheMaster/TheBot/Suite2/ccc').get()
        ddd = utils.TestKey('TheMaster/TheBot/Suite2/ddd').get()
        self.assertEqual(sheriff_entity.key, aaa.sheriff)
        self.assertEqual(sheriff_entity.key, bbb.sheriff)
        self.assertIsNone(ccc.sheriff)
        self.assertIsNone(ddd.sheriff)
示例#5
0
 def testPost_NoNameGivenWhenEditingSheriff_ShowsErrorMessage(self):
   response = self.testapp.post('/edit_sheriffs', {
       'add-edit': 'edit',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   expected_message = 'No name given'
   self.assertIn(expected_message, response.body)
示例#6
0
    def testPost_GetTableConfigDetailsForEdit(self):
        self._AddInternalBotsToDataStore()
        config = copy.deepcopy(_SAMPLE_TABLE_CONFIG)
        config['xsrf_token'] = xsrf.GenerateToken(users.get_current_user())

        self.testapp.post('/create_health_report', config)

        response = self.testapp.post(
            '/create_health_report', {
                'getTableConfigDetails': 'my_sample_config',
            })
        # Similar to the valid data test, ensure everything is correct.
        self.assertIn('my_sample_config', response)
        table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
        self.assertTrue(table_entity.internal_only)
        self.assertEqual('*****@*****.**', table_entity.username)
        self.assertEqual(
            ['my_test_suite/my_test', 'my_test_suite/my_other_test'],
            table_entity.tests)
        master_key = ndb.Key('Master', 'ChromiumPerf')
        win_bot = graph_data.Bot(id='win',
                                 parent=master_key,
                                 internal_only=False).key
        linux_bot = graph_data.Bot(id='linux',
                                   parent=master_key,
                                   internal_only=False).key
        bots = [win_bot, linux_bot]
        self.assertEqual(bots, table_entity.bots)
        self.assertEqual(
            '{"my_test_suite/my_test": ["Foreground", "Pretty Name 1"], '
            '"my_test_suite/my_other_test": ["Foreground", "Pretty Name 2"]}',
            table_entity.table_layout)
示例#7
0
  def testPost_SendsNotificationEmail(self):
    self._AddSampleTestData()
    self._AddSheriff('Chromium Perf Sheriff', patterns=['*/*/*/*'])
    self.testapp.post('/edit_sheriffs', {
        'add-edit': 'edit',
        'edit-name': 'Chromium Perf Sheriff',
        'patterns': '*/*/*/ddd\n\n*/*/*/ccc',
        'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
    })
    sheriff_entity = sheriff.Sheriff.query().fetch()[0]
    self.assertEqual(['*/*/*/ccc', '*/*/*/ddd'], sheriff_entity.patterns)

    messages = self.mail_stub.get_sent_messages()
    self.assertEqual(1, len(messages))
    self.assertEqual('*****@*****.**', messages[0].sender)
    self.assertEqual('*****@*****.**',
                     messages[0].to)
    self.assertEqual(
        'Added or updated Sheriff: Chromium Perf Sheriff by [email protected]',
        messages[0].subject)
    expected_email = """The configuration of None was changed by [email protected].

Key: Chromium Perf Sheriff

New test path patterns:
[
  "*/*/*/ccc",
  "*/*/*/ddd"
]

Old test path patterns
[
  "*/*/*/*"
]"""
    self.assertIn(expected_email, str(messages[0].body))
 def testPost_ValidData(self):
     self._AddInternalBotsToDataStore()
     _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
         users.get_current_user())
     response = self.testapp.post('/create_health_report',
                                  _SAMPLE_TABLE_CONFIG)
     self.assertIn('my_sample_config', response)
     table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
     self.assertTrue(table_entity.internal_only)
     self.assertEqual('*****@*****.**', table_entity.username)
     self.assertEqual(
         ['my_test_suite/my_test', 'my_test_suite/my_other_test'],
         table_entity.tests)
     master_key = ndb.Key('Master', 'ChromiumPerf')
     win_bot = graph_data.Bot(id='win',
                              parent=master_key,
                              internal_only=False).key
     linux_bot = graph_data.Bot(id='linux',
                                parent=master_key,
                                internal_only=False).key
     bots = [win_bot, linux_bot]
     self.assertEqual(bots, table_entity.bots)
     self.assertEqual(
         '{"my_test_suite/my_test": ["Foreground", "Pretty Name 1"], '
         '"my_test_suite/my_other_test": ["Foreground", "Pretty Name 2"]}',
         table_entity.table_layout)
 def testPost_PublicOnlyBots(self):
     self._AddPublicBotsToDataStore()
     _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
         users.get_current_user())
     self.testapp.post('/create_health_report', _SAMPLE_TABLE_CONFIG)
     table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
     self.assertFalse(table_entity.internal_only)
示例#10
0
 def testPost_WithKey_UpdatesNonNamespacedValues(self):
     self.testapp.post(
         '/edit_site_config', {
             'key': 'foo',
             'value': '[1, 2, 3]',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     self.assertEqual([1, 2, 3], stored_object.Get('foo'))
示例#11
0
    def testPost_TwoPostsSameNameReturnsError(self):
        self._AddInternalBotsToDataStore()
        config = copy.deepcopy(_SAMPLE_TABLE_CONFIG)
        config['xsrf_token'] = xsrf.GenerateToken(users.get_current_user())

        self.testapp.post('/create_health_report', config)
        response = self.testapp.post('/create_health_report', config)
        self.assertIn('my_sample_config already exists.', response)
示例#12
0
    def testPost_InternalOnlyAndPublicBots(self):
        self._AddMixedBotsToDataStore()
        config = copy.deepcopy(_SAMPLE_TABLE_CONFIG)
        config['xsrf_token'] = xsrf.GenerateToken(users.get_current_user())

        self.testapp.post('/create_health_report', config)
        table_entity = ndb.Key('TableConfig', 'my_sample_config').get()
        self.assertTrue(table_entity.internal_only)
示例#13
0
 def testPost_EmptyForm(self):
   response = self.testapp.post('/create_health_report', {
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
       })
   self.assertIn('Please fill out the form entirely.', response)
   query = table_config.TableConfig.query()
   table_values = query.fetch()
   self.assertEqual(len(table_values), 0)
示例#14
0
 def testPost_LogAdded(self):
     self.testapp.post(
         '/bad_bisect?', {
             'try_job_id': '1234',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     logs = quick_logger.Get('bad_bisect', 'report')
     self.assertEqual(1, len(logs))
    def testPost_GetTableConfigList(self):
        self._AddInternalBotsToDataStore()
        _SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
            users.get_current_user())
        _ALT_SAMPLE_TABLE_CONFIG['xsrf_token'] = xsrf.GenerateToken(
            users.get_current_user())
        self.testapp.post('/create_health_report', _SAMPLE_TABLE_CONFIG)
        self.testapp.post('/create_health_report', _ALT_SAMPLE_TABLE_CONFIG)

        response = self.testapp.post('/create_health_report', {
            'getTableConfigList': True,
        })
        return_list = self.GetJsonValue(response, 'table_config_list')
        query = table_config.TableConfig.query()
        all_configs = query.fetch(keys_only=True)
        for config in all_configs:
            self.assertIn(config.id(), return_list)
示例#16
0
 def testPost_NameForExistingSheriffNotFound_ShowsErrorMessage(self):
   response = self.testapp.post('/edit_sheriffs', {
       'add-edit': 'edit',
       'edit-name': 'X',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   expected_message = 'does not exist'
   self.assertIn(expected_message, response.body)
示例#17
0
 def testPost_LoggedIntoInvalidDomain_DoesNotModifyAnomaly(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   self.testapp.post('/edit_anomalies', {
       'keys': json.dumps([anomaly_keys[0].urlsafe()]),
       'bug_id': 31337,
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   }, status=403)
   self.assertIsNone(anomaly_keys[0].get().bug_id)
示例#18
0
 def testPost_FeedbackRecorded(self):
     self.testapp.post(
         '/bad_bisect?', {
             'try_job_id': '1234',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     jobs = try_job.TryJob.query().fetch()
     self.assertEqual(1, len(jobs))
     self.assertEqual({'*****@*****.**'}, jobs[0].bad_result_emails)
示例#19
0
 def testPost_LoggedIntoValidSheriffAccount_ChangesBugID(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   self.testapp.post('/edit_anomalies', {
       'keys': json.dumps([anomaly_keys[0].urlsafe()]),
       'bug_id': 31337,
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual(31337, anomaly_keys[0].get().bug_id)
示例#20
0
 def testPost_ExternalUser_ShowsErrorMessage(self):
     self.SetCurrentUser('*****@*****.**')
     response = self.testapp.post(
         '/edit_site_config', {
             'key': 'foo',
             'value': '[1, 2, 3]',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     self.assertIn('Only internal users', response.body)
示例#21
0
 def testPost_NameForNewSheriffAlreadyUsed_ShowsErrorMessage(self):
   self._AddSheriff('X')
   response = self.testapp.post('/edit_sheriffs', {
       'add-edit': 'add',
       'add-name': 'X',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   expected_message = 'already exists'
   self.assertIn(expected_message, response.body)
示例#22
0
 def testPost_WithSomeInvalidJSON_ShowsErrorAndDoesNotModify(self):
     stored_object.Set('foo', 'XXX')
     response = self.testapp.post(
         '/edit_site_config', {
             'key': 'foo',
             'value': '[1, 2, this is not json',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     self.assertIn('Invalid JSON', response.body)
     self.assertEqual('XXX', stored_object.Get('foo'))
示例#23
0
 def testPost_IncompleteParametersGiven_ReturnsError(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   response = self.testapp.post('/edit_anomalies', {
       'keys': json.dumps([anomaly_keys[0].urlsafe()]),
       'new_start_revision': '123',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual(
       {'error': 'No bug ID or new revision specified.'},
       json.loads(response.body))
示例#24
0
 def testPost_NoKeysGiven_Error(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   response = self.testapp.post('/edit_anomalies', {
       'bug_id': 31337,
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual(
       {'error': 'No alerts specified to add bugs to.'},
       json.loads(response.body))
   self.assertIsNone(anomaly_keys[0].get().bug_id)
示例#25
0
 def testPost_ChangeRevisions(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   self.testapp.post('/edit_anomalies', {
       'keys': json.dumps([anomaly_keys[0].urlsafe()]),
       'new_start_revision': '123450',
       'new_end_revision': '123455',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual(123450, anomaly_keys[0].get().start_revision)
   self.assertEqual(123455, anomaly_keys[0].get().end_revision)
示例#26
0
 def testPost_RemoveBug(self):
   anomaly_keys = self._AddAnomaliesToDataStore()
   self.SetCurrentUser('*****@*****.**')
   a = anomaly_keys[0].get()
   a.bug_id = 12345
   a.put()
   self.testapp.post('/edit_anomalies', {
       'keys': json.dumps([anomaly_keys[0].urlsafe()]),
       'bug_id': 'REMOVE',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertIsNone(anomaly_keys[0].get().bug_id)
示例#27
0
 def testPost_InvalidBots(self):
   self._AddInternalBotsToDataStore()
   response = self.testapp.post('/create_health_report', {
       'tableName': 'myName',
       'tableBots': 'garbage/moarGarbage',
       'tableTests': 'someTests',
       'tableLayout': '{A layout}',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
       })
   self.assertIn('Invalid Master/Bot: garbage/moarGarbage', response)
   query = table_config.TableConfig.query()
   table_values = query.fetch()
   self.assertEqual(len(table_values), 0)
示例#28
0
 def testPost_ValidBotsBadLayout(self):
   self._AddPublicBotsToDataStore()
   response = self.testapp.post('/create_health_report', {
       'tableName': 'myName',
       'tableBots': 'ChromiumPerf/linux',
       'tableTests': 'someTests',
       'tableLayout': 'garbage',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
       })
   self.assertIn('Invalid JSON for table layout', response)
   query = table_config.TableConfig.query()
   table_values = query.fetch()
   self.assertEqual(len(table_values), 0)
示例#29
0
    def testBugLabelPattern_AddAndRemove(self):
        self.testapp.post(
            '/edit_bug_labels', {
                'action': 'add_buglabel_pattern',
                'buglabel_to_add': 'Performance-1',
                'pattern': '*/*/Suite1/*',
                'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
            })

        # The list of patterns should now contain the pattern that was added.
        self.assertEqual(
            ['*/*/Suite1/*'],
            bug_label_patterns.GetBugLabelPatterns()['Performance-1'])

        # Add another pattern for the same bug label.
        self.testapp.post(
            '/edit_bug_labels', {
                'action': 'add_buglabel_pattern',
                'buglabel_to_add': 'Performance-1',
                'pattern': '*/*/Suite2/*',
                'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
            })

        # The list of patterns should now contain both patterns.
        self.assertEqual(
            ['*/*/Suite1/*', '*/*/Suite2/*'],
            bug_label_patterns.GetBugLabelPatterns()['Performance-1'])

        # Remove the BugLabelPattern entity.
        self.testapp.post(
            '/edit_bug_labels', {
                'action': 'remove_buglabel_pattern',
                'buglabel_to_remove': 'Performance-1',
                'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
            })

        # It should now be absent from the datastore.
        self.assertNotIn('Performance-1',
                         bug_label_patterns.GetBugLabelPatterns())
示例#30
0
 def testPost_WithKey_UpdatesNamespacedValues(self):
     namespaced_stored_object.Set('foo', 'XXXinternalYYY')
     namespaced_stored_object.SetExternal('foo', 'XXXYYY')
     self.testapp.post(
         '/edit_site_config', {
             'key': 'foo',
             'external_value': '{"x": "y"}',
             'internal_value': '{"x": "yz"}',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     self.assertEqual({'x': 'yz'}, namespaced_stored_object.Get('foo'))
     self.assertEqual({'x': 'y'},
                      namespaced_stored_object.GetExternal('foo'))