Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / template_data_source_test.py
blobfee69a9af37d312557c43223310b6d76649e0943
1 #!/usr/bin/env python
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.
6 import json
7 import os
8 import sys
9 import unittest
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
15 from third_party.handlebar import Handlebar
18 class TemplateDataSourceTest(unittest.TestCase):
20 def setUp(self):
21 self._base_path = os.path.join(sys.path[0],
22 'test_data',
23 'template_data_source')
25 def _CreateTemplateDataSource(self, partial_dir):
26 return TemplateDataSource(
27 ServerInstance.ForLocal(),
28 None, # Request
29 partial_dir='%s/test_data/template_data_source/%s' %
30 (SERVER2, partial_dir))
32 def testSimple(self):
33 template_data_source = self._CreateTemplateDataSource('simple')
34 template_a1 = Handlebar(ReadFile(self._base_path, 'simple', 'test1.html'))
35 context = [{}, {'templates': {}}]
36 self.assertEqual(
37 template_a1.Render(*context).text,
38 template_data_source.get('test1').Render(*context).text)
39 template_a2 = Handlebar(ReadFile(self._base_path, 'simple', 'test2.html'))
40 self.assertEqual(
41 template_a2.Render(*context).text,
42 template_data_source.get('test2').Render(*context).text)
44 @DisableLogging('warning')
45 def testNotFound(self):
46 template_data_source = self._CreateTemplateDataSource('simple')
47 self.assertEqual(None, template_data_source.get('junk'))
49 @DisableLogging('warning')
50 def testPartials(self):
51 template_data_source = self._CreateTemplateDataSource('partials')
52 context = json.loads(ReadFile(self._base_path, 'partials', 'input.json'))
53 self.assertEqual(
54 ReadFile(self._base_path, 'partials', 'test_expected.html'),
55 template_data_source.get('test_tmpl').Render(
56 context, template_data_source).text)
59 if __name__ == '__main__':
60 unittest.main()