Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2885)

Unified Diff: appengine/findit/waterfall/test/wf_configured_test_case.py

Issue 1836293002: [Findit] Adding central config test class for unit tests (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressing comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/waterfall/test/waterfall_config_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/waterfall/test/wf_configured_test_case.py
diff --git a/appengine/findit/waterfall/test/wf_configured_test_case.py b/appengine/findit/waterfall/test/wf_configured_test_case.py
new file mode 100644
index 0000000000000000000000000000000000000000..eafeeb9495ef4908a242d946cecb7b1a1ede2ce0
--- /dev/null
+++ b/appengine/findit/waterfall/test/wf_configured_test_case.py
@@ -0,0 +1,127 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from testing_utils import testing
+
+from model.wf_config import FinditConfig
+
+
+_DEFAULT_STEPS_FOR_MASTERS_RULES = {
+ 'supported_masters': {
+ 'm': {
+ 'check_global': True
+ },
+ 'm3': {
+ 'check_global': True
+ },
+ 'master1': {
+ # supported_steps override global.
+ 'supported_steps': ['unsupported_step6'],
+ 'unsupported_steps': ['unsupported_step1',
+ 'unsupported_step2',
+ 'unsupported_step3'],
+ 'check_global': True
+ },
+ 'master2': {
+ # Only supports step4 and step5 regardless of global.
+ 'supported_steps': ['step4', 'step5'],
+ 'check_global': False
+ },
+ 'master3': {
+ # Supports everything not blacklisted in global.
+ 'check_global': True
+ },
+ },
+ 'global': {
+ # Blacklists all listed steps for all masters unless overridden.
+ 'unsupported_steps': ['unsupported_step6', 'unsupported_step7'],
+ }
+}
+
+
+_DEFAULT_TRY_BOT_MAPPING = {
+ 'master1': {
+ 'builder1': {
+ 'mastername': 'tryserver1',
+ 'buildername': 'trybot1',
+ 'strict_regex': True,
+ }
+ },
+ 'm': {
+ 'b': {
+ 'mastername': 'tryserver.master',
+ 'buildername': 'tryserver.builder',
+ }
+ }
+}
+
+
+_DEFAULT_TRY_JOB_SETTINGS = {
+ 'server_query_interval_seconds': 60,
+ 'job_timeout_hours': 5,
+ 'allowed_response_error_times': 5
+}
+
+
+_DEFAULT_SWARMING_SETTINGS = {
+ 'server_host': 'chromium-swarm.appspot.com',
+ 'default_request_priority': 150,
+ 'request_expiration_hours': 20,
+ 'server_query_interval_seconds': 60,
+ 'task_timeout_hours': 23,
+ 'isolated_server': 'https://isolateserver.appspot.com',
+ 'isolated_storage_url': 'isolateserver.storage.googleapis.com',
+ 'iterations_to_rerun': 10
+}
+
+
+DEFAULT_UNIT_TEST_CONFIG_DATA = {
+ 'steps_for_masters_rules': _DEFAULT_STEPS_FOR_MASTERS_RULES,
+ 'builders_to_trybots': _DEFAULT_TRY_BOT_MAPPING,
+ 'try_job_settings': _DEFAULT_TRY_JOB_SETTINGS,
+ 'swarming_settings': _DEFAULT_SWARMING_SETTINGS
+}
+
+
+def MockConfigSettings(config_data=None): # pragma: no cover.
+ """Sets up Findit's config for unit tests.
+
+ Args:
+ config_data: a dict containing the config Findit should use for unit tests.
+ If None, then a default config is used.
+ """
+
+ if config_data is None:
+ FinditConfig.Get().Update(**DEFAULT_UNIT_TEST_CONFIG_DATA)
+ else:
+ FinditConfig.Get().Update(**config_data)
+
+
+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.
+
+ def setUp(self):
+ super(WaterfallTestCase, self).setUp()
+ self.mock_current_user(user_email='test@chromium.org', is_admin=True)
+ MockConfigSettings()
+ self.mock_current_user()
+
+ 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
+ """Updates a single setting under a configurable property for testing.
+
+ This method should only be used for updating config settings for a
+ single-layer dict such as that used in try_job_settings or
+ swarming_settings.
+
+ Args:
+ property_name: The name of the property to update.
+ setting_name: The setting under the property to update.
+ new_value: The value to be assigned to the setting.
+ """
+ if property_name not in ['try_job_settings', 'swarming_settings']:
+ return
+
+ 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.
+ self.mock_current_user(user_email='test@chromium.org', is_admin=True)
+ MockConfigSettings(DEFAULT_UNIT_TEST_CONFIG_DATA)
+ 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.
« no previous file with comments | « appengine/findit/waterfall/test/waterfall_config_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698