Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2854)

Unified Diff: Tools/GardeningServer/alerts_test.py

Issue 465233002: Store alerts in sheriff-o-matic's memcache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simplify testing environment. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Tools/GardeningServer/alerts_test.py
diff --git a/Tools/GardeningServer/alerts_test.py b/Tools/GardeningServer/alerts_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..c2506cff1f66aa800a4a38eaeaa83f5d492d9427
--- /dev/null
+++ b/Tools/GardeningServer/alerts_test.py
@@ -0,0 +1,64 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import alerts
+import json
+import unittest
+import webtest
+
+from google.appengine.api import memcache
+from google.appengine.ext import testbed
+
+
+class AlertsTest(unittest.TestCase):
+ def setUp(self):
+ self.testbed = testbed.Testbed()
+ self.testbed.activate()
+ self.testbed.init_memcache_stub()
+ self.testapp = webtest.TestApp(alerts.app)
+
+ def tearDown(self):
+ self.testbed.deactivate()
+
+ def check_json_headers(self, res):
+ self.assertEqual(res.content_type, 'application/json')
+ # This is necessary for cross-site tools to retrieve alerts
+ self.assertEqual(res.headers['access-control-allow-origin'], '*')
+
+ def test_get_no_data_cached(self):
+ res = self.testapp.get('/alerts')
+ self.check_json_headers(res)
+ self.assertEqual(res.body, '')
+
+ def test_happy_path(self):
+ # Set it.
+ params = {'content': '{"alerts": ["hello", "world"]}'}
+ self.testapp.post('/alerts', params)
+
+ # Get it.
+ res = self.testapp.get('/alerts')
+ self.check_json_headers(res)
+ alerts = json.loads(res.body)
+
+ # The server should have stuck a 'date' on there.
+ self.assertTrue('date' in alerts)
+ self.assertEqual(type(alerts['date']), int)
+
+ self.assertEqual(alerts['alerts'], ['hello', 'world'])
+
+ def test_post_invalid_data_not_reflected(self):
+ params = {'content': '[{"this is not valid JSON'}
+ self.testapp.post('/alerts', params, status=400)
+ res = self.testapp.get('/alerts')
+ self.assertEqual(res.body, '')
+
+ def test_post_invalid_data_does_not_overwrite_valid_data(self):
+ # Populate the cache with something valid
+ params = {'content': '{"alerts": "everything is OK"}'}
+ self.testapp.post('/alerts', params)
+ self.testapp.post('/alerts', {'content': 'woozlwuzl'}, status=400)
+ res = self.testapp.get('/alerts')
+ self.check_json_headers(res)
+ alerts = json.loads(res.body)
+ self.assertEqual(alerts['alerts'], 'everything is OK')

Powered by Google App Engine
This is Rietveld 408576698