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

Unified Diff: chrome/common/extensions/docs/server2/rietveld_patcher_test.py

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: add executable bits for tests Created 7 years, 7 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/rietveld_patcher_test.py
diff --git a/chrome/common/extensions/docs/server2/rietveld_patcher_test.py b/chrome/common/extensions/docs/server2/rietveld_patcher_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..c6a8a7e81678c78768bf4c254bc730aae5805eab
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/rietveld_patcher_test.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright 2013 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 sys
+import unittest
+from appengine_url_fetcher import AppEngineUrlFetcher
+from fake_fetchers import ConfigureFakeFetchers
+from file_system import FileNotFoundError
+from rietveld_patcher import RietveldPatcher
+from svn_constants import EXTENSIONS_PATH
+import url_constants
+
+class RietveldPatcherTest(unittest.TestCase):
+ def setUp(self):
+ ConfigureFakeFetchers()
+ self._patcher = RietveldPatcher(
+ EXTENSIONS_PATH,
+ '14096030',
+ AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER))
+
+ def _ReadLocalFile(self, filename):
+ with open(os.path.join(sys.path[0],
+ 'test_data',
+ 'rietveld_patcher',
+ 'expected',
+ filename), 'r') as f:
+ return f.read()
+
+ def _ApplySingle(self, path, binary=False):
+ return self._patcher.Apply([path], None, binary).Get()[path]
+
+ def testGetVersion(self):
+ self.assertEqual(self._patcher.GetVersion(), '22002')
+
+ def testGetPatchedFiles(self):
+ added, deleted, modified = self._patcher.GetPatchedFiles()
+ self.assertEqual(sorted(added),
+ sorted([
+ u'docs/templates/articles/test_foo.html',
+ u'docs/templates/public/extensions/test_foo.html']))
+ self.assertEqual(sorted(deleted),
+ sorted([
+ u'docs/templates/public/extensions/runtime.html']))
+ self.assertEqual(sorted(modified),
+ sorted([
+ u'api/test.json',
+ u'docs/templates/json/extensions_sidenav.json']))
+
+ def testApply(self):
+ article_path = 'docs/templates/articles/test_foo.html'
+
+ # Make sure RietveldPatcher handles |binary| correctly.
+ self.assertTrue(isinstance(self._ApplySingle(article_path, True), str),
+ 'Expected result is binary. It was text.')
+ self.assertTrue(isinstance(self._ApplySingle(article_path), unicode),
+ 'Expected result is text. It was binary.')
+
+ # Apply to an added file.
+ self.assertEqual(
+ self._ReadLocalFile('test_foo.html'),
+ self._ApplySingle(
+ 'docs/templates/public/extensions/test_foo.html'))
+
+ # Apply to a modified file.
+ self.assertEqual(
+ self._ReadLocalFile('extensions_sidenav.json'),
+ self._ApplySingle(
+ 'docs/templates/json/extensions_sidenav.json'))
+
+ # Applying to a deleted file doesn't throw exceptions. It just returns
+ # empty content.
+ # self.assertRaises(FileNotFoundError, self._ApplySingle,
+ # 'docs/templates/public/extensions/runtime.html')
+
+ # Apply to an unknown file.
+ self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing')
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « chrome/common/extensions/docs/server2/rietveld_patcher.py ('k') | chrome/common/extensions/docs/server2/robots.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698