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 json | 5 import json |
6 | 6 |
7 import webapp2 | 7 import webapp2 |
8 | 8 |
9 from handlers import config | 9 from handlers import config |
10 from model import wf_config | 10 from model import wf_config |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 _MOCK_VERSION_NUMBER = 12 | 28 _MOCK_VERSION_NUMBER = 12 |
29 | 29 |
30 | 30 |
31 class ConfigTest(testing.AppengineTestCase): | 31 class ConfigTest(testing.AppengineTestCase): |
32 app_module = webapp2.WSGIApplication([ | 32 app_module = webapp2.WSGIApplication([ |
33 ('/config', config.Configuration), | 33 ('/config', config.Configuration), |
34 ], debug=True) | 34 ], debug=True) |
35 | 35 |
36 def testGetConfigurationSettings(self): | 36 def testGetConfigurationSettings(self): |
37 class MockFinditConfig(): | 37 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
38 masters_to_blacklisted_steps = _MOCK_MASTERS_TO_BLACKLISTED_STEPS | |
39 builders_to_trybots = _MOCK_BUILDERS_TO_TRYBOTS | |
40 | 38 |
41 @property | 39 config_data = { |
42 def VersionNumber(self): | 40 'masters_to_blacklisted_steps': _MOCK_MASTERS_TO_BLACKLISTED_STEPS, |
43 return _MOCK_VERSION_NUMBER | 41 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, |
44 | 42 } |
45 def MockSettings(): | 43 wf_config.FinditConfig.Get().Update(**config_data) |
46 return MockFinditConfig() | |
47 | |
48 self.mock(wf_config, 'Settings', MockSettings) | |
49 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | |
50 | 44 |
51 response = self.test_app.get('/config', params={'format': 'json'}) | 45 response = self.test_app.get('/config', params={'format': 'json'}) |
52 self.assertEquals(response.status_int, 200) | 46 self.assertEquals(response.status_int, 200) |
53 | 47 |
54 expected_response = { | 48 expected_response = { |
55 'masters': _MOCK_MASTERS_TO_BLACKLISTED_STEPS, | 49 'masters': _MOCK_MASTERS_TO_BLACKLISTED_STEPS, |
56 'builders': _MOCK_BUILDERS_TO_TRYBOTS, | 50 'builders': _MOCK_BUILDERS_TO_TRYBOTS, |
57 'version': _MOCK_VERSION_NUMBER, | 51 'version': 1, |
58 } | 52 } |
59 | 53 |
60 self.assertEquals(expected_response, response.json_body) | 54 self.assertEquals(expected_response, response.json_body) |
61 | 55 |
62 def testValidateMastersDict(self): | 56 def testValidateMastersDict(self): |
63 self.assertTrue(config._SupportedMastersConfigIsValid({ | 57 self.assertTrue(config._SupportedMastersConfigIsValid({ |
64 'a': ['string1', 'string2', 'string3'], | 58 'a': ['string1', 'string2', 'string3'], |
65 'b': ['string1', 'string2', 'string3'], | 59 'b': ['string1', 'string2', 'string3'], |
66 })) | 60 })) |
67 self.assertFalse(config._SupportedMastersConfigIsValid({ | 61 self.assertFalse(config._SupportedMastersConfigIsValid({ |
(...skipping 26 matching lines...) Expand all Loading... |
94 'masters_to_blacklisted_steps': { | 88 'masters_to_blacklisted_steps': { |
95 'a': [] | 89 'a': [] |
96 } | 90 } |
97 })) | 91 })) |
98 self.assertFalse(config._ConfigurationDictIsValid([])) | 92 self.assertFalse(config._ConfigurationDictIsValid([])) |
99 self.assertFalse(config._ConfigurationDictIsValid({ | 93 self.assertFalse(config._ConfigurationDictIsValid({ |
100 'this_is_not_a_valid_property': [] | 94 'this_is_not_a_valid_property': [] |
101 })) | 95 })) |
102 | 96 |
103 def testPostConfigurationSettings(self): | 97 def testPostConfigurationSettings(self): |
104 | |
105 class MockFinditConfig(): | |
106 masters_to_blacklisted_steps = { | |
107 'a': [], | |
108 } | |
109 builders_to_trybots = {} | |
110 | |
111 def modify(self, **kwargs): | |
112 for k, v in kwargs.iteritems(): | |
113 setattr(self, k, v) | |
114 | |
115 @property | |
116 def VersionNumber(self): | |
117 return _MOCK_VERSION_NUMBER | |
118 | |
119 mock_config = MockFinditConfig() | |
120 | |
121 def MockSettings(): | |
122 return mock_config | |
123 | |
124 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 98 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
125 self.mock(wf_config, 'FinditConfig', MockFinditConfig) | |
126 self.mock(wf_config, 'Settings', MockSettings) | |
127 | 99 |
128 params = { | 100 params = { |
129 'format': 'json', | 101 'format': 'json', |
130 'data': json.dumps({ | 102 'data': json.dumps({ |
131 'masters_to_blacklisted_steps': { | 103 'masters_to_blacklisted_steps': { |
132 'a': ['1', '2', '3'], | 104 'a': ['1', '2', '3'], |
133 'b': [] | 105 'b': [], |
134 }, | 106 }, |
135 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, | 107 'builders_to_trybots': _MOCK_BUILDERS_TO_TRYBOTS, |
136 }) | 108 }) |
137 } | 109 } |
138 | 110 |
139 expected_response = { | 111 expected_response = { |
140 'masters': { | 112 'masters': { |
141 'a': ['1', '2', '3'], | 113 'a': ['1', '2', '3'], |
142 'b': [] | 114 'b': [] |
143 }, | 115 }, |
144 'builders': _MOCK_BUILDERS_TO_TRYBOTS, | 116 'builders': _MOCK_BUILDERS_TO_TRYBOTS, |
145 'version': _MOCK_VERSION_NUMBER, | 117 'version': 1, |
146 } | 118 } |
147 | 119 |
148 response = self.test_app.post('/config', params=params) | 120 response = self.test_app.post('/config', params=params) |
149 self.assertEquals(expected_response, response.json_body) | 121 self.assertEquals(expected_response, response.json_body) |
OLD | NEW |