OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 from testing_utils import testing | |
6 | |
7 from model.wf_config import FinditConfig | |
8 | |
9 | |
10 _DEFAULT_STEPS_FOR_MASTERS_RULES = { | |
11 'supported_masters': { | |
12 'm': { | |
13 'check_global': True | |
14 }, | |
15 'm3': { | |
16 'check_global': True | |
17 }, | |
18 'master1': { | |
19 # supported_steps override global. | |
20 'supported_steps': ['unsupported_step6'], | |
21 'unsupported_steps': ['unsupported_step1', | |
22 'unsupported_step2', | |
23 'unsupported_step3'], | |
24 'check_global': True | |
25 }, | |
26 'master2': { | |
27 # Only supports step4 and step5 regardless of global. | |
28 'supported_steps': ['step4', 'step5'], | |
29 'check_global': False | |
30 }, | |
31 'master3': { | |
32 # Supports everything not blacklisted in global. | |
33 'check_global': True | |
34 }, | |
35 }, | |
36 'global': { | |
37 # Blacklists all listed steps for all masters unless overridden. | |
38 'unsupported_steps': ['unsupported_step6', 'unsupported_step7'], | |
39 } | |
40 } | |
41 | |
42 | |
43 _DEFAULT_TRY_BOT_MAPPING = { | |
44 'master1': { | |
45 'builder1': { | |
46 'mastername': 'tryserver1', | |
47 'buildername': 'trybot1', | |
48 'strict_regex': True, | |
49 } | |
50 }, | |
51 'm': { | |
52 'b': { | |
53 'mastername': 'tryserver.master', | |
54 'buildername': 'tryserver.builder', | |
55 } | |
56 } | |
57 } | |
58 | |
59 | |
60 _DEFAULT_TRY_JOB_SETTINGS = { | |
61 'server_query_interval_seconds': 60, | |
62 'job_timeout_hours': 5, | |
63 'allowed_response_error_times': 5 | |
64 } | |
65 | |
66 | |
67 _DEFAULT_SWARMING_SETTINGS = { | |
68 'server_host': 'chromium-swarm.appspot.com', | |
69 'default_request_priority': 150, | |
70 'request_expiration_hours': 20, | |
71 'server_query_interval_seconds': 60, | |
72 'task_timeout_hours': 23, | |
73 'isolated_server': 'https://isolateserver.appspot.com', | |
74 'isolated_storage_url': 'isolateserver.storage.googleapis.com', | |
75 'iterations_to_rerun': 10 | |
76 } | |
77 | |
78 | |
79 DEFAULT_UNIT_TEST_CONFIG_DATA = { | |
80 'steps_for_masters_rules': _DEFAULT_STEPS_FOR_MASTERS_RULES, | |
81 'builders_to_trybots': _DEFAULT_TRY_BOT_MAPPING, | |
82 'try_job_settings': _DEFAULT_TRY_JOB_SETTINGS, | |
83 'swarming_settings': _DEFAULT_SWARMING_SETTINGS | |
84 } | |
85 | |
86 | |
87 def MockConfigSettings(config_data=None): # pragma: no cover. | |
88 """Sets up Findit's config for unit tests. | |
89 | |
90 Args: | |
91 config_data: a dict containing the config Findit should use for unit tests. | |
92 If None, then a default config is used. | |
93 """ | |
94 | |
95 if config_data is None: | |
96 FinditConfig.Get().Update(**DEFAULT_UNIT_TEST_CONFIG_DATA) | |
97 else: | |
98 FinditConfig.Get().Update(**config_data) | |
99 | |
100 | |
101 class WaterfallTestCase(testing.AppengineTestCase): # pragma: no cover. | |
stgao
2016/04/01 18:51:46
After the class rename, should we rename the file
lijeffrey
2016/04/01 23:06:46
Done.
| |
102 | |
103 def setUp(self): | |
104 super(WaterfallTestCase, self).setUp() | |
105 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | |
106 MockConfigSettings() | |
107 self.mock_current_user() | |
108 | |
109 def UpdateConfigSetting(self, property_name, setting_name, new_value): | |
stgao
2016/04/01 18:51:46
What if the test has to update multiple values? Do
lijeffrey
2016/04/01 23:06:46
I made it so it's possible to update the entire 's
| |
110 """Updates a single setting under a configurable property for testing. | |
111 | |
112 This method should only be used for updating config settings for a | |
113 single-layer dict such as that used in try_job_settings or | |
114 swarming_settings. | |
115 | |
116 Args: | |
117 property_name: The name of the property to update. | |
118 setting_name: The setting under the property to update. | |
119 new_value: The value to be assigned to the setting. | |
120 """ | |
121 if property_name not in ['try_job_settings', 'swarming_settings']: | |
122 return | |
123 | |
124 DEFAULT_UNIT_TEST_CONFIG_DATA[property_name][setting_name] = new_value | |
stgao
2016/04/01 18:51:46
Is there possible be side effect for this change?
lijeffrey
2016/04/01 23:06:46
Done.
stgao
2016/04/01 23:35:48
Seems the bug is not fixed in the new patch.
| |
125 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | |
126 MockConfigSettings(DEFAULT_UNIT_TEST_CONFIG_DATA) | |
127 self.mock_current_user() | |
stgao
2016/04/01 18:51:46
Is it possible to avoid this mock and unmock?
lijeffrey
2016/04/01 23:06:46
Done.
| |
OLD | NEW |