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
15 from third_party
.handlebar
import Handlebar
18 class TemplateDataSourceTest(unittest
.TestCase
):
21 self
._base
_path
= os
.path
.join(sys
.path
[0],
23 'template_data_source')
25 def _CreateTemplateDataSource(self
, partial_dir
):
26 return TemplateDataSource(
27 ServerInstance
.ForLocal(),
29 partial_dir
='%s/test_data/template_data_source/%s' %
30 (SERVER2
, partial_dir
))
33 template_data_source
= self
._CreateTemplateDataSource
('simple')
34 template_a1
= Handlebar(ReadFile(self
._base
_path
, 'simple', 'test1.html'))
35 context
= [{}, {'templates': {}}]
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'))
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'))
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__':