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

Unified Diff: Tools/GardeningServer/alerts_test.py

Issue 664563002: Restructured alerts-history endpoint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « Tools/GardeningServer/alerts.py ('k') | Tools/GardeningServer/app.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/GardeningServer/alerts_test.py
diff --git a/Tools/GardeningServer/alerts_test.py b/Tools/GardeningServer/alerts_test.py
index 9933d738978d23d49799a5141702a20da6fdfaed..2c6a401336d1d39164901d7c76e61fcc14d8d509 100644
--- a/Tools/GardeningServer/alerts_test.py
+++ b/Tools/GardeningServer/alerts_test.py
@@ -101,11 +101,57 @@ class AlertsTest(unittest.TestCase):
response = self.testapp.get('/alerts-history')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
- response_json = json.loads(response.normal_body)
- self.assertEqual(len(response_json['history']), 1)
- self.assertEqual(response_json['history'][0], test_alert)
+ parsed_json = json.loads(response.normal_body)
+ self.assertEqual(len(parsed_json['history']), 1)
+
+ entry_id = parsed_json['history'][0]
+ response = self.testapp.get('/alerts-history/%s' % entry_id)
+ self.assertEqual(response.status_int, 200)
+ self.assertEqual(response.content_type, 'application/json')
+ parsed_json = json.loads(response.normal_body)
+ self.assertEqual(parsed_json['alerts'], test_alert['alerts'])
+
+ def test_provides_login_url(self):
+ response = self.testapp.get('/alerts-history')
+ self.assertIn('login-url', response)
+
+ def test_invalid_keys_return_400(self):
+ response = self.testapp.get('/alerts-history/kjhg$%T',
+ expect_errors=True)
+ self.assertEqual(response.status_int, 400)
+ self.assertEqual(response.content_type, 'application/json')
+
+ def test_non_existing_keys_return_404(self):
+ response = self.testapp.get('/alerts-history/5348024557502464',
+ expect_errors=True)
+ self.assertEqual(response.status_int, 404)
+ self.assertEqual(response.content_type, 'application/json')
+
+ def test_internal_alerts_can_only_retrieved_by_internal_users(self):
+ test_alert = {'alerts': ['hello', 'world', '1']}
+ internal_alert = alerts.AlertsJSON(json=json.dumps(test_alert),
+ type='internal-alerts')
+ internal_alert_key = internal_alert.put().integer_id()
+
+ # No signed-in user.
+ response = self.testapp.get('/alerts-history/%s' % internal_alert_key,
+ expect_errors=True)
+ self.assertEqual(response.status_int, 404)
+ self.assertEqual(response.content_type, 'application/json')
+ parsed_json = json.loads(response.normal_body)
+ self.assertNotIn('alerts', parsed_json)
+
+ # Non-internal user.
+ self.testbed.setup_env(USER_EMAIL='test@example.com', USER_ID='1',
+ USER_IS_ADMIN='1', overwrite=True)
+ response = self.testapp.get('/alerts-history/%s' % internal_alert_key,
+ expect_errors=True)
+ self.assertEqual(response.status_int, 404)
+ self.assertEqual(response.content_type, 'application/json')
+ parsed_json = json.loads(response.normal_body)
+ self.assertNotIn('alerts', parsed_json)
- def test_internal_alerts_in_history_visible_to_internal_users_only(self):
+ def test_lists_internal_alerts_to_internal_users_only(self):
test_alert = {'alerts': ['hello', 'world', '1']}
alerts.AlertsJSON(json=json.dumps(test_alert),
type='internal-alerts').put()
@@ -134,7 +180,6 @@ class AlertsTest(unittest.TestCase):
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 1)
- self.assertEqual(response_json['history'][0], test_alert)
def test_returned_alerts_from_history_are_paged(self):
for i in range(20):
« no previous file with comments | « Tools/GardeningServer/alerts.py ('k') | Tools/GardeningServer/app.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698