Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/template_fetcher_test.py |
| diff --git a/chrome/common/extensions/docs/server2/template_fetcher_test.py b/chrome/common/extensions/docs/server2/template_fetcher_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..9a8fb44eb69ddd170d90b9d098e8facdf1130c56 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/template_fetcher_test.py |
| @@ -0,0 +1,50 @@ |
| +#!/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 os |
| +import unittest |
| +import test_urlfetch |
| + |
| +from local_fetcher import LocalFetcher |
| +from template_fetcher import TemplateFetcher |
| +from third_party.handlebar import Handlebar |
| + |
| +def _ReadFile(filename): |
| + with open(filename, 'r') as f: |
| + return f.read() |
| + |
| +class TestFetcher(LocalFetcher): |
| + def FetchResource(self, branch, path): |
| + result = self._Resource() |
| + result.content = _ReadFile(os.path.join(self.base_path, branch, path)) |
| + return result |
| + |
| +class TemplateFetcherTest(unittest.TestCase): |
| + def testFetcher(self): |
| + path = os.path.join('test_data', 'template_fetcher') |
| + fetcher = TestFetcher(path) |
| + t_fetcher = TemplateFetcher(fetcher) |
| + t_fetcher.FetchTemplate('a', 'test1.tmpl') |
| + t_fetcher.FetchTemplate('a', 'test2.tmpl') |
| + t_fetcher.FetchTemplate('b', 'test1.tmpl') |
|
not at google - send to devlin
2012/06/04 23:52:26
Two little things here: I thought we were doing .h
|
| + |
| + self.assertEqual(2, len(t_fetcher.AsDict('a'))) |
| + self.assertEqual(1, len(t_fetcher.AsDict('b'))) |
| + self.assertEqual(0, len(t_fetcher.AsDict('c'))) |
| + |
| + template_a1 = Handlebar(_ReadFile(os.path.join(path, 'a', 'test1.tmpl'))) |
| + self.assertEqual(template_a1.render('{}', {'templates': {}}).text, |
| + t_fetcher['a', 'test1.tmpl'].render('{}', {'templates': {}}).text) |
| + |
| + template_a2 = Handlebar(_ReadFile(os.path.join(path, 'a', 'test2.tmpl'))) |
| + self.assertEqual(template_a2.render('{}', {'templates': {}}).text, |
| + t_fetcher['a', 'test2.tmpl'].render('{}', {'templates': {}}).text) |
| + |
| + template_b1 = Handlebar(_ReadFile(os.path.join(path, 'b', 'test1.tmpl'))) |
| + self.assertEqual(template_b1.render('{}', {'templates': {}}).text, |
| + t_fetcher['b', 'test1.tmpl'].render('{}', {'templates': {}}).text) |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |