| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import random | 9 import random |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 # Setups environment. | 13 # Setups environment. |
| 14 APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 14 APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 15 sys.path.insert(0, APP_DIR) | 15 sys.path.insert(0, APP_DIR) |
| 16 import test_env_handlers | 16 import test_env_handlers |
| 17 | 17 |
| 18 from google.appengine.api import datastore_errors |
| 18 from google.appengine.ext import ndb | 19 from google.appengine.ext import ndb |
| 19 | 20 |
| 20 import webtest | 21 import webtest |
| 21 | 22 |
| 22 import event_mon_metrics | 23 import event_mon_metrics |
| 23 import handlers_backend | 24 import handlers_backend |
| 24 | 25 |
| 25 from components import auth | 26 from components import auth |
| 26 from components import auth_testing | 27 from components import auth_testing |
| 27 from components import datastore_utils | 28 from components import datastore_utils |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 704 |
| 704 def test_schedule_request_forbidden_dim_via_star(self): | 705 def test_schedule_request_forbidden_dim_via_star(self): |
| 705 self.mock_dim_acls({u'abc:*': u'noone'}) | 706 self.mock_dim_acls({u'abc:*': u'noone'}) |
| 706 self._quick_schedule(properties={'dimensions': {u'pool': u'default'}}) | 707 self._quick_schedule(properties={'dimensions': {u'pool': u'default'}}) |
| 707 with self.assertRaises(auth.AuthorizationError): | 708 with self.assertRaises(auth.AuthorizationError): |
| 708 self._quick_schedule( | 709 self._quick_schedule( |
| 709 properties={'dimensions': {u'pool': u'default', u'abc': u'blah'}}) | 710 properties={'dimensions': {u'pool': u'default', u'abc': u'blah'}}) |
| 710 | 711 |
| 711 def test_schedule_request_id_without_pool(self): | 712 def test_schedule_request_id_without_pool(self): |
| 712 self.mock_dim_acls({u'pool:good': u'mocked'}) | 713 self.mock_dim_acls({u'pool:good': u'mocked'}) |
| 713 with self.assertRaises(auth.AuthorizationError): | 714 with self.assertRaises(datastore_errors.BadValueError): |
| 714 self._quick_schedule(properties={'dimensions': {u'id': u'abc'}}) | 715 self._quick_schedule(properties={'dimensions': {u'id': u'abc'}}) |
| 715 auth_testing.mock_is_admin(self) | 716 auth_testing.mock_is_admin(self) |
| 716 self._quick_schedule(properties={'dimensions': {u'id': u'abc'}}, nb_task=0) | 717 with self.assertRaises(datastore_errors.BadValueError): |
| 718 self._quick_schedule(properties={'dimensions': {u'id': u'abc'}}) |
| 717 | 719 |
| 718 def test_schedule_request_id_and_pool(self): | 720 def test_schedule_request_id_and_pool(self): |
| 719 self.mock_dim_acls({u'pool:good': u'mocked'}) | 721 self.mock_dim_acls({u'pool:good': u'mocked'}) |
| 720 self.mock_dim_acls({u'pool:bad': u'unknown'}) | 722 self.mock_dim_acls({u'pool:bad': u'unknown'}) |
| 721 | 723 |
| 722 def mocked_is_group_member(group, ident): | 724 def mocked_is_group_member(group, ident): |
| 723 if group == 'mocked' and ident == auth_testing.DEFAULT_MOCKED_IDENTITY: | 725 if group == 'mocked' and ident == auth_testing.DEFAULT_MOCKED_IDENTITY: |
| 724 return True | 726 return True |
| 725 return False | 727 return False |
| 726 self.mock(auth, 'is_group_member', mocked_is_group_member) | 728 self.mock(auth, 'is_group_member', mocked_is_group_member) |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 (['1d69b9f088008911'], 0, 0), | 1385 (['1d69b9f088008911'], 0, 0), |
| 1384 task_scheduler.cron_handle_bot_died('f.local')) | 1386 task_scheduler.cron_handle_bot_died('f.local')) |
| 1385 | 1387 |
| 1386 | 1388 |
| 1387 if __name__ == '__main__': | 1389 if __name__ == '__main__': |
| 1388 if '-v' in sys.argv: | 1390 if '-v' in sys.argv: |
| 1389 unittest.TestCase.maxDiff = None | 1391 unittest.TestCase.maxDiff = None |
| 1390 logging.basicConfig( | 1392 logging.basicConfig( |
| 1391 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 1393 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 1392 unittest.main() | 1394 unittest.main() |
| OLD | NEW |