| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from dashboard import add_point_queue | 7 from dashboard import add_point_queue |
| 8 from dashboard.common import testing_common | 8 from dashboard.common import testing_common |
| 9 from dashboard.common import utils | 9 from dashboard.common import utils |
| 10 from dashboard.models import anomaly |
| 10 from dashboard.models import graph_data | 11 from dashboard.models import graph_data |
| 11 from dashboard.models import stoppage_alert | 12 from dashboard.models import stoppage_alert |
| 12 | 13 |
| 13 | 14 |
| 14 class GetOrCreateAncestorsTest(testing_common.TestCase): | 15 class GetOrCreateAncestorsTest(testing_common.TestCase): |
| 15 | 16 |
| 16 def setUp(self): | 17 def setUp(self): |
| 17 super(GetOrCreateAncestorsTest, self).setUp() | 18 super(GetOrCreateAncestorsTest, self).setUp() |
| 18 self.SetCurrentUser('foo@bar.com', is_admin=True) | 19 self.SetCurrentUser('foo@bar.com', is_admin=True) |
| 19 | 20 |
| 20 def testGetOrCreateAncestors_GetsExistingEntities(self): | 21 def testGetOrCreateAncestors_GetsExistingEntities(self): |
| 21 master_key = graph_data.Master(id='ChromiumPerf', parent=None).put() | 22 master_key = graph_data.Master(id='ChromiumPerf', parent=None).put() |
| 22 graph_data.Bot(id='win7', parent=master_key).put() | 23 graph_data.Bot(id='win7', parent=master_key).put() |
| 23 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo',).put() | 24 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo',).put() |
| 24 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo/dom').put() | 25 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo/dom').put() |
| 25 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo/dom/modify').put() | 26 graph_data.TestMetadata(id='ChromiumPerf/win7/dromaeo/dom/modify').put() |
| 26 actual_parent = add_point_queue._GetOrCreateAncestors( | 27 actual_parent = add_point_queue.GetOrCreateAncestors( |
| 27 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') | 28 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') |
| 28 self.assertEqual( | 29 self.assertEqual( |
| 29 'ChromiumPerf/win7/dromaeo/dom/modify', actual_parent.key.id()) | 30 'ChromiumPerf/win7/dromaeo/dom/modify', actual_parent.key.id()) |
| 30 # No extra TestMetadata or Bot objects should have been added to the | 31 # No extra TestMetadata or Bot objects should have been added to the |
| 31 # database beyond the four that were put in before the _GetOrCreateAncestors | 32 # database beyond the four that were put in before the _GetOrCreateAncestors |
| 32 # call. | 33 # call. |
| 33 self.assertEqual(1, len(graph_data.Master.query().fetch())) | 34 self.assertEqual(1, len(graph_data.Master.query().fetch())) |
| 34 self.assertEqual(1, len(graph_data.Bot.query().fetch())) | 35 self.assertEqual(1, len(graph_data.Bot.query().fetch())) |
| 35 self.assertEqual(3, len(graph_data.TestMetadata.query().fetch())) | 36 self.assertEqual(3, len(graph_data.TestMetadata.query().fetch())) |
| 36 | 37 |
| 37 def testGetOrCreateAncestors_CreatesAllExpectedEntities(self): | 38 def testGetOrCreateAncestors_CreatesAllExpectedEntities(self): |
| 38 parent = add_point_queue._GetOrCreateAncestors( | 39 parent = add_point_queue.GetOrCreateAncestors( |
| 39 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') | 40 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') |
| 40 self.assertEqual('ChromiumPerf/win7/dromaeo/dom/modify', parent.key.id()) | 41 self.assertEqual('ChromiumPerf/win7/dromaeo/dom/modify', parent.key.id()) |
| 41 # Check that all the Bot and TestMetadata entities were correctly added. | 42 # Check that all the Bot and TestMetadata entities were correctly added. |
| 42 created_masters = graph_data.Master.query().fetch() | 43 created_masters = graph_data.Master.query().fetch() |
| 43 created_bots = graph_data.Bot.query().fetch() | 44 created_bots = graph_data.Bot.query().fetch() |
| 44 created_tests = graph_data.TestMetadata.query().fetch() | 45 created_tests = graph_data.TestMetadata.query().fetch() |
| 45 self.assertEqual(1, len(created_masters)) | 46 self.assertEqual(1, len(created_masters)) |
| 46 self.assertEqual(1, len(created_bots)) | 47 self.assertEqual(1, len(created_bots)) |
| 47 self.assertEqual(3, len(created_tests)) | 48 self.assertEqual(3, len(created_tests)) |
| 48 self.assertEqual('ChromiumPerf', created_masters[0].key.id()) | 49 self.assertEqual('ChromiumPerf', created_masters[0].key.id()) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 'ChromiumPerf/win7/dromaeo/dom', created_tests[2].parent_test.id()) | 63 'ChromiumPerf/win7/dromaeo/dom', created_tests[2].parent_test.id()) |
| 63 self.assertIsNone(created_tests[2].bot) | 64 self.assertIsNone(created_tests[2].bot) |
| 64 | 65 |
| 65 def testGetOrCreateAncestors_UpdatesStoppageAlert(self): | 66 def testGetOrCreateAncestors_UpdatesStoppageAlert(self): |
| 66 testing_common.AddTests(['M'], ['b'], {'suite': {'foo': {}}}) | 67 testing_common.AddTests(['M'], ['b'], {'suite': {'foo': {}}}) |
| 67 row = testing_common.AddRows('M/b/suite/foo', {123})[0] | 68 row = testing_common.AddRows('M/b/suite/foo', {123})[0] |
| 68 test = utils.TestKey('M/b/suite/foo').get() | 69 test = utils.TestKey('M/b/suite/foo').get() |
| 69 alert_key = stoppage_alert.CreateStoppageAlert(test, row).put() | 70 alert_key = stoppage_alert.CreateStoppageAlert(test, row).put() |
| 70 test.stoppage_alert = alert_key | 71 test.stoppage_alert = alert_key |
| 71 test.put() | 72 test.put() |
| 72 add_point_queue._GetOrCreateAncestors('M', 'b', 'suite/foo') | 73 add_point_queue.GetOrCreateAncestors('M', 'b', 'suite/foo') |
| 73 self.assertIsNone(test.key.get().stoppage_alert) | 74 self.assertIsNone(test.key.get().stoppage_alert) |
| 74 self.assertTrue(alert_key.get().recovered) | 75 self.assertTrue(alert_key.get().recovered) |
| 75 self.assertIsNotNone(alert_key.get().last_row_timestamp) | 76 self.assertIsNotNone(alert_key.get().last_row_timestamp) |
| 76 | 77 |
| 78 def testGetOrCreateAncestors_RespectsImprovementDirectionForNewTest(self): |
| 79 test = add_point_queue.GetOrCreateAncestors( |
| 80 'M', 'b', 'suite/foo', units='bogus', |
| 81 improvement_direction=anomaly.UP) |
| 82 self.assertEqual(anomaly.UP, test.improvement_direction) |
| 83 |
| 77 | 84 |
| 78 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 79 unittest.main() | 86 unittest.main() |
| OLD | NEW |