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

Unified Diff: chrome/common/extensions/docs/server2/patch_servlet_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: rebase 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/patch_servlet_test.py
===================================================================
--- chrome/common/extensions/docs/server2/patch_servlet_test.py (revision 0)
+++ chrome/common/extensions/docs/server2/patch_servlet_test.py (revision 0)
@@ -0,0 +1,94 @@
+#!/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 unittest
+
+from empty_dir_file_system import EmptyDirFileSystem
+from fake_fetchers import ConfigureFakeFetchers
+from local_file_system import LocalFileSystem
+from patch_servlet import PatchServlet
+from render_servlet import RenderServlet
+from server_instance import ServerInstance
+from servlet import Request
+
+class _RenderServletDelegate(RenderServlet.Delegate):
+ def CreateServerInstanceForChannel(self, channel):
+ return ServerInstance.ForTest(LocalFileSystem.Create())
+
+class _PatchServletDelegate(PatchServlet.Delegate):
+ def _GetChannel(self, channel):
+ return 'test'
+
+ def CreateAppSamplesFileSystem(self, object_store_creator):
+ return EmptyDirFileSystem()
+
+ def CreateHostFileSystemForBranch(self, channel):
+ return LocalFileSystem.Create()
+
+class PatchServletTest(unittest.TestCase):
+ def setUp(self):
+ ConfigureFakeFetchers()
+
+ def renderWithPatch(self, path, issue):
not at google - send to devlin 2013/05/11 20:39:53 _RenderWithPatch though it looks like none of the
方觉(Fang Jue) 2013/05/12 03:01:47 Done.
+ real_path = '%s/%s' % (issue, path)
+ return PatchServlet(Request.ForTest(real_path),
+ _PatchServletDelegate(issue)).Get()
+
+ def renderWithoutPatch(self, path):
not at google - send to devlin 2013/05/11 20:39:53 _RenderWithoutPatch
方觉(Fang Jue) 2013/05/12 03:01:47 Done.
+ return RenderServlet(Request.ForTest(path), _RenderServletDelegate()).Get()
+
+ def compare(self, patched_response, unpatched_response, issue):
not at google - send to devlin 2013/05/11 20:39:53 _Compare, but besides "compare" usually implies a
方觉(Fang Jue) 2013/05/12 04:22:07 Done.
+ patched_response.headers.pop('cache-control', None)
+ unpatched_response.headers.pop('cache-control', None)
+ return (patched_response.status == unpatched_response.status and
+ patched_response.headers == unpatched_response.headers and
+ patched_response.content.ToString().replace(
+ '/_patch/%s/static/' % issue, '/test/static/') ==
+ unpatched_response.content.ToString())
+
+ def renderAndCompare(self, path, issue):
not at google - send to devlin 2013/05/11 20:39:53 _IsRenderingEqual?
方觉(Fang Jue) 2013/05/12 03:01:47 Done.
+ return self.compare(self.renderWithPatch(path, issue),
+ self.renderWithoutPatch(path),
+ issue)
+
+ def assertNotFound(self, path, issue):
+ self.assertEqual(self.renderWithPatch(path, issue).status, 404,
+ 'Path %s with issue %s should have been removed.' % (path, issue))
+
+ def assertOk(self, path, issue):
+ response = self.renderWithPatch(path, issue)
+ self.assertEqual(response.status, 200,
+ 'Failed to render path %s with issue %s.' % (path, issue))
+ self.assertTrue(len(response.content.ToString()) > 0,
+ 'Rendered result for path %s with issue %s should not be empty.' %
+ (path, issue))
+
+ def testRender(self):
+ # '_patch' is not included in paths below because it's stripped by Handler.
+ issue = '14096030'
+
+ # extensions_sidenav.json is modified in the patch.
+ self.assertFalse(self.renderAndCompare('extensions/index.html', issue))
+ # apps_sidenav.json is not patched.
+ self.assertTrue(self.renderAndCompare('apps/about_apps.html', issue))
+
+ # extensions/runtime.html is removed in the patch.
+ self.assertNotFound('extensions/runtime.html', issue)
+ # apps/runtime.html is not removed.
+ self.assertTrue(self.renderAndCompare('apps/runtime.html', issue))
+
+ # test_foo.html is added in the patch.
+ self.assertOk('extensions/test_foo.html', issue)
+
+ # Invalid issue number results in a 404.
+ self.assertNotFound('extensions/index.html', '11111')
+
+ # Test redirect.
+ self.assertEqual(self.renderWithPatch('extensions/',
+ issue).headers['Location'],
+ '/_patch/%s/extensions/index.html' % issue)
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: chrome/common/extensions/docs/server2/patch_servlet_test.py
___________________________________________________________________
Added: svn:eol-style
+ LF
Added: svn:executable
+ *

Powered by Google App Engine
This is Rietveld 408576698