| 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 random | 8 import random |
| 9 import sys | 9 import sys |
| 10 import unittest | 10 import unittest |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 'extra_args': [], | 248 'extra_args': [], |
| 249 'execution_timeout_secs': 30, | 249 'execution_timeout_secs': 30, |
| 250 'grace_period_secs': 30, | 250 'grace_period_secs': 30, |
| 251 'idempotent': True, | 251 'idempotent': True, |
| 252 'inputs_ref': { | 252 'inputs_ref': { |
| 253 'isolated': None, | 253 'isolated': None, |
| 254 'isolatedserver': 'https://isolateserver.appspot.com', | 254 'isolatedserver': 'https://isolateserver.appspot.com', |
| 255 'namespace': 'default-gzip', | 255 'namespace': 'default-gzip', |
| 256 }, | 256 }, |
| 257 'io_timeout_secs': None, | 257 'io_timeout_secs': None, |
| 258 'outputs': [], |
| 258 } | 259 } |
| 259 expected_request = { | 260 expected_request = { |
| 260 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 261 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 261 'name': u'Request name', | 262 'name': u'Request name', |
| 262 'parent_task_id': unicode(parent_id), | 263 'parent_task_id': unicode(parent_id), |
| 263 'priority': 49, | 264 'priority': 49, |
| 264 'properties': expected_properties, | 265 'properties': expected_properties, |
| 265 # Intentionally hard code the hash value since it has to be deterministic. | 266 # Intentionally hard code the hash value since it has to be deterministic. |
| 266 # Other unit tests should use the calculated value. | 267 # Other unit tests should use the calculated value. |
| 267 'properties_hash': '2202337f592f7e31b407e38832c35e23f306c6c8', | 268 'properties_hash': 'c6e0db8e858dd5b1bdae0e8eae7486f4a8a82967', |
| 268 'pubsub_topic': None, | 269 'pubsub_topic': None, |
| 269 'pubsub_userdata': None, | 270 'pubsub_userdata': None, |
| 270 'service_account': u'none', | 271 'service_account': u'none', |
| 271 'tags': [ | 272 'tags': [ |
| 272 u'OS:Windows-3.1.1', | 273 u'OS:Windows-3.1.1', |
| 273 u'hostname:localhost', | 274 u'hostname:localhost', |
| 274 u'pool:default', | 275 u'pool:default', |
| 275 u'priority:49', | 276 u'priority:49', |
| 276 u'service_account:none', | 277 u'service_account:none', |
| 277 u'tag:1', | 278 u'tag:1', |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 'extra_args': [], | 324 'extra_args': [], |
| 324 'execution_timeout_secs': 30, | 325 'execution_timeout_secs': 30, |
| 325 'grace_period_secs': 30, | 326 'grace_period_secs': 30, |
| 326 'idempotent': True, | 327 'idempotent': True, |
| 327 'inputs_ref': { | 328 'inputs_ref': { |
| 328 'isolated': None, | 329 'isolated': None, |
| 329 'isolatedserver': 'https://isolateserver.appspot.com', | 330 'isolatedserver': 'https://isolateserver.appspot.com', |
| 330 'namespace': 'default-gzip', | 331 'namespace': 'default-gzip', |
| 331 }, | 332 }, |
| 332 'io_timeout_secs': None, | 333 'io_timeout_secs': None, |
| 334 'outputs': [], |
| 333 } | 335 } |
| 334 expected_request = { | 336 expected_request = { |
| 335 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 337 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 336 'name': u'Request name', | 338 'name': u'Request name', |
| 337 'parent_task_id': unicode(parent_id), | 339 'parent_task_id': unicode(parent_id), |
| 338 'priority': 49, | 340 'priority': 49, |
| 339 'properties': expected_properties, | 341 'properties': expected_properties, |
| 340 # Intentionally hard code the hash value since it has to be deterministic. | 342 # Intentionally hard code the hash value since it has to be deterministic. |
| 341 # Other unit tests should use the calculated value. | 343 # Other unit tests should use the calculated value. |
| 342 'properties_hash': '2202337f592f7e31b407e38832c35e23f306c6c8', | 344 'properties_hash': 'c6e0db8e858dd5b1bdae0e8eae7486f4a8a82967', |
| 343 'pubsub_topic': None, | 345 'pubsub_topic': None, |
| 344 'pubsub_userdata': None, | 346 'pubsub_userdata': None, |
| 345 'service_account': u'none', | 347 'service_account': u'none', |
| 346 'tags': [ | 348 'tags': [ |
| 347 u'OS:Windows-3.1.1', | 349 u'OS:Windows-3.1.1', |
| 348 u'hostname:localhost', | 350 u'hostname:localhost', |
| 349 u'pool:default', | 351 u'pool:default', |
| 350 u'priority:49', | 352 u'priority:49', |
| 351 u'service_account:none', | 353 u'service_account:none', |
| 352 u'tag:1', | 354 u'tag:1', |
| (...skipping 21 matching lines...) Expand all Loading... |
| 374 _gen_request(parent_task_id='1d69b9f088008810') | 376 _gen_request(parent_task_id='1d69b9f088008810') |
| 375 | 377 |
| 376 def test_init_new_request_idempotent(self): | 378 def test_init_new_request_idempotent(self): |
| 377 request = mkreq(_gen_request(properties=dict(idempotent=True))) | 379 request = mkreq(_gen_request(properties=dict(idempotent=True))) |
| 378 as_dict = request.to_dict() | 380 as_dict = request.to_dict() |
| 379 self.assertEqual(True, as_dict['properties']['idempotent']) | 381 self.assertEqual(True, as_dict['properties']['idempotent']) |
| 380 # Intentionally hard code the hash value since it has to be deterministic. | 382 # Intentionally hard code the hash value since it has to be deterministic. |
| 381 # Other unit tests should use the calculated value. | 383 # Other unit tests should use the calculated value. |
| 382 # Ensure the algorithm is deterministic. | 384 # Ensure the algorithm is deterministic. |
| 383 self.assertEqual( | 385 self.assertEqual( |
| 384 '2202337f592f7e31b407e38832c35e23f306c6c8', as_dict['properties_hash']) | 386 'c6e0db8e858dd5b1bdae0e8eae7486f4a8a82967', as_dict['properties_hash']) |
| 385 | 387 |
| 386 def test_init_new_request_bot_service_account(self): | 388 def test_init_new_request_bot_service_account(self): |
| 387 request = mkreq(_gen_request(service_account_token='bot')) | 389 request = mkreq(_gen_request(service_account_token='bot')) |
| 388 as_dict = request.to_dict() | 390 as_dict = request.to_dict() |
| 389 self.assertEqual('bot', as_dict['service_account']) | 391 self.assertEqual('bot', as_dict['service_account']) |
| 390 self.assertIn(u'service_account:bot', as_dict['tags']) | 392 self.assertIn(u'service_account:bot', as_dict['tags']) |
| 391 | 393 |
| 392 def test_duped(self): | 394 def test_duped(self): |
| 393 # Two TestRequest with the same properties. | 395 # Two TestRequest with the same properties. |
| 394 request_1 = mkreq(_gen_request(properties=dict(idempotent=True))) | 396 request_1 = mkreq(_gen_request(properties=dict(idempotent=True))) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 'execution_timeout_secs': 30, | 644 'execution_timeout_secs': 30, |
| 643 'extra_args': [], | 645 'extra_args': [], |
| 644 'grace_period_secs': 30, | 646 'grace_period_secs': 30, |
| 645 'idempotent': False, | 647 'idempotent': False, |
| 646 'inputs_ref': { | 648 'inputs_ref': { |
| 647 'isolated': None, | 649 'isolated': None, |
| 648 'isolatedserver': 'https://isolateserver.appspot.com', | 650 'isolatedserver': 'https://isolateserver.appspot.com', |
| 649 'namespace': 'default-gzip', | 651 'namespace': 'default-gzip', |
| 650 }, | 652 }, |
| 651 'io_timeout_secs': None, | 653 'io_timeout_secs': None, |
| 654 'outputs': [], |
| 652 } | 655 } |
| 653 # Differences from new_request() are: | 656 # Differences from new_request() are: |
| 654 # - parent_task_id was reset to None. | 657 # - parent_task_id was reset to None. |
| 655 # - tag 'user:' was replaced | 658 # - tag 'user:' was replaced |
| 656 # - user was replaced. | 659 # - user was replaced. |
| 657 expected_request = { | 660 expected_request = { |
| 658 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 661 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 659 'name': u'Request name (Retry #1)', | 662 'name': u'Request name (Retry #1)', |
| 660 'parent_task_id': None, | 663 'parent_task_id': None, |
| 661 'priority': 49, | 664 'priority': 49, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), | 721 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), |
| 719 task_request.request_id_to_key(0xeb5313d0300000)) | 722 task_request.request_id_to_key(0xeb5313d0300000)) |
| 720 | 723 |
| 721 | 724 |
| 722 if __name__ == '__main__': | 725 if __name__ == '__main__': |
| 723 if '-v' in sys.argv: | 726 if '-v' in sys.argv: |
| 724 unittest.TestCase.maxDiff = None | 727 unittest.TestCase.maxDiff = None |
| 725 logging.basicConfig( | 728 logging.basicConfig( |
| 726 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 729 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
| 727 unittest.main() | 730 unittest.main() |
| OLD | NEW |