blob: 73b9f03832af866f27eb05802109b6b0b6e580ad [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed 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."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
13import webapp2
14
15from framework import banned
16from framework import monorailrequest
17from services import service_manager
18from testing import testing_helpers
19
20
21class BannedTest(unittest.TestCase):
22
23 def setUp(self):
24 self.services = service_manager.Services()
25
26 def testAssertBasePermission(self):
27 servlet = banned.Banned('request', 'response', services=self.services)
28
29 mr = monorailrequest.MonorailRequest(self.services)
30 mr.auth.user_id = 0 # Anon user cannot see banned page.
31 with self.assertRaises(webapp2.HTTPException) as cm:
32 servlet.AssertBasePermission(mr)
33 self.assertEqual(404, cm.exception.code)
34
35 mr.auth.user_id = 111 # User who is not banned cannot view banned page.
36 with self.assertRaises(webapp2.HTTPException) as cm:
37 servlet.AssertBasePermission(mr)
38 self.assertEqual(404, cm.exception.code)
39
40 # This should not throw exception.
41 mr.auth.user_pb.banned = 'spammer'
42 servlet.AssertBasePermission(mr)
43
44 def testGatherPageData(self):
45 servlet = banned.Banned('request', 'response', services=self.services)
46 self.assertNotEqual(servlet.template, None)
47
48 _request, mr = testing_helpers.GetRequestObjects()
49 page_data = servlet.GatherPageData(mr)
50
51 self.assertFalse(page_data['is_plus_address'])
52 self.assertEqual(None, page_data['currentPageURLEncoded'])
53
54 mr.auth.user_pb.email = 'user+shadystuff@example.com'
55 page_data = servlet.GatherPageData(mr)
56
57 self.assertTrue(page_data['is_plus_address'])
58 self.assertEqual(None, page_data['currentPageURLEncoded'])