blob: f07b6e87bed6abdb9578ddeb18e83767fa096c5e [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unittests for monorail.framework.banned."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
Copybara854996b2021-09-07 19:36:02 +000012from framework import banned
13from framework import monorailrequest
14from services import service_manager
15from testing import testing_helpers
16
17
18class BannedTest(unittest.TestCase):
19
20 def setUp(self):
21 self.services = service_manager.Services()
22
23 def testAssertBasePermission(self):
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020024 servlet = banned.Banned(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000025
26 mr = monorailrequest.MonorailRequest(self.services)
27 mr.auth.user_id = 0 # Anon user cannot see banned page.
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020028 with self.assertRaises(Exception) as cm:
Copybara854996b2021-09-07 19:36:02 +000029 servlet.AssertBasePermission(mr)
30 self.assertEqual(404, cm.exception.code)
31
32 mr.auth.user_id = 111 # User who is not banned cannot view banned page.
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020033 with self.assertRaises(Exception) as cm:
Copybara854996b2021-09-07 19:36:02 +000034 servlet.AssertBasePermission(mr)
35 self.assertEqual(404, cm.exception.code)
36
37 # This should not throw exception.
38 mr.auth.user_pb.banned = 'spammer'
39 servlet.AssertBasePermission(mr)
40
41 def testGatherPageData(self):
Adrià Vilanova Martínez9f9ade52022-10-10 23:20:11 +020042 servlet = banned.Banned(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000043 self.assertNotEqual(servlet.template, None)
44
45 _request, mr = testing_helpers.GetRequestObjects()
46 page_data = servlet.GatherPageData(mr)
47
48 self.assertFalse(page_data['is_plus_address'])
49 self.assertEqual(None, page_data['currentPageURLEncoded'])
50
51 mr.auth.user_pb.email = 'user+shadystuff@example.com'
52 page_data = servlet.GatherPageData(mr)
53
54 self.assertTrue(page_data['is_plus_address'])
55 self.assertEqual(None, page_data['currentPageURLEncoded'])