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

Side by Side Diff: appengine/findit/handlers/test/config_test.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: Rebase Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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
11 from handlers import config 11 from handlers import config
12 from model import wf_config 12 from model import wf_config
13 from testing_utils import testing 13 from testing_utils import testing
14 14 from google.appengine.api import users
15 15
16 _MOCK_STEPS_FOR_MASTERS_RULES_OLD_FORMAT = { 16 _MOCK_STEPS_FOR_MASTERS_RULES_OLD_FORMAT = {
17 'master1': ['unsupported_step1', 'unsupported_step2'], 17 'master1': ['unsupported_step1', 'unsupported_step2'],
18 'master2': ['unsupported_step3', 'unsupported_step4'], 18 'master2': ['unsupported_step3', 'unsupported_step4'],
19 } 19 }
20 20
21 _MOCK_STEPS_FOR_MASTERS_RULES = { 21 _MOCK_STEPS_FOR_MASTERS_RULES = {
22 'supported_masters': { 22 'supported_masters': {
23 'master1': { 23 'master1': {
24 # supported_steps override global. 24 # supported_steps override global.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 _MOCK_VERSION_NUMBER = 12 71 _MOCK_VERSION_NUMBER = 12
72 72
73 73
74 class ConfigTest(testing.AppengineTestCase): 74 class ConfigTest(testing.AppengineTestCase):
75 app_module = webapp2.WSGIApplication([ 75 app_module = webapp2.WSGIApplication([
76 ('/config', config.Configuration), 76 ('/config', config.Configuration),
77 ], debug=True) 77 ], debug=True)
78 78
79 def testGetConfigurationSettings(self): 79 def testGetConfigurationSettings(self):
80 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
81
82 config_data = { 80 config_data = {
83 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, 81 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES,
84 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, 82 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS,
85 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 83 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
86 'swarming_settings': _MOCK_SWARMING_SETTINGS 84 'swarming_settings': _MOCK_SWARMING_SETTINGS
87 } 85 }
88 wf_config.FinditConfig.Get().Update(**config_data) 86
87 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
88
89 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True,
90 **config_data)
89 91
90 response = self.test_app.get('/config', params={'format': 'json'}) 92 response = self.test_app.get('/config', params={'format': 'json'})
91 self.assertEquals(response.status_int, 200) 93 self.assertEquals(response.status_int, 200)
92 94
93 expected_response = { 95 expected_response = {
94 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, 96 'masters': _MOCK_STEPS_FOR_MASTERS_RULES,
95 'builders': _MOCK_BUILDERS_TO_TRYBOTS, 97 'builders': _MOCK_BUILDERS_TO_TRYBOTS,
96 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 98 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
97 'swarming_settings': _MOCK_SWARMING_SETTINGS, 99 'swarming_settings': _MOCK_SWARMING_SETTINGS,
98 'version': 1, 100 'version': 1,
99 'latest_version': 1, 101 'latest_version': 1,
100 'updated_by': 'test', 102 'updated_by': 'test',
101 'updated_ts': response.json_body.get('updated_ts') 103 'updated_ts': response.json_body.get('updated_ts')
102 } 104 }
103 105
104 self.assertEquals(expected_response, response.json_body) 106 self.assertEquals(expected_response, response.json_body)
105 107
106 def testGetVersionOfConfigurationSettings(self): 108 def testGetVersionOfConfigurationSettings(self):
107 self.mock_current_user(user_email='test@chromium.org', is_admin=True) 109 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
108 110
109 config_data = { 111 config_data = {
110 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, 112 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES,
111 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, 113 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS,
112 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 114 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
113 'swarming_settings': _MOCK_SWARMING_SETTINGS 115 'swarming_settings': _MOCK_SWARMING_SETTINGS
114 } 116 }
115 wf_config.FinditConfig.Get().Update(**config_data) 117 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True,
118 **config_data)
116 119
117 response = self.test_app.get( 120 response = self.test_app.get(
118 '/config', params={'version': 1, 'format': 'json'}) 121 '/config', params={'version': 1, 'format': 'json'})
119 self.assertEquals(response.status_int, 200) 122 self.assertEquals(response.status_int, 200)
120 123
121 expected_response = { 124 expected_response = {
122 'masters': _MOCK_STEPS_FOR_MASTERS_RULES, 125 'masters': _MOCK_STEPS_FOR_MASTERS_RULES,
123 'builders': _MOCK_BUILDERS_TO_TRYBOTS, 126 'builders': _MOCK_BUILDERS_TO_TRYBOTS,
124 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 127 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
125 'swarming_settings': _MOCK_SWARMING_SETTINGS, 128 'swarming_settings': _MOCK_SWARMING_SETTINGS,
126 'version': 1, 129 'version': 1,
127 'latest_version': 1, 130 'latest_version': 1,
128 'updated_by': 'test', 131 'updated_by': 'test',
129 'updated_ts': response.json_body.get('updated_ts') 132 'updated_ts': response.json_body.get('updated_ts')
130 } 133 }
131 134
132 self.assertEquals(expected_response, response.json_body) 135 self.assertEquals(expected_response, response.json_body)
133 136
134 def testGetOutOfBoundsVersionOfConfigurationSettings(self): 137 def testGetOutOfBoundsVersionOfConfigurationSettings(self):
135 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
136
137 config_data = { 138 config_data = {
138 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES, 139 'steps_for_masters_rules': _MOCK_STEPS_FOR_MASTERS_RULES,
139 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, 140 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS,
140 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 141 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
141 'swarming_settings': _MOCK_SWARMING_SETTINGS 142 'swarming_settings': _MOCK_SWARMING_SETTINGS
142 } 143 }
143 wf_config.FinditConfig.Get().Update(**config_data) 144 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
145
146 wf_config.FinditConfig.Get().Update(users.GetCurrentUser(), True,
147 **config_data)
144 148
145 self.assertRaisesRegexp( 149 self.assertRaisesRegexp(
146 webtest.app.AppError, 150 webtest.app.AppError,
147 re.compile('The requested version is invalid or not found.', 151 re.compile('The requested version is invalid or not found.',
148 re.MULTILINE | re.DOTALL), 152 re.MULTILINE | re.DOTALL),
149 self.test_app.get, '/config', params={'version': 0, 'format': 'json'}) 153 self.test_app.get, '/config', params={'version': 0, 'format': 'json'})
150 self.assertRaisesRegexp( 154 self.assertRaisesRegexp(
151 webtest.app.AppError, 155 webtest.app.AppError,
152 re.compile('The requested version is invalid or not found.', 156 re.compile('The requested version is invalid or not found.',
153 re.MULTILINE | re.DOTALL), 157 re.MULTILINE | re.DOTALL),
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 'builders': _MOCK_BUILDERS_TO_TRYBOTS, 617 'builders': _MOCK_BUILDERS_TO_TRYBOTS,
614 'try_job_settings': _MOCK_TRY_JOB_SETTINGS, 618 'try_job_settings': _MOCK_TRY_JOB_SETTINGS,
615 'swarming_settings': _MOCK_SWARMING_SETTINGS, 619 'swarming_settings': _MOCK_SWARMING_SETTINGS,
616 'version': 1, 620 'version': 1,
617 'latest_version': 1, 621 'latest_version': 1,
618 'updated_by': 'test', 622 'updated_by': 'test',
619 'updated_ts': response.json_body.get('updated_ts') 623 'updated_ts': response.json_body.get('updated_ts')
620 } 624 }
621 625
622 self.assertEquals(expected_response, response.json_body) 626 self.assertEquals(expected_response, response.json_body)
OLDNEW
« no previous file with comments | « appengine/findit/handlers/test/build_failure_test.py ('k') | appengine/findit/handlers/test/handlers_util_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698