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 3 # found in the LICENSE file. 4 5 import unittest 6 7 from dashboard import add_point_queue 8 from dashboard import testing_common 9 from dashboard import utils 10 from dashboard.models import graph_data 11 from dashboard.models import stoppage_alert 12 13 14 class GetOrCreateAncestorsTest(testing_common.TestCase): 15 16 def setUp(self): 17 super(GetOrCreateAncestorsTest, self).setUp() 18 self.SetCurrentUser('foo (at] bar.com', is_admin=True) 19 20 def testGetOrCreateAncestors_GetsExistingEntities(self): 21 master_key = graph_data.Master(id='ChromiumPerf', parent=None).put() 22 bot_key = graph_data.Bot(id='win7', parent=master_key).put() 23 suite_key = graph_data.Test(id='dromaeo', parent=bot_key).put() 24 subtest_key = graph_data.Test(id='dom', parent=suite_key).put() 25 graph_data.Test(id='modify', parent=subtest_key).put() 26 actual_parent = add_point_queue._GetOrCreateAncestors( 27 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') 28 self.assertEqual('modify', actual_parent.key.id()) 29 # No extra Test or Bot objects should have been added to the database 30 # beyond the four that were put in before the _GetOrCreateAncestors call. 31 self.assertEqual(1, len(graph_data.Master.query().fetch())) 32 self.assertEqual(1, len(graph_data.Bot.query().fetch())) 33 self.assertEqual(3, len(graph_data.Test.query().fetch())) 34 35 def testGetOrCreateAncestors_CreatesAllExpectedEntities(self): 36 parent = add_point_queue._GetOrCreateAncestors( 37 'ChromiumPerf', 'win7', 'dromaeo/dom/modify') 38 self.assertEqual('modify', parent.key.id()) 39 # Check that all the Bot and Test entities were correctly added. 40 created_masters = graph_data.Master.query().fetch() 41 created_bots = graph_data.Bot.query().fetch() 42 created_tests = graph_data.Test.query().fetch() 43 self.assertEqual(1, len(created_masters)) 44 self.assertEqual(1, len(created_bots)) 45 self.assertEqual(3, len(created_tests)) 46 self.assertEqual('ChromiumPerf', created_masters[0].key.id()) 47 self.assertIsNone(created_masters[0].key.parent()) 48 self.assertEqual('win7', created_bots[0].key.id()) 49 self.assertEqual('ChromiumPerf', created_bots[0].key.parent().id()) 50 self.assertEqual('dromaeo', created_tests[0].key.id()) 51 self.assertIsNone(created_tests[0].parent_test) 52 self.assertEqual('win7', created_tests[0].bot.id()) 53 self.assertEqual('dom', created_tests[1].key.id()) 54 self.assertEqual('dromaeo', created_tests[1].parent_test.id()) 55 self.assertIsNone(created_tests[1].bot) 56 self.assertEqual('modify', created_tests[2].key.id()) 57 self.assertEqual('dom', created_tests[2].parent_test.id()) 58 self.assertIsNone(created_tests[2].bot) 59 60 def testGetOrCreateAncestors_UpdatesStoppageAlert(self): 61 testing_common.AddTests(['M'], ['b'], {'suite': {'foo': {}}}) 62 row = testing_common.AddRows('M/b/suite/foo', {123})[0] 63 test = utils.TestKey('M/b/suite/foo').get() 64 alert_key = stoppage_alert.CreateStoppageAlert(test, row).put() 65 test.stoppage_alert = alert_key 66 test.put() 67 add_point_queue._GetOrCreateAncestors('M', 'b', 'suite/foo') 68 self.assertIsNone(test.key.get().stoppage_alert) 69 self.assertTrue(alert_key.get().recovered) 70 71 72 if __name__ == '__main__': 73 unittest.main() 74