| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 datetime | 5 import datetime |
| 6 import json | 6 import json |
| 7 import re | 7 import re |
| 8 import webapp2 | 8 import webapp2 |
| 9 import webtest | 9 import webtest |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 'server_host': 'chromium-swarm.appspot.com', | 61 'server_host': 'chromium-swarm.appspot.com', |
| 62 'default_request_priority': 150, | 62 'default_request_priority': 150, |
| 63 'request_expiration_hours': 20, | 63 'request_expiration_hours': 20, |
| 64 'server_query_interval_seconds': 60, | 64 'server_query_interval_seconds': 60, |
| 65 'task_timeout_hours': 23, | 65 'task_timeout_hours': 23, |
| 66 'isolated_server': 'https://isolateserver.appspot.com', | 66 'isolated_server': 'https://isolateserver.appspot.com', |
| 67 'isolated_storage_url': 'isolateserver.storage.googleapis.com', | 67 'isolated_storage_url': 'isolateserver.storage.googleapis.com', |
| 68 'iterations_to_rerun': 10 | 68 'iterations_to_rerun': 10 |
| 69 } | 69 } |
| 70 | 70 |
| 71 |
| 72 _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS = { |
| 73 'download_interval_seconds': 10, |
| 74 'memcache_master_download_expiration_seconds': 3600, |
| 75 'use_chrome_build_extract': True |
| 76 } |
| 77 |
| 71 _MOCK_VERSION_NUMBER = 12 | 78 _MOCK_VERSION_NUMBER = 12 |
| 72 | 79 |
| 73 | 80 |
| 74 class ConfigTest(testing.AppengineTestCase): | 81 class ConfigTest(testing.AppengineTestCase): |
| 75 app_module = webapp2.WSGIApplication([ | 82 app_module = webapp2.WSGIApplication([ |
| 76 ('/config', config.Configuration), | 83 ('/config', config.Configuration), |
| 77 ], debug=True) | 84 ], debug=True) |
| 78 | 85 |
| 79 def testGetConfigurationSettings(self): | 86 def testGetConfigurationSettings(self): |
| 80 config_data = { | 87 config_data = { |
| 81 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, | 88 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, |
| 82 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, | 89 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, |
| 83 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 90 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 84 'swarming_settings': _MOCK_SWARMING_SETTINGS | 91 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 92 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS |
| 85 } | 93 } |
| 86 | 94 |
| 87 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 95 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 88 | 96 |
| 89 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True, | 97 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True, |
| 90 **config_data) | 98 **config_data) |
| 91 | 99 |
| 92 response = self.test_app.get('/config', params={'format': 'json'}) | 100 response = self.test_app.get('/config', params={'format': 'json'}) |
| 93 self.assertEquals(response.status_int, 200) | 101 self.assertEquals(response.status_int, 200) |
| 94 | 102 |
| 95 expected_response = { | 103 expected_response = { |
| 96 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, | 104 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, |
| 97 'builders': _MOCK_BUILDERS_TO_TRYBOTS, | 105 'builders': _MOCK_BUILDERS_TO_TRYBOTS, |
| 98 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 106 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 99 'swarming_settings': _MOCK_SWARMING_SETTINGS, | 107 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 108 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS, |
| 100 'version': 1, | 109 'version': 1, |
| 101 'latest_version': 1, | 110 'latest_version': 1, |
| 102 'updated_by': 'test', | 111 'updated_by': 'test', |
| 103 'updated_ts': response.json_body.get('updated_ts') | 112 'updated_ts': response.json_body.get('updated_ts') |
| 104 } | 113 } |
| 105 | 114 |
| 106 self.assertEquals(expected_response, response.json_body) | 115 self.assertEquals(expected_response, response.json_body) |
| 107 | 116 |
| 108 def testGetVersionOfConfigurationSettings(self): | 117 def testGetVersionOfConfigurationSettings(self): |
| 109 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 118 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 110 | 119 |
| 111 config_data = { | 120 config_data = { |
| 112 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, | 121 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, |
| 113 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, | 122 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, |
| 114 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 123 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 115 'swarming_settings': _MOCK_SWARMING_SETTINGS | 124 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 125 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS |
| 116 } | 126 } |
| 117 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True, | 127 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True, |
| 118 **config_data) | 128 **config_data) |
| 119 | 129 |
| 120 response = self.test_app.get( | 130 response = self.test_app.get( |
| 121 '/config', params={'version': 1, 'format': 'json'}) | 131 '/config', params={'version': 1, 'format': 'json'}) |
| 122 self.assertEquals(response.status_int, 200) | 132 self.assertEquals(response.status_int, 200) |
| 123 | 133 |
| 124 expected_response = { | 134 expected_response = { |
| 125 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, | 135 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, |
| 126 'builders': _MOCK_BUILDERS_TO_TRYBOTS, | 136 'builders': _MOCK_BUILDERS_TO_TRYBOTS, |
| 127 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 137 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 128 'swarming_settings': _MOCK_SWARMING_SETTINGS, | 138 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 139 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS, |
| 129 'version': 1, | 140 'version': 1, |
| 130 'latest_version': 1, | 141 'latest_version': 1, |
| 131 'updated_by': 'test', | 142 'updated_by': 'test', |
| 132 'updated_ts': response.json_body.get('updated_ts') | 143 'updated_ts': response.json_body.get('updated_ts') |
| 133 } | 144 } |
| 134 | 145 |
| 135 self.assertEquals(expected_response, response.json_body) | 146 self.assertEquals(expected_response, response.json_body) |
| 136 | 147 |
| 137 def testGetOutOfBoundsVersionOfConfigurationSettings(self): | 148 def testGetOutOfBoundsVersionOfConfigurationSettings(self): |
| 138 config_data = { | 149 config_data = { |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 'server_host': 'chromium-swarm.appspot.com', | 559 'server_host': 'chromium-swarm.appspot.com', |
| 549 'default_request_priority': 150, | 560 'default_request_priority': 150, |
| 550 'request_expiration_hours': 20, | 561 'request_expiration_hours': 20, |
| 551 'server_query_interval_seconds': 60, | 562 'server_query_interval_seconds': 60, |
| 552 'task_timeout_hours': 23, | 563 'task_timeout_hours': 23, |
| 553 'isolated_server': 'https://isolateserver.appspot.com', | 564 'isolated_server': 'https://isolateserver.appspot.com', |
| 554 'isolated_storage_url': 'isolateserver.storage.googleapis.com', | 565 'isolated_storage_url': 'isolateserver.storage.googleapis.com', |
| 555 'iterations_to_rerun': 10 | 566 'iterations_to_rerun': 10 |
| 556 })) | 567 })) |
| 557 | 568 |
| 569 def testValidateDownloadBuildDataSettings(self): |
| 570 self.assertFalse(config._ValidateDownloadBuildDataSettings({})) |
| 571 self.assertFalse(config._ValidateDownloadBuildDataSettings({ |
| 572 'download_interval_seconds': {}, # Should be an int. |
| 573 'memcache_master_download_expiration_seconds': 10, |
| 574 'use_chrome_build_extract': True |
| 575 })) |
| 576 self.assertFalse(config._ValidateDownloadBuildDataSettings({ |
| 577 'download_interval_seconds': 10, |
| 578 'memcache_master_download_expiration_seconds': [], # Should be an int. |
| 579 'use_chrome_build_extract': True |
| 580 })) |
| 581 self.assertFalse(config._ValidateDownloadBuildDataSettings({ |
| 582 'download_interval_seconds': 10, |
| 583 'memcache_master_download_expiration_seconds': 3600, |
| 584 'use_chrome_build_extract': 'blabla' # Should be a bool. |
| 585 })) |
| 586 self.assertTrue(config._ValidateDownloadBuildDataSettings({ |
| 587 'download_interval_seconds': 10, |
| 588 'memcache_master_download_expiration_seconds': 3600, |
| 589 'use_chrome_build_extract': False |
| 590 })) |
| 591 |
| 558 def testConfigurationDictIsValid(self): | 592 def testConfigurationDictIsValid(self): |
| 559 self.assertTrue(config._ConfigurationDictIsValid({ | 593 self.assertTrue(config._ConfigurationDictIsValid({ |
| 560 'steps_for_masters_rules': { | 594 'steps_for_masters_rules': { |
| 561 'supported_masters': { | 595 'supported_masters': { |
| 562 'master1': { | 596 'master1': { |
| 563 'unsupported_steps': ['step1', 'step2'], | 597 'unsupported_steps': ['step1', 'step2'], |
| 564 }, | 598 }, |
| 565 'master2': { | 599 'master2': { |
| 566 'supported_steps': ['step3'], | 600 'supported_steps': ['step3'], |
| 567 'check_global': False | 601 'check_global': False |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 'supported_steps': ['5'], | 635 'supported_steps': ['5'], |
| 602 'check_global': False | 636 'check_global': False |
| 603 } | 637 } |
| 604 }, | 638 }, |
| 605 'global': { | 639 'global': { |
| 606 'unsupported_steps': ['1'] | 640 'unsupported_steps': ['1'] |
| 607 } | 641 } |
| 608 }, | 642 }, |
| 609 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, | 643 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, |
| 610 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 644 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 611 'swarming_settings': _MOCK_SWARMING_SETTINGS | 645 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 646 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS |
| 612 }) | 647 }) |
| 613 } | 648 } |
| 614 | 649 |
| 615 response = self.test_app.post('/config', params=params) | 650 response = self.test_app.post('/config', params=params) |
| 616 | 651 |
| 617 expected_response = { | 652 expected_response = { |
| 618 'masters': { | 653 'masters': { |
| 619 'supported_masters': { | 654 'supported_masters': { |
| 620 'a': { | 655 'a': { |
| 621 }, | 656 }, |
| 622 'b': { | 657 'b': { |
| 623 'supported_steps': ['1'], | 658 'supported_steps': ['1'], |
| 624 'unsupported_steps': ['2', '3', '4'], | 659 'unsupported_steps': ['2', '3', '4'], |
| 625 }, | 660 }, |
| 626 'c': { | 661 'c': { |
| 627 'supported_steps': ['5'], | 662 'supported_steps': ['5'], |
| 628 'check_global': False | 663 'check_global': False |
| 629 } | 664 } |
| 630 }, | 665 }, |
| 631 'global': { | 666 'global': { |
| 632 'unsupported_steps': ['1'] | 667 'unsupported_steps': ['1'] |
| 633 } | 668 } |
| 634 }, | 669 }, |
| 635 'builders': _MOCK_BUILDERS_TO_TRYBOTS, | 670 'builders': _MOCK_BUILDERS_TO_TRYBOTS, |
| 636 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, | 671 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, |
| 637 'swarming_settings': _MOCK_SWARMING_SETTINGS, | 672 'swarming_settings': _MOCK_SWARMING_SETTINGS, |
| 673 'download_build_data_settings': _MOCK_DOWNLOAD_BUILD_DATA_SETTINGS, |
| 638 'version': 1, | 674 'version': 1, |
| 639 'latest_version': 1, | 675 'latest_version': 1, |
| 640 'updated_by': 'test', | 676 'updated_by': 'test', |
| 641 'updated_ts': response.json_body.get('updated_ts') | 677 'updated_ts': response.json_body.get('updated_ts') |
| 642 } | 678 } |
| 643 | 679 |
| 644 self.assertEquals(expected_response, response.json_body) | 680 self.assertEquals(expected_response, response.json_body) |
| OLD | NEW |