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 """Unit tests for servlet base class helper functions.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from framework import permissions |
| 11 from framework import servlet_helpers |
| 12 from proto import project_pb2 |
| 13 from testing import testing_helpers |
| 14 |
| 15 |
| 16 class EztDataTest(unittest.TestCase): |
| 17 |
| 18 def testGetBannerTime(self): |
| 19 """Tests GetBannerTime method.""" |
| 20 timestamp = ['2009', '3', '13', '21', '24', '5'] |
| 21 |
| 22 banner_time = servlet_helpers.GetBannerTime(timestamp) |
| 23 |
| 24 # Ensure that the banner timestamp falls in a timestamp range to account for |
| 25 # the test being run in different timezones. |
| 26 # Using "Sun, 12 Mar 2009 00:00:00 GMT" and "Sun, 15 Mar 2009 00:00:00 GMT". |
| 27 self.assertTrue(1236816000000 <= banner_time.ts <= 1237075200000) |
| 28 self.assertEqual(2009, banner_time.year) |
| 29 self.assertEqual(3, banner_time.month) |
| 30 self.assertEqual(13, banner_time.day) |
| 31 self.assertEqual(21, banner_time.hour) |
| 32 self.assertEqual(24, banner_time.minute) |
| 33 self.assertEqual(5, banner_time.second) |
| 34 self.assertEqual('Friday', banner_time.weekday) |
| 35 self.assertEqual('09:24PM', banner_time.hour_min) |
| 36 |
| 37 |
| 38 class AssertBasePermissionTest(unittest.TestCase): |
| 39 |
| 40 def testAccessGranted(self): |
| 41 _, mr = testing_helpers.GetRequestObjects(path='/hosting') |
| 42 # No exceptions should be raised. |
| 43 servlet_helpers.AssertBasePermission(mr) |
| 44 |
| 45 mr.auth.user_id = 123L |
| 46 # No exceptions should be raised. |
| 47 servlet_helpers.AssertBasePermission(mr) |
| 48 servlet_helpers.AssertBasePermissionForUser( |
| 49 mr.auth.user_pb, mr.auth.user_view) |
| 50 |
| 51 def testBanned(self): |
| 52 _, mr = testing_helpers.GetRequestObjects(path='/hosting') |
| 53 mr.auth.user_pb.banned = 'spammer' |
| 54 self.assertRaises( |
| 55 permissions.BannedUserException, |
| 56 servlet_helpers.AssertBasePermissionForUser, |
| 57 mr.auth.user_pb, mr.auth.user_view) |
| 58 self.assertRaises( |
| 59 permissions.BannedUserException, |
| 60 servlet_helpers.AssertBasePermission, mr) |
| 61 |
| 62 def testNoAccessToProject(self): |
| 63 project = project_pb2.Project() |
| 64 project.project_name = 'proj' |
| 65 project.access = project_pb2.ProjectAccess.MEMBERS_ONLY |
| 66 _, mr = testing_helpers.GetRequestObjects(path='/p/proj/', project=project) |
| 67 mr.perms = permissions.EMPTY_PERMISSIONSET |
| 68 self.assertRaises( |
| 69 permissions.PermissionException, |
| 70 servlet_helpers.AssertBasePermission, mr) |
| 71 |
| 72 |
| 73 if __name__ == '__main__': |
| 74 unittest.main() |
OLD | NEW |