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 server_instance import ServerInstance
12 from template_data_source import TemplateDataSource
13 from test_util import DisableLogging, ReadFile
14 from third_party.handlebar import Handlebar
17 class TemplateDataSourceTest(unittest.TestCase):
20 self._base_path = os.path.join(sys.path[0],
22 'template_data_source')
24 def _CreateTemplateDataSource(self, partial_dir):
25 return TemplateDataSource(
26 ServerInstance.ForLocal(),
28 partial_dir='docs/server2/test_data/template_data_source/%s' %
32 template_data_source = self._CreateTemplateDataSource('simple')
33 template_a1 = Handlebar(ReadFile(self._base_path, 'simple', 'test1.html'))
34 context = [{}, {'templates': {}}]
36 template_a1.Render(*context).text,
37 template_data_source.get('test1').Render(*context).text)
38 template_a2 = Handlebar(ReadFile(self._base_path, 'simple', 'test2.html'))
40 template_a2.Render(*context).text,
41 template_data_source.get('test2').Render(*context).text)
43 @DisableLogging('warning')
44 def testNotFound(self):
45 template_data_source = self._CreateTemplateDataSource('simple')
46 self.assertEqual(None, template_data_source.get('junk'))
48 @DisableLogging('warning')
49 def testPartials(self):
50 template_data_source = self._CreateTemplateDataSource('partials')
51 context = json.loads(ReadFile(self._base_path, 'partials', 'input.json'))
53 ReadFile(self._base_path, 'partials', 'test_expected.html'),
54 template_data_source.get('test_tmpl').Render(
55 context, template_data_source).text)
58 if __name__ == '__main__':