| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # Copyright 2015 The LUCI Authors. All rights reserved. | 3 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 4 # Use of this source code is governed by the Apache v2.0 license that can be | 4 # Use of this source code is governed by the Apache v2.0 license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import datetime | 8 import datetime |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 def test_bootstrap(self): | 129 def test_bootstrap(self): |
| 130 self._test_file('bootstrap') | 130 self._test_file('bootstrap') |
| 131 | 131 |
| 132 def test_bot_config(self): | 132 def test_bot_config(self): |
| 133 self._test_file('bot_config') | 133 self._test_file('bot_config') |
| 134 | 134 |
| 135 | 135 |
| 136 class TasksApiTest(BaseTest): | 136 class TasksApiTest(BaseTest): |
| 137 api_service_cls = handlers_endpoints.SwarmingTasksService | 137 api_service_cls = handlers_endpoints.SwarmingTasksService |
| 138 | 138 |
| 139 def setUp(self): |
| 140 super(TasksApiTest, self).setUp() |
| 141 utils.clear_cache(config.settings) |
| 142 |
| 139 def test_new_ok_raw(self): | 143 def test_new_ok_raw(self): |
| 140 """Asserts that new generates appropriate metadata.""" | 144 """Asserts that new generates appropriate metadata.""" |
| 141 self.mock(random, 'getrandbits', lambda _: 0x88) | 145 self.mock(random, 'getrandbits', lambda _: 0x88) |
| 142 now = datetime.datetime(2010, 1, 2, 3, 4, 5) | 146 now = datetime.datetime(2010, 1, 2, 3, 4, 5) |
| 143 self.mock_now(now) | 147 self.mock_now(now) |
| 144 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) | 148 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) |
| 145 request = swarming_rpcs.NewTaskRequest( | 149 request = swarming_rpcs.NewTaskRequest( |
| 146 expiration_secs=30, | 150 expiration_secs=30, |
| 147 name='job1', | 151 name='job1', |
| 148 priority=200, | 152 priority=200, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 u'priority:200', | 502 u'priority:200', |
| 499 u'user:joe@localhost', | 503 u'user:joe@localhost', |
| 500 ], | 504 ], |
| 501 u'user': u'joe@localhost', | 505 u'user': u'joe@localhost', |
| 502 }, | 506 }, |
| 503 u'task_id': u'5cee488008810', | 507 u'task_id': u'5cee488008810', |
| 504 } | 508 } |
| 505 response = self.call_api('new', body=message_to_dict(request)) | 509 response = self.call_api('new', body=message_to_dict(request)) |
| 506 self.assertEqual(expected, response.json) | 510 self.assertEqual(expected, response.json) |
| 507 | 511 |
| 512 def test_new_ok_isolated_with_defaults(self): |
| 513 self.mock(random, 'getrandbits', lambda _: 0x88) |
| 514 now = datetime.datetime(2010, 1, 2, 3, 4, 5) |
| 515 self.mock_now(now) |
| 516 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) |
| 517 |
| 518 cfg = config.settings() |
| 519 cfg.isolate.default_server = 'https://isolateserver.appspot.com' |
| 520 cfg.isolate.default_namespace = 'default-gzip' |
| 521 self.mock(config, 'settings', lambda: cfg) |
| 522 |
| 523 request = swarming_rpcs.NewTaskRequest( |
| 524 expiration_secs=30, |
| 525 name='job1', |
| 526 priority=200, |
| 527 properties=swarming_rpcs.TaskProperties( |
| 528 dimensions=[ |
| 529 swarming_rpcs.StringPair(key='pool', value='default'), |
| 530 swarming_rpcs.StringPair(key='foo', value='bar'), |
| 531 ], |
| 532 env=[ |
| 533 swarming_rpcs.StringPair(key='PATH', value='/'), |
| 534 ], |
| 535 execution_timeout_secs=30, |
| 536 inputs_ref=swarming_rpcs.FilesRef(isolated='1'*40), |
| 537 io_timeout_secs=30), |
| 538 tags=['foo:bar'], |
| 539 user='joe@localhost') |
| 540 expected = { |
| 541 u'request': { |
| 542 u'authenticated': u'user:user@example.com', |
| 543 u'created_ts': str_now, |
| 544 u'expiration_secs': u'30', |
| 545 u'name': u'job1', |
| 546 u'priority': u'200', |
| 547 u'properties': { |
| 548 u'dimensions': [ |
| 549 {u'key': u'foo', u'value': u'bar'}, |
| 550 {u'key': u'pool', u'value': u'default'}, |
| 551 ], |
| 552 u'env': [ |
| 553 {u'key': u'PATH', u'value': u'/'}, |
| 554 ], |
| 555 u'execution_timeout_secs': u'30', |
| 556 u'grace_period_secs': u'30', |
| 557 u'idempotent': False, |
| 558 u'inputs_ref': { |
| 559 'isolated': '1'*40, |
| 560 'isolatedserver': 'https://isolateserver.appspot.com', |
| 561 'namespace': 'default-gzip', |
| 562 }, |
| 563 u'io_timeout_secs': u'30', |
| 564 }, |
| 565 u'tags': [ |
| 566 u'foo:bar', |
| 567 u'pool:default', |
| 568 u'priority:200', |
| 569 u'user:joe@localhost', |
| 570 ], |
| 571 u'user': u'joe@localhost', |
| 572 }, |
| 573 u'task_id': u'5cee488008810', |
| 574 } |
| 575 response = self.call_api('new', body=message_to_dict(request)) |
| 576 self.assertEqual(expected, response.json) |
| 577 |
| 508 def test_list_ok(self): | 578 def test_list_ok(self): |
| 509 """Asserts that list requests all TaskResultSummaries.""" | 579 """Asserts that list requests all TaskResultSummaries.""" |
| 510 first, second, str_now_120, start, end = self._gen_two_tasks() | 580 first, second, str_now_120, start, end = self._gen_two_tasks() |
| 511 first_no_perf = first.copy() | 581 first_no_perf = first.copy() |
| 512 first_no_perf.pop('performance_stats') | 582 first_no_perf.pop('performance_stats') |
| 513 # Basic request. | 583 # Basic request. |
| 514 request = swarming_rpcs.TasksRequest( | 584 request = swarming_rpcs.TasksRequest( |
| 515 end=end, start=start, include_performance_stats=True) | 585 end=end, start=start, include_performance_stats=True) |
| 516 expected = {u'now': str_now_120, u'items': [second, first]} | 586 expected = {u'now': str_now_120, u'items': [second, first]} |
| 517 actual = self.call_api('list', body=message_to_dict(request)).json | 587 actual = self.call_api('list', body=message_to_dict(request)).json |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 self.assertEqual(expected, response.json) | 1433 self.assertEqual(expected, response.json) |
| 1364 | 1434 |
| 1365 | 1435 |
| 1366 if __name__ == '__main__': | 1436 if __name__ == '__main__': |
| 1367 if '-v' in sys.argv: | 1437 if '-v' in sys.argv: |
| 1368 unittest.TestCase.maxDiff = None | 1438 unittest.TestCase.maxDiff = None |
| 1369 logging.basicConfig(level=logging.DEBUG) | 1439 logging.basicConfig(level=logging.DEBUG) |
| 1370 else: | 1440 else: |
| 1371 logging.basicConfig(level=logging.CRITICAL) | 1441 logging.basicConfig(level=logging.CRITICAL) |
| 1372 unittest.main() | 1442 unittest.main() |
| OLD | NEW |