OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 alerts |
5 import internal_alerts | 6 import internal_alerts |
6 import json | 7 import json |
7 import random | 8 import random |
8 import string | 9 import string |
9 import unittest | 10 import unittest |
10 import webtest | 11 import webtest |
11 | 12 |
12 from google.appengine.api import memcache | 13 from google.appengine.api import memcache |
13 from google.appengine.ext import testbed | 14 from google.appengine.ext import testbed |
14 | 15 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 # Populate the cache with something valid | 74 # Populate the cache with something valid |
74 params = {'content': '{"alerts": "everything is OK"}'} | 75 params = {'content': '{"alerts": "everything is OK"}'} |
75 self.testapp.post('/internal-alerts', params) | 76 self.testapp.post('/internal-alerts', params) |
76 self.testapp.post('/internal-alerts', {'content': 'woozlwuzl'}, | 77 self.testapp.post('/internal-alerts', {'content': 'woozlwuzl'}, |
77 status=400) | 78 status=400) |
78 res = self.testapp.get('/internal-alerts') | 79 res = self.testapp.get('/internal-alerts') |
79 self.check_json_headers(res) | 80 self.check_json_headers(res) |
80 internal_alerts = json.loads(res.body) | 81 internal_alerts = json.loads(res.body) |
81 self.assertEqual(internal_alerts['alerts'], 'everything is OK') | 82 self.assertEqual(internal_alerts['alerts'], 'everything is OK') |
82 | 83 |
| 84 def test_internal_alerts_stored_in_history_have_correct_type(self): |
| 85 test_alerts1 = {'alerts': ['hello', 'world', '1']} |
| 86 test_alerts2 = {'alerts': ['hello', 'world', '2']} |
| 87 self.testapp.post('/internal-alerts', |
| 88 {'content': json.dumps(test_alerts1)}) |
| 89 self.testapp.post('/internal-alerts', |
| 90 {'content': json.dumps(test_alerts2)}) |
| 91 alerts_query = alerts.AlertsJSON.query().order(alerts.AlertsJSON.date) |
| 92 stored_alerts = alerts_query.fetch(limit=3) |
| 93 self.assertEqual(2, len(stored_alerts)) |
| 94 self.assertEqual(stored_alerts[0].type, 'internal-alerts') |
| 95 self.assertEqual(stored_alerts[1].type, 'internal-alerts') |
| 96 |
| 97 def test_internal_alerts_same_as_last_alerts_are_added_to_history(self): |
| 98 test_alerts = {'alerts': ['hello', 'world']} |
| 99 alerts.AlertsJSON(json=json.dumps(test_alerts), type='alerts').put() |
| 100 self.testapp.post('/internal-alerts', |
| 101 {'content': json.dumps(test_alerts)}) |
| 102 alerts_query = alerts.AlertsJSON.query() |
| 103 self.assertEqual(2, alerts_query.count(limit=3)) |
| 104 |
83 def test_large_number_of_internal_alerts(self): | 105 def test_large_number_of_internal_alerts(self): |
84 self.user_helper('tester@google.com', '123') | 106 self.user_helper('tester@google.com', '123') |
85 # This generates ~2.5MB of JSON that compresses to ~750K. Real | 107 # This generates ~2.5MB of JSON that compresses to ~750K. Real |
86 # data compresses about 6x better. | 108 # data compresses about 6x better. |
87 random.seed(0xf00f00) | 109 random.seed(0xf00f00) |
88 put_internal_alerts = self.generate_fake_internal_alerts(4000) | 110 put_internal_alerts = self.generate_fake_internal_alerts(4000) |
89 | 111 |
90 params = {'content': json.dumps(put_internal_alerts)} | 112 params = {'content': json.dumps(put_internal_alerts)} |
91 self.testapp.post('/internal-alerts', params) | 113 self.testapp.post('/internal-alerts', params) |
92 | 114 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 181 |
160 def value(): | 182 def value(): |
161 generators = [time, build, revision, test, literal_array, | 183 generators = [time, build, revision, test, literal_array, |
162 literal_map] | 184 literal_map] |
163 return random.choice(generators)() | 185 return random.choice(generators)() |
164 | 186 |
165 alert = {} | 187 alert = {} |
166 for _ in range(random.randint(6, 9)): | 188 for _ in range(random.randint(6, 9)): |
167 alert[label()] = value() | 189 alert[label()] = value() |
168 return alert | 190 return alert |
OLD | NEW |