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

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: 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 unified diff | Download patch
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.ForLocal()
19
20 class _PatchServletDelegate(RenderServlet.Delegate):
21 def CreateAppSamplesFileSystem(self, object_store_creator):
22 return EmptyDirFileSystem()
23
24 def CreateHostFileSystemForBranch(self, channel):
25 return LocalFileSystem.Create()
26
27 class PatchServletTest(unittest.TestCase):
28 def setUp(self):
29 ConfigureFakeFetchers()
30
31 def _RenderWithPatch(self, path, issue):
32 real_path = '%s/%s' % (issue, path)
33 return PatchServlet(Request.ForTest(real_path),
34 _PatchServletDelegate()).Get()
35
36 def _RenderWithoutPatch(self, path):
37 return RenderServlet(Request.ForTest(path), _RenderServletDelegate()).Get()
38
39 def _RenderAndCheck(self, path, issue, expected_equal):
40 patched_response = self._RenderWithPatch(path, issue)
41 unpatched_response = self._RenderWithoutPatch(path)
42 patched_response.headers.pop('cache-control', None)
43 unpatched_response.headers.pop('cache-control', None)
44 patched_content = patched_response.content.ToString().replace(
45 '/_patch/%s/static/' % issue, '/static/')
46 unpatched_content = unpatched_response.content.ToString()
47
48 self.assertEqual(patched_response.status, unpatched_response.status)
49 self.assertEqual(patched_response.headers, unpatched_response.headers)
50 if expected_equal:
51 self.assertEqual(patched_content, unpatched_content)
52 else:
53 self.assertNotEqual(patched_content, unpatched_content)
54
55 def _RenderAndAssertEqual(self, path, issue):
56 self._RenderAndCheck(path, issue, True)
57
58 def _RenderAndAssertNotEqual(self, path, issue):
59 self._RenderAndCheck(path, issue, False)
60
61 def _AssertNotFound(self, path, issue):
62 self.assertEqual(self._RenderWithPatch(path, issue).status, 404,
63 'Path %s with issue %s should have been removed.' % (path, issue))
64
65 def _AssertOk(self, path, issue):
66 response = self._RenderWithPatch(path, issue)
67 self.assertEqual(response.status, 200,
68 'Failed to render path %s with issue %s.' % (path, issue))
69 self.assertTrue(len(response.content.ToString()) > 0,
70 'Rendered result for path %s with issue %s should not be empty.' %
71 (path, issue))
72
73 def testRender(self):
74 # '_patch' is not included in paths below because it's stripped by Handler.
75 issue = '14096030'
76
77 # extensions_sidenav.json is modified in the patch.
78 self._RenderAndAssertNotEqual('extensions/index.html', issue)
79 # apps_sidenav.json is not patched.
80 self._RenderAndAssertEqual('apps/about_apps.html', issue)
81
82 # extensions/runtime.html is removed in the patch.
83 self._AssertNotFound('extensions/runtime.html', issue)
84 # apps/runtime.html is not removed.
85 self._RenderAndAssertEqual('apps/runtime.html', issue)
86
87 # test_foo.html is added in the patch.
88 self._AssertOk('extensions/test_foo.html', issue)
89
90 # Invalid issue number results in a 404.
91 self._AssertNotFound('extensions/index.html', '11111')
92
93 # Test redirect.
94 self.assertEqual(self._RenderWithPatch('extensions/',
95 issue).headers['Location'],
96 '/_patch/%s/extensions/index.html' % issue)
97
98 if __name__ == '__main__':
99 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/patch_servlet.py ('k') | chrome/common/extensions/docs/server2/patched_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698