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

Unified 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 side-by-side diff with in-line comments
Download patch
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()

Powered by Google App Engine
This is Rietveld 408576698