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
4 # found in the LICENSE file.
11 from extensions_paths import SERVER2
12 from server_instance import ServerInstance
13 from template_data_source import TemplateDataSource
14 from test_util import DisableLogging, ReadFile, Server2Path
15 from third_party.handlebar import Handlebar
18 class TemplateDataSourceTest(unittest.TestCase):
20 def _ReadFile(self, *path):
21 return ReadFile(SERVER2, 'test_data', 'template_data_source', *path)
23 def _CreateTemplateDataSource(self, partial_dir):
24 return TemplateDataSource(
25 ServerInstance.ForLocal(),
27 partial_dir='%stest_data/template_data_source/%s/' %
28 (SERVER2, partial_dir))
31 template_data_source = self._CreateTemplateDataSource('simple')
32 template_a1 = Handlebar(self._ReadFile('simple', 'test1.html'))
33 context = [{}, {'templates': {}}]
35 template_a1.Render(*context).text,
36 template_data_source.get('test1').Render(*context).text)
37 template_a2 = Handlebar(self._ReadFile('simple', 'test2.html'))
39 template_a2.Render(*context).text,
40 template_data_source.get('test2').Render(*context).text)
42 @DisableLogging('warning')
43 def testNotFound(self):
44 template_data_source = self._CreateTemplateDataSource('simple')
45 self.assertEqual(None, template_data_source.get('junk'))
47 @DisableLogging('warning')
48 def testPartials(self):
49 template_data_source = self._CreateTemplateDataSource('partials')
50 context = json.loads(self._ReadFile('partials', 'input.json'))
52 self._ReadFile('partials', 'test_expected.html'),
53 template_data_source.get('test_tmpl').Render(
54 context, template_data_source).text)
57 if __name__ == '__main__':