Project import generated by Copybara.
GitOrigin-RevId: d9e9e3fb4e31372ec1fb43b178994ca78fa8fe70
diff --git a/framework/test/banned_test.py b/framework/test/banned_test.py
new file mode 100644
index 0000000..73b9f03
--- /dev/null
+++ b/framework/test/banned_test.py
@@ -0,0 +1,58 @@
+# Copyright 2016 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 or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Unittests for monorail.framework.banned."""
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+
+import unittest
+
+import webapp2
+
+from framework import banned
+from framework import monorailrequest
+from services import service_manager
+from testing import testing_helpers
+
+
+class BannedTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services()
+
+ def testAssertBasePermission(self):
+ servlet = banned.Banned('request', 'response', services=self.services)
+
+ mr = monorailrequest.MonorailRequest(self.services)
+ mr.auth.user_id = 0 # Anon user cannot see banned page.
+ with self.assertRaises(webapp2.HTTPException) as cm:
+ servlet.AssertBasePermission(mr)
+ self.assertEqual(404, cm.exception.code)
+
+ mr.auth.user_id = 111 # User who is not banned cannot view banned page.
+ with self.assertRaises(webapp2.HTTPException) as cm:
+ servlet.AssertBasePermission(mr)
+ self.assertEqual(404, cm.exception.code)
+
+ # This should not throw exception.
+ mr.auth.user_pb.banned = 'spammer'
+ servlet.AssertBasePermission(mr)
+
+ def testGatherPageData(self):
+ servlet = banned.Banned('request', 'response', services=self.services)
+ self.assertNotEqual(servlet.template, None)
+
+ _request, mr = testing_helpers.GetRequestObjects()
+ page_data = servlet.GatherPageData(mr)
+
+ self.assertFalse(page_data['is_plus_address'])
+ self.assertEqual(None, page_data['currentPageURLEncoded'])
+
+ mr.auth.user_pb.email = 'user+shadystuff@example.com'
+ page_data = servlet.GatherPageData(mr)
+
+ self.assertTrue(page_data['is_plus_address'])
+ self.assertEqual(None, page_data['currentPageURLEncoded'])