Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/common/extensions/docs/server2/template_data_source_test.py

Issue 10545043: Extensions docs server: Design changes, partial template support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
5
6 import json
7 import os
8 import unittest
9 import test_urlfetch
10
11 from local_fetcher import LocalFetcher
12 from template_data_source import TemplateDataSource
13 from third_party.handlebar import Handlebar
14
15 def _ReadFile(filename):
16 with open(filename, 'r') as f:
17 return f.read()
18
19 class TestFetcher(LocalFetcher):
not at google - send to devlin 2012/06/07 04:43:57 why do you need a TestFetcher, can you just use a
cduvall 2012/06/08 00:39:23 Done.
20 def FetchResource(self, path):
21 result = self._Resource()
22 result.content = _ReadFile(os.path.join(self._base_path, path))
23 return result
24
25 class TemplateDataSourceTest(unittest.TestCase):
26 def testSimple(self):
27 path = os.path.join('test_data', 'template_data_source', 'simple')
28 fetcher = TestFetcher(path)
29 t_data_source = TemplateDataSource(fetcher, ['./'], 0)
30
31 template_a1 = Handlebar(_ReadFile(os.path.join(path, 'test1.html')))
32 self.assertEqual(template_a1.render({}, {'templates': {}}).text,
33 t_data_source['test1'].render({}, {'templates': {}}).text)
34
35 template_a2 = Handlebar(_ReadFile(os.path.join(path, 'test2.html')))
36 self.assertEqual(template_a2.render({}, {'templates': {}}).text,
37 t_data_source['test2'].render({}, {'templates': {}}).text)
38
39 self.assertEqual(None, t_data_source['junk.html'])
40
41 def testPartials(self):
42 path = os.path.join('test_data', 'template_data_source', 'partials')
43 fetcher = TestFetcher(path)
44 t_data_source = TemplateDataSource(fetcher, ['./'], 0)
45
46 self.assertEqual(_ReadFile(os.path.join(path, 'test.html')),
47 t_data_source['test_tmpl'].render(
48 json.loads(_ReadFile(os.path.join(path, 'input.json'))),
49 t_data_source).text)
50
51 if __name__ == '__main__':
52 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698