| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import contextlib | 5 import contextlib |
| 6 import datetime | 6 import datetime |
| 7 | 7 |
| 8 from components import auth | 8 from components import auth |
| 9 from components import net | 9 from components import net |
| 10 from components import utils | 10 from components import utils |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 'changes': [{ | 41 'changes': [{ |
| 42 'author': 'nodir@google.com', | 42 'author': 'nodir@google.com', |
| 43 'message': 'buildbucket: initial commit' | 43 'message': 'buildbucket: initial commit' |
| 44 }] | 44 }] |
| 45 } | 45 } |
| 46 ) | 46 ) |
| 47 | 47 |
| 48 self.current_identity = auth.Identity('service', 'unittest') | 48 self.current_identity = auth.Identity('service', 'unittest') |
| 49 self.mock(auth, 'get_current_identity', lambda: self.current_identity) | 49 self.mock(auth, 'get_current_identity', lambda: self.current_identity) |
| 50 self.mock(acl, 'can_async', lambda *_: future(True)) | 50 self.mock(acl, 'can_async', lambda *_: future(True)) |
| 51 self.mock(utils, 'utcnow', lambda: datetime.datetime(2015, 1, 1)) | 51 self.now = datetime.datetime(2015, 1, 1) |
| 52 self.mock(utils, 'utcnow', lambda: self.now) |
| 52 self.mock(swarming, 'is_for_swarming_async', mock.Mock()) | 53 self.mock(swarming, 'is_for_swarming_async', mock.Mock()) |
| 53 self.mock(swarming, 'create_task_async', mock.Mock()) | 54 self.mock(swarming, 'create_task_async', mock.Mock()) |
| 54 swarming.is_for_swarming_async.return_value = ndb.Future() | 55 swarming.is_for_swarming_async.return_value = ndb.Future() |
| 55 swarming.is_for_swarming_async.return_value.set_result(False) | 56 swarming.is_for_swarming_async.return_value.set_result(False) |
| 56 | 57 |
| 57 def put_many_builds(self): | 58 def put_many_builds(self): |
| 58 for _ in xrange(100): | 59 for _ in xrange(100): |
| 59 b = model.Build(bucket=self.test_build.bucket) | 60 b = model.Build(bucket=self.test_build.bucket) |
| 60 b.put() | 61 b.put() |
| 61 | 62 |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 self.test_build.bucket, model.BuildStatus.SCHEDULED) | 816 self.test_build.bucket, model.BuildStatus.SCHEDULED) |
| 816 | 817 |
| 817 def test_delete_many_builds_schedule_task(self): | 818 def test_delete_many_builds_schedule_task(self): |
| 818 service.delete_many_builds( | 819 service.delete_many_builds( |
| 819 self.test_build.bucket, model.BuildStatus.SCHEDULED) | 820 self.test_build.bucket, model.BuildStatus.SCHEDULED) |
| 820 | 821 |
| 821 def test_delete_many_completed_builds(self): | 822 def test_delete_many_completed_builds(self): |
| 822 with self.assertRaises(errors.InvalidInputError): | 823 with self.assertRaises(errors.InvalidInputError): |
| 823 service.delete_many_builds( | 824 service.delete_many_builds( |
| 824 self.test_build.bucket, model.BuildStatus.COMPLETED) | 825 self.test_build.bucket, model.BuildStatus.COMPLETED) |
| 826 |
| 827 ########################### LONGEST_PENDING_TIME ############################ |
| 828 |
| 829 def test_longest_pending_time(self): |
| 830 builds = [ |
| 831 model.Build( |
| 832 bucket='chromium', |
| 833 tags=['builder:x'], |
| 834 create_time=self.now - datetime.timedelta(minutes=10), |
| 835 ), |
| 836 model.Build( |
| 837 bucket='chromium', |
| 838 tags=['builder:x'], |
| 839 create_time=self.now - datetime.timedelta(minutes=20), |
| 840 ), |
| 841 model.Build( |
| 842 bucket='chromium', |
| 843 tags=['builder:y'], |
| 844 create_time=self.now - datetime.timedelta(minutes=30), |
| 845 ), |
| 846 ] |
| 847 for b in builds: |
| 848 b.put() |
| 849 actual = service.longest_pending_time('chromium', 'x') |
| 850 self.assertEqual(actual, datetime.timedelta(minutes=20)) |
| 851 |
| 852 def test_longest_pending_time_invalid_input(self): |
| 853 with self.assertRaises(errors.InvalidInputError): |
| 854 service.longest_pending_time('', 'x') |
| 855 with self.assertRaises(errors.InvalidInputError): |
| 856 service.longest_pending_time('chromium', '') |
| 857 |
| 858 def test_longest_pending_time_no_builds(self): |
| 859 actual = service.longest_pending_time('chromium', 'x') |
| 860 self.assertEqual(actual, datetime.timedelta(0)) |
| 861 |
| 862 def test_longest_pending_time_without_permissions(self): |
| 863 self.mock_cannot(acl.Action.ACCESS_BUCKET) |
| 864 with self.assertRaises(auth.AuthorizationError): |
| 865 service.longest_pending_time('chromium', 'x') |
| OLD | NEW |