OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from copy import deepcopy | 6 from copy import deepcopy |
7 import json | 7 import json |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 def _GetType(dict_, name): | 34 def _GetType(dict_, name): |
35 for type_ in dict_['types']: | 35 for type_ in dict_['types']: |
36 if type_['name'] == name: | 36 if type_['name'] == name: |
37 return type_ | 37 return type_ |
38 | 38 |
39 | 39 |
40 class FakeAvailabilityFinder(object): | 40 class FakeAvailabilityFinder(object): |
41 | 41 |
42 def GetApiAvailability(self, version): | 42 def GetApiAvailability(self, version): |
43 return ChannelInfo('stable', 396, 5) | 43 return ChannelInfo('stable', '396', 5) |
44 | 44 |
45 | 45 |
46 class FakeSamplesDataSource(object): | 46 class FakeSamplesDataSource(object): |
47 | 47 |
48 def Create(self, request): | 48 def Create(self, request): |
49 return {} | 49 return {} |
50 | 50 |
51 | 51 |
52 class FakeAPIAndListDataSource(object): | 52 class FakeAPIAndListDataSource(object): |
53 | 53 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 model = _JSCModel(self._LoadJSON('test_file.json')[0], | 165 model = _JSCModel(self._LoadJSON('test_file.json')[0], |
166 self._CreateRefResolver('test_file_data_source.json'), | 166 self._CreateRefResolver('test_file_data_source.json'), |
167 False, | 167 False, |
168 FakeAvailabilityFinder(), | 168 FakeAvailabilityFinder(), |
169 TestBranchUtility.CreateWithCannedData(), | 169 TestBranchUtility.CreateWithCannedData(), |
170 self._json_cache, | 170 self._json_cache, |
171 FakeTemplateDataSource(), | 171 FakeTemplateDataSource(), |
172 None) | 172 None) |
173 # The model namespace is "tester". No predetermined availability is found, | 173 # The model namespace is "tester". No predetermined availability is found, |
174 # so the FakeAvailabilityFinder instance is used to find availability. | 174 # so the FakeAvailabilityFinder instance is used to find availability. |
175 self.assertEqual(ChannelInfo('stable', 396, 5), | 175 self.assertEqual(ChannelInfo('stable', '396', 5), |
176 model._GetApiAvailability()) | 176 model._GetApiAvailability()) |
177 | 177 |
178 # These APIs have predetermined availabilities in the | 178 # These APIs have predetermined availabilities in the |
179 # api_availabilities.json file within CANNED_DATA. | 179 # api_availabilities.json file within CANNED_DATA. |
180 model._namespace.name = 'trunk_api' | 180 model._namespace.name = 'trunk_api' |
181 self.assertEqual(ChannelInfo('trunk', 'trunk', 'trunk'), | 181 self.assertEqual(ChannelInfo('trunk', 'trunk', 'trunk'), |
182 model._GetApiAvailability()) | 182 model._GetApiAvailability()) |
183 | 183 |
184 model._namespace.name = 'dev_api' | 184 model._namespace.name = 'dev_api' |
185 self.assertEqual(ChannelInfo('dev', 1500, 28), | 185 self.assertEqual(ChannelInfo('dev', '1500', 28), |
186 model._GetApiAvailability()) | 186 model._GetApiAvailability()) |
187 | 187 |
188 model._namespace.name = 'beta_api' | 188 model._namespace.name = 'beta_api' |
189 self.assertEqual(ChannelInfo('beta', 1453, 27), | 189 self.assertEqual(ChannelInfo('beta', '1453', 27), |
190 model._GetApiAvailability()) | 190 model._GetApiAvailability()) |
191 | 191 |
192 model._namespace.name = 'stable_api' | 192 model._namespace.name = 'stable_api' |
193 self.assertEqual(ChannelInfo('stable', 1132, 20), | 193 self.assertEqual(ChannelInfo('stable', '1132', 20), |
194 model._GetApiAvailability()) | 194 model._GetApiAvailability()) |
195 | 195 |
196 def testGetIntroList(self): | 196 def testGetIntroList(self): |
197 model = _JSCModel(self._LoadJSON('test_file.json')[0], | 197 model = _JSCModel(self._LoadJSON('test_file.json')[0], |
198 self._CreateRefResolver('test_file_data_source.json'), | 198 self._CreateRefResolver('test_file_data_source.json'), |
199 False, | 199 False, |
200 FakeAvailabilityFinder(), | 200 FakeAvailabilityFinder(), |
201 TestBranchUtility.CreateWithCannedData(), | 201 TestBranchUtility.CreateWithCannedData(), |
202 self._json_cache, | 202 self._json_cache, |
203 FakeTemplateDataSource(), | 203 FakeTemplateDataSource(), |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 self.assertFalse('addRulesFunction' in dict_['events'][1]) | 388 self.assertFalse('addRulesFunction' in dict_['events'][1]) |
389 # But addListener should be defined. | 389 # But addListener should be defined. |
390 self.assertEquals('tester', dict_['name']) | 390 self.assertEquals('tester', dict_['name']) |
391 self.assertEquals('noRules', dict_['events'][1]['name']) | 391 self.assertEquals('noRules', dict_['events'][1]['name']) |
392 self.assertEquals('callback', | 392 self.assertEquals('callback', |
393 dict_['events'][0]['addListenerFunction'][ | 393 dict_['events'][0]['addListenerFunction'][ |
394 'parameters'][0]['name']) | 394 'parameters'][0]['name']) |
395 | 395 |
396 if __name__ == '__main__': | 396 if __name__ == '__main__': |
397 unittest.main() | 397 unittest.main() |
OLD | NEW |