Index: chrome/common/extensions/docs/server2/template_data_source_test.py |
diff --git a/chrome/common/extensions/docs/server2/template_data_source_test.py b/chrome/common/extensions/docs/server2/template_data_source_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..80e64d6e676c6ad1b7ad9b07aa3d290667de977c |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/template_data_source_test.py |
@@ -0,0 +1,52 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import json |
+import os |
+import unittest |
+import test_urlfetch |
+ |
+from local_fetcher import LocalFetcher |
+from template_data_source import TemplateDataSource |
+from third_party.handlebar import Handlebar |
+ |
+def _ReadFile(filename): |
+ with open(filename, 'r') as f: |
+ return f.read() |
+ |
+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.
|
+ def FetchResource(self, path): |
+ result = self._Resource() |
+ result.content = _ReadFile(os.path.join(self._base_path, path)) |
+ return result |
+ |
+class TemplateDataSourceTest(unittest.TestCase): |
+ def testSimple(self): |
+ path = os.path.join('test_data', 'template_data_source', 'simple') |
+ fetcher = TestFetcher(path) |
+ t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
+ |
+ template_a1 = Handlebar(_ReadFile(os.path.join(path, 'test1.html'))) |
+ self.assertEqual(template_a1.render({}, {'templates': {}}).text, |
+ t_data_source['test1'].render({}, {'templates': {}}).text) |
+ |
+ template_a2 = Handlebar(_ReadFile(os.path.join(path, 'test2.html'))) |
+ self.assertEqual(template_a2.render({}, {'templates': {}}).text, |
+ t_data_source['test2'].render({}, {'templates': {}}).text) |
+ |
+ self.assertEqual(None, t_data_source['junk.html']) |
+ |
+ def testPartials(self): |
+ path = os.path.join('test_data', 'template_data_source', 'partials') |
+ fetcher = TestFetcher(path) |
+ t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
+ |
+ self.assertEqual(_ReadFile(os.path.join(path, 'test.html')), |
+ t_data_source['test_tmpl'].render( |
+ json.loads(_ReadFile(os.path.join(path, 'input.json'))), |
+ t_data_source).text) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |