| 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_key(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].key, 'internal-alerts') |
| 95 self.assertEqual(stored_alerts[1].key, 'internal-alerts') |
| 96 |
| 83 def test_large_number_of_internal_alerts(self): | 97 def test_large_number_of_internal_alerts(self): |
| 84 self.user_helper('tester@google.com', '123') | 98 self.user_helper('tester@google.com', '123') |
| 85 # This generates ~2.5MB of JSON that compresses to ~750K. Real | 99 # This generates ~2.5MB of JSON that compresses to ~750K. Real |
| 86 # data compresses about 6x better. | 100 # data compresses about 6x better. |
| 87 random.seed(0xf00f00) | 101 random.seed(0xf00f00) |
| 88 put_internal_alerts = self.generate_fake_internal_alerts(4000) | 102 put_internal_alerts = self.generate_fake_internal_alerts(4000) |
| 89 | 103 |
| 90 params = {'content': json.dumps(put_internal_alerts)} | 104 params = {'content': json.dumps(put_internal_alerts)} |
| 91 self.testapp.post('/internal-alerts', params) | 105 self.testapp.post('/internal-alerts', params) |
| 92 | 106 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 173 |
| 160 def value(): | 174 def value(): |
| 161 generators = [time, build, revision, test, literal_array, | 175 generators = [time, build, revision, test, literal_array, |
| 162 literal_map] | 176 literal_map] |
| 163 return random.choice(generators)() | 177 return random.choice(generators)() |
| 164 | 178 |
| 165 alert = {} | 179 alert = {} |
| 166 for _ in range(random.randint(6, 9)): | 180 for _ in range(random.randint(6, 9)): |
| 167 alert[label()] = value() | 181 alert[label()] = value() |
| 168 return alert | 182 return alert |
| OLD | NEW |