OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 json | 5 import json |
6 import webapp2 | 6 import webapp2 |
7 import webtest | 7 import webtest |
8 | 8 |
| 9 from google.appengine.ext import ndb |
| 10 |
9 from dashboard import add_histograms_queue | 11 from dashboard import add_histograms_queue |
10 from dashboard.common import testing_common | 12 from dashboard.common import testing_common |
11 from dashboard.common import utils | 13 from dashboard.common import utils |
| 14 from dashboard.models import anomaly |
| 15 from dashboard.models import graph_data |
12 from dashboard.models import histogram | 16 from dashboard.models import histogram |
13 | 17 |
14 | 18 |
15 | |
16 TEST_HISTOGRAM = json.dumps({ | 19 TEST_HISTOGRAM = json.dumps({ |
17 'guid': 'a5dd1360-fed5-4872-9f0e-c1c079b2ae26', | 20 'guid': 'a5dd1360-fed5-4872-9f0e-c1c079b2ae26', |
18 'binBoundaries': [1, [1, 1000, 20]], | 21 'binBoundaries': [1, [1, 1000, 20]], |
19 'name': 'foo', | 22 'name': 'foo', |
20 'unit': 'count' | 23 'unit': 'count_biggerIsBetter' |
21 }) | 24 }) |
22 | 25 |
23 | 26 |
| 27 TEST_SPARSE_DIAGNOSTIC = json.dumps({ |
| 28 'guid': 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb', |
| 29 'benchmarkName': 'myBenchmark', |
| 30 'canonicalUrl': 'myCanonicalUrl', |
| 31 'label': 'myLabel', |
| 32 'legacyTIRLabel': 'myLegacyTIRLabel', |
| 33 'storyDisplayName': 'myStoryDisplayName', |
| 34 'type': 'TelemetryInfo' |
| 35 }) |
| 36 |
| 37 |
24 class AddHistogramsQueueTest(testing_common.TestCase): | 38 class AddHistogramsQueueTest(testing_common.TestCase): |
25 def setUp(self): | 39 def setUp(self): |
26 super(AddHistogramsQueueTest, self).setUp() | 40 super(AddHistogramsQueueTest, self).setUp() |
27 app = webapp2.WSGIApplication([ | 41 app = webapp2.WSGIApplication([ |
28 ('/add_histograms_queue', | 42 ('/add_histograms_queue', |
29 add_histograms_queue.AddHistogramsQueueHandler)]) | 43 add_histograms_queue.AddHistogramsQueueHandler)]) |
30 self.testapp = webtest.TestApp(app) | 44 self.testapp = webtest.TestApp(app) |
31 self.SetCurrentUser('foo@bar.com', is_admin=True) | 45 self.SetCurrentUser('foo@bar.com', is_admin=True) |
32 | 46 |
33 def testPost(self): | 47 def testPostHistogram(self): |
34 test_path = 'Chromium/win7/suite/metric' | 48 test_path = 'Chromium/win7/suite/metric' |
35 params = { | 49 params = { |
36 'data': TEST_HISTOGRAM, | 50 'data': TEST_HISTOGRAM, |
37 'test_path': test_path, | 51 'test_path': test_path, |
38 'revision': 123 | 52 'revision': 123 |
39 } | 53 } |
40 test_key = utils.TestKey(test_path) | |
41 self.testapp.post('/add_histograms_queue', params) | 54 self.testapp.post('/add_histograms_queue', params) |
42 | 55 |
| 56 test_key = utils.TestKey(test_path) |
43 original_histogram = json.loads(TEST_HISTOGRAM) | 57 original_histogram = json.loads(TEST_HISTOGRAM) |
44 | 58 |
| 59 test = test_key.get() |
| 60 self.assertEqual(test.units, 'count_biggerIsBetter') |
| 61 self.assertEqual(test.improvement_direction, anomaly.UP) |
| 62 |
| 63 master = ndb.Key('Master', 'Chromium').get() |
| 64 self.assertIsNotNone(master) |
| 65 |
| 66 bot = ndb.Key('Master', 'Chromium', 'Bot', 'win7').get() |
| 67 self.assertIsNotNone(bot) |
| 68 |
| 69 tests = graph_data.TestMetadata.query().fetch() |
| 70 self.assertEqual(2, len(tests)) |
| 71 |
45 histograms = histogram.Histogram.query().fetch() | 72 histograms = histogram.Histogram.query().fetch() |
46 self.assertEqual(1, len(histograms)) | 73 self.assertEqual(1, len(histograms)) |
47 self.assertEqual(original_histogram['guid'], histograms[0].key.id()) | 74 self.assertEqual(original_histogram['guid'], histograms[0].key.id()) |
48 | 75 |
49 h = histograms[0] | 76 h = histograms[0] |
50 self.assertEqual(TEST_HISTOGRAM, h.data) | 77 self.assertEqual(TEST_HISTOGRAM, h.data) |
51 self.assertEqual(test_key, h.test) | 78 self.assertEqual(test_key, h.test) |
52 self.assertEqual(123, h.revision) | 79 self.assertEqual(123, h.revision) |
| 80 |
| 81 def testPostSparseDiagnostic(self): |
| 82 test_path = 'Chromium/win7/suite/metric' |
| 83 params = { |
| 84 'data': TEST_SPARSE_DIAGNOSTIC, |
| 85 'test_path': test_path, |
| 86 'revision': 123 |
| 87 } |
| 88 self.testapp.post('/add_histograms_queue', params) |
| 89 |
| 90 test_key = utils.TestKey(test_path) |
| 91 |
| 92 test = test_key.get() |
| 93 self.assertIsNone(test.units) |
| 94 |
| 95 def testGetUnitArgs_Up(self): |
| 96 unit_args = add_histograms_queue.GetUnitArgs('count_biggerIsBetter') |
| 97 self.assertEquals(anomaly.UP, unit_args['improvement_direction']) |
| 98 |
| 99 def testGetUnitArgs_Down(self): |
| 100 unit_args = add_histograms_queue.GetUnitArgs('count_smallerIsBetter') |
| 101 self.assertEquals(anomaly.DOWN, unit_args['improvement_direction']) |
| 102 |
| 103 def testGetUnitArgs_Unknown(self): |
| 104 unit_args = add_histograms_queue.GetUnitArgs('count') |
| 105 self.assertEquals(anomaly.UNKNOWN, unit_args['improvement_direction']) |
OLD | NEW |