Esempio n. 1
0
 def testTestMetadataKey_Test(self):
     key = utils.TestMetadataKey(
         ndb.Key('Master', 'm', 'Bot', 'b', 'Test', 'suite', 'Test',
                 'metric'))
     self.assertEqual('TestMetadata', key.kind())
     self.assertEqual('m/b/suite/metric', key.id())
     self.assertEqual(('TestMetadata', 'm/b/suite/metric'), key.flat())
Esempio n. 2
0
    def GetTestMetadataKey(self):
        """Get the key for the TestMetadata entity of this alert.

    We are in the process of converting from Test entities to TestMetadata.
    Until this is done, it's possible that an alert may store either Test
    or TestMetadata in the 'test' KeyProperty. This gets the TestMetadata key
    regardless of what's stored.
    """
        return utils.TestMetadataKey(self.test)
Esempio n. 3
0
 def testGetAlertsForTest(self):
     old_style_key1 = utils.OldStyleTestKey('master/bot/test1/metric')
     new_style_key1 = utils.TestMetadataKey('master/bot/test1/metric')
     old_style_key2 = utils.OldStyleTestKey('master/bot/test2/metric')
     new_style_key2 = utils.TestMetadataKey('master/bot/test2/metric')
     anomaly.Anomaly(id="old_1", test=old_style_key1).put()
     anomaly.Anomaly(id="old_1a", test=old_style_key1).put()
     anomaly.Anomaly(id="old_2", test=old_style_key2).put()
     anomaly.Anomaly(id="new_1", test=new_style_key1).put()
     anomaly.Anomaly(id="new_2", test=new_style_key2).put()
     anomaly.Anomaly(id="new_2a", test=new_style_key2).put()
     key1_alerts = anomaly.Anomaly.GetAlertsForTest(new_style_key1)
     self.assertEqual(['new_1', 'old_1', 'old_1a'],
                      [a.key.id() for a in key1_alerts])
     key2_alerts = anomaly.Anomaly.GetAlertsForTest(old_style_key2)
     self.assertEqual(['new_2', 'new_2a', 'old_2'],
                      [a.key.id() for a in key2_alerts])
     key2_alerts_limit = anomaly.Anomaly.GetAlertsForTest(old_style_key2,
                                                          limit=2)
     self.assertEqual(['new_2', 'new_2a'],
                      [a.key.id() for a in key2_alerts_limit])
Esempio n. 4
0
    def _pre_put_hook(self):
        """Sets the has_rows property of the parent test before putting this Row.

    This isn't atomic because the parent_test put() and Row put() don't happen
    in the same transaction. But in practice it shouldn't be an issue because
    the parent test will get more points as the test runs.
    """
        parent_test = utils.TestMetadataKey(self.key.parent().id()).get()

        # If the TestMetadata pointed to by parent_test is not valid, that indicates
        # that a TestMetadata entity was not properly created in add_point.
        if not parent_test:
            parent_key = self.key.parent()
            logging.warning(
                'Row put without valid TestMetadata. Parent key: %s',
                parent_key)
            return

        if not parent_test.has_rows:
            parent_test.has_rows = True
            parent_test.put()
Esempio n. 5
0
 def GetAlertsForTest(cls, test_key, limit=None):
     return cls.query(
         cls.test.IN([
             utils.TestMetadataKey(test_key),
             utils.OldStyleTestKey(test_key)
         ])).fetch(limit=limit)
Esempio n. 6
0
 def testTestMetadataKey_String(self):
     key = utils.TestMetadataKey('m/b/suite/metric/page')
     self.assertEqual('TestMetadata', key.kind())
     self.assertEqual('m/b/suite/metric/page', key.id())
     self.assertEqual(('TestMetadata', 'm/b/suite/metric/page'), key.flat())
Esempio n. 7
0
 def testTestMetadataKey_TestMetadata(self):
     original_key = ndb.Key('TestMetadata', 'm/b/suite/metric')
     key = utils.TestMetadataKey(original_key)
     self.assertEqual(original_key, key)
Esempio n. 8
0
 def testTestMetadataKey_None(self):
     key = utils.TestMetadataKey(None)
     self.assertIsNone(key)