Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2478)

Unified Diff: appengine/monorail/framework/test/servlet_helpers_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/framework/test/servlet_helpers_test.py
diff --git a/appengine/monorail/framework/test/servlet_helpers_test.py b/appengine/monorail/framework/test/servlet_helpers_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..34c9a894e6746ea59ac97aab00d302e8dd12c0a1
--- /dev/null
+++ b/appengine/monorail/framework/test/servlet_helpers_test.py
@@ -0,0 +1,74 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Unit tests for servlet base class helper functions."""
+
+import unittest
+
+from framework import permissions
+from framework import servlet_helpers
+from proto import project_pb2
+from testing import testing_helpers
+
+
+class EztDataTest(unittest.TestCase):
+
+ def testGetBannerTime(self):
+ """Tests GetBannerTime method."""
+ timestamp = ['2009', '3', '13', '21', '24', '5']
+
+ banner_time = servlet_helpers.GetBannerTime(timestamp)
+
+ # Ensure that the banner timestamp falls in a timestamp range to account for
+ # the test being run in different timezones.
+ # Using "Sun, 12 Mar 2009 00:00:00 GMT" and "Sun, 15 Mar 2009 00:00:00 GMT".
+ self.assertTrue(1236816000000 <= banner_time.ts <= 1237075200000)
+ self.assertEqual(2009, banner_time.year)
+ self.assertEqual(3, banner_time.month)
+ self.assertEqual(13, banner_time.day)
+ self.assertEqual(21, banner_time.hour)
+ self.assertEqual(24, banner_time.minute)
+ self.assertEqual(5, banner_time.second)
+ self.assertEqual('Friday', banner_time.weekday)
+ self.assertEqual('09:24PM', banner_time.hour_min)
+
+
+class AssertBasePermissionTest(unittest.TestCase):
+
+ def testAccessGranted(self):
+ _, mr = testing_helpers.GetRequestObjects(path='/hosting')
+ # No exceptions should be raised.
+ servlet_helpers.AssertBasePermission(mr)
+
+ mr.auth.user_id = 123L
+ # No exceptions should be raised.
+ servlet_helpers.AssertBasePermission(mr)
+ servlet_helpers.AssertBasePermissionForUser(
+ mr.auth.user_pb, mr.auth.user_view)
+
+ def testBanned(self):
+ _, mr = testing_helpers.GetRequestObjects(path='/hosting')
+ mr.auth.user_pb.banned = 'spammer'
+ self.assertRaises(
+ permissions.BannedUserException,
+ servlet_helpers.AssertBasePermissionForUser,
+ mr.auth.user_pb, mr.auth.user_view)
+ self.assertRaises(
+ permissions.BannedUserException,
+ servlet_helpers.AssertBasePermission, mr)
+
+ def testNoAccessToProject(self):
+ project = project_pb2.Project()
+ project.project_name = 'proj'
+ project.access = project_pb2.ProjectAccess.MEMBERS_ONLY
+ _, mr = testing_helpers.GetRequestObjects(path='/p/proj/', project=project)
+ mr.perms = permissions.EMPTY_PERMISSIONSET
+ self.assertRaises(
+ permissions.PermissionException,
+ servlet_helpers.AssertBasePermission, mr)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/framework/test/registerpages_helpers_test.py ('k') | appengine/monorail/framework/test/servlet_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698