OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Unittests for monorail.framework.banned.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 import webapp2 |
| 11 |
| 12 from framework import banned |
| 13 from framework import monorailrequest |
| 14 from services import service_manager |
| 15 from testing import testing_helpers |
| 16 |
| 17 |
| 18 class BannedTest(unittest.TestCase): |
| 19 |
| 20 def testAssertBasePermission(self): |
| 21 servlet = banned.Banned( |
| 22 'request', 'response', services=service_manager.Services()) |
| 23 |
| 24 mr = monorailrequest.MonorailRequest() |
| 25 mr.auth.user_id = 0L # Anon user cannot see banned page. |
| 26 try: |
| 27 servlet.AssertBasePermission(mr) |
| 28 self.fail() |
| 29 except webapp2.HTTPException as e: |
| 30 self.assertEquals(404, e.code) |
| 31 |
| 32 mr.auth.user_id = 111L # User who is not banned cannot view banned page. |
| 33 try: |
| 34 servlet.AssertBasePermission(mr) |
| 35 self.fail() |
| 36 except webapp2.HTTPException as e: |
| 37 self.assertEquals(404, e.code) |
| 38 |
| 39 # This should not throw exception. |
| 40 mr.auth.user_pb.banned = 'spammer' |
| 41 servlet.AssertBasePermission(mr) |
| 42 |
| 43 def testGatherPageData(self): |
| 44 servlet = banned.Banned( |
| 45 'request', 'response', services=service_manager.Services()) |
| 46 self.assertNotEquals(servlet.template, None) |
| 47 |
| 48 _request, mr = testing_helpers.GetRequestObjects() |
| 49 page_data = servlet.GatherPageData(mr) |
| 50 |
| 51 self.assertEquals(None, page_data['currentPageURLEncoded']) |
| 52 |
| 53 |
| 54 if __name__ == '__main__': |
| 55 unittest.main() |
OLD | NEW |