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

Side by Side 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 unified diff | Download patch
Property Changes:
Added: svn:eol-style
+ LF
Added: svn:executable
+ *
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import unittest
7
8 from empty_dir_file_system import EmptyDirFileSystem
9 from fake_fetchers import ConfigureFakeFetchers
10 from local_file_system import LocalFileSystem
11 from patch_servlet import PatchServlet
12 from render_servlet import RenderServlet
13 from server_instance import ServerInstance
14 from servlet import Request
15
16 class _RenderServletDelegate(RenderServlet.Delegate):
17 def CreateServerInstanceForChannel(self, channel):
18 return ServerInstance.ForTest(LocalFileSystem.Create())
19
20 class _PatchServletDelegate(PatchServlet.Delegate):
21 def _GetChannel(self, channel):
22 return 'test'
23
24 def CreateAppSamplesFileSystem(self, object_store_creator):
25 return EmptyDirFileSystem()
26
27 def CreateHostFileSystemForBranch(self, channel):
28 return LocalFileSystem.Create()
29
30 class PatchServletTest(unittest.TestCase):
31 def setUp(self):
32 ConfigureFakeFetchers()
33
34 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.
35 real_path = '%s/%s' % (issue, path)
36 return PatchServlet(Request.ForTest(real_path),
37 _PatchServletDelegate(issue)).Get()
38
39 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.
40 return RenderServlet(Request.ForTest(path), _RenderServletDelegate()).Get()
41
42 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.
43 patched_response.headers.pop('cache-control', None)
44 unpatched_response.headers.pop('cache-control', None)
45 return (patched_response.status == unpatched_response.status and
46 patched_response.headers == unpatched_response.headers and
47 patched_response.content.ToString().replace(
48 '/_patch/%s/static/' % issue, '/test/static/') ==
49 unpatched_response.content.ToString())
50
51 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.
52 return self.compare(self.renderWithPatch(path, issue),
53 self.renderWithoutPatch(path),
54 issue)
55
56 def assertNotFound(self, path, issue):
57 self.assertEqual(self.renderWithPatch(path, issue).status, 404,
58 'Path %s with issue %s should have been removed.' % (path, issue))
59
60 def assertOk(self, path, issue):
61 response = self.renderWithPatch(path, issue)
62 self.assertEqual(response.status, 200,
63 'Failed to render path %s with issue %s.' % (path, issue))
64 self.assertTrue(len(response.content.ToString()) > 0,
65 'Rendered result for path %s with issue %s should not be empty.' %
66 (path, issue))
67
68 def testRender(self):
69 # '_patch' is not included in paths below because it's stripped by Handler.
70 issue = '14096030'
71
72 # extensions_sidenav.json is modified in the patch.
73 self.assertFalse(self.renderAndCompare('extensions/index.html', issue))
74 # apps_sidenav.json is not patched.
75 self.assertTrue(self.renderAndCompare('apps/about_apps.html', issue))
76
77 # extensions/runtime.html is removed in the patch.
78 self.assertNotFound('extensions/runtime.html', issue)
79 # apps/runtime.html is not removed.
80 self.assertTrue(self.renderAndCompare('apps/runtime.html', issue))
81
82 # test_foo.html is added in the patch.
83 self.assertOk('extensions/test_foo.html', issue)
84
85 # Invalid issue number results in a 404.
86 self.assertNotFound('extensions/index.html', '11111')
87
88 # Test redirect.
89 self.assertEqual(self.renderWithPatch('extensions/',
90 issue).headers['Location'],
91 '/_patch/%s/extensions/index.html' % issue)
92
93 if __name__ == '__main__':
94 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698