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

Side by Side Diff: chrome/common/extensions/docs/server2/patch_servlet_test.py

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better redirects 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import unittest 6 import unittest
7 7
8 from empty_dir_file_system import EmptyDirFileSystem 8 from empty_dir_file_system import EmptyDirFileSystem
9 from fake_fetchers import ConfigureFakeFetchers 9 from fake_fetchers import ConfigureFakeFetchers
10 from local_file_system import LocalFileSystem 10 from local_file_system import LocalFileSystem
11 from patch_servlet import PatchServlet 11 from patch_servlet import PatchServlet
12 from render_servlet import RenderServlet 12 from render_servlet import RenderServlet
13 from server_instance import ServerInstance 13 from server_instance import ServerInstance
14 from servlet import Request 14 from servlet import Request
15 from test_util import DisableLogging 15 from test_util import DisableLogging
16 16
17 _ALLOWED_HOST = 'https://chrome-apps-doc.appspot.com' 17 _ALLOWED_HOST = 'https://chrome-apps-doc.appspot.com'
18 18
19 class _RenderServletDelegate(RenderServlet.Delegate): 19 class _RenderServletDelegate(RenderServlet.Delegate):
20 def CreateServerInstanceForChannel(self, channel): 20 def CreateServerInstance(self):
21 return ServerInstance.ForLocal() 21 return ServerInstance.ForLocal()
22 22
23 class _PatchServletDelegate(RenderServlet.Delegate): 23 class _PatchServletDelegate(RenderServlet.Delegate):
24 def CreateAppSamplesFileSystem(self, object_store_creator): 24 def CreateAppSamplesFileSystem(self, object_store_creator):
25 return EmptyDirFileSystem() 25 return EmptyDirFileSystem()
26 26
27 def CreateHostFileSystemForBranch(self, channel): 27 def CreateHostFileSystem(self):
28 return LocalFileSystem.Create() 28 return LocalFileSystem.Create()
29 29
30 class PatchServletTest(unittest.TestCase): 30 class PatchServletTest(unittest.TestCase):
31 def setUp(self): 31 def setUp(self):
32 ConfigureFakeFetchers() 32 ConfigureFakeFetchers()
33 33
34 def _RenderWithPatch(self, path, issue): 34 def _RenderWithPatch(self, path, issue):
35 real_path = '%s/%s' % (issue, path) 35 path_with_issue = '%s/%s' % (issue, path)
36 return PatchServlet(Request.ForTest(real_path, host=_ALLOWED_HOST), 36 return PatchServlet(Request.ForTest(path_with_issue, host=_ALLOWED_HOST),
37 _PatchServletDelegate()).Get() 37 _PatchServletDelegate()).Get()
38 38
39 def _RenderWithoutPatch(self, path): 39 def _RenderWithoutPatch(self, path):
40 return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST), 40 return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST),
41 _RenderServletDelegate()).Get() 41 _RenderServletDelegate()).Get()
42 42
43 def _RenderAndCheck(self, path, issue, expected_equal): 43 def _RenderAndCheck(self, path, issue, expected_equal):
44 patched_response = self._RenderWithPatch(path, issue) 44 patched_response = self._RenderWithPatch(path, issue)
45 unpatched_response = self._RenderWithoutPatch(path) 45 unpatched_response = self._RenderWithoutPatch(path)
46 patched_response.headers.pop('cache-control', None) 46 patched_response.headers.pop('cache-control', None)
(...skipping 10 matching lines...) Expand all
57 self.assertNotEqual(patched_content, unpatched_content) 57 self.assertNotEqual(patched_content, unpatched_content)
58 58
59 def _RenderAndAssertEqual(self, path, issue): 59 def _RenderAndAssertEqual(self, path, issue):
60 self._RenderAndCheck(path, issue, True) 60 self._RenderAndCheck(path, issue, True)
61 61
62 def _RenderAndAssertNotEqual(self, path, issue): 62 def _RenderAndAssertNotEqual(self, path, issue):
63 self._RenderAndCheck(path, issue, False) 63 self._RenderAndCheck(path, issue, False)
64 64
65 @DisableLogging('warning') 65 @DisableLogging('warning')
66 def _AssertNotFound(self, path, issue): 66 def _AssertNotFound(self, path, issue):
67 self.assertEqual(self._RenderWithPatch(path, issue).status, 404, 67 response = self._RenderWithPatch(path, issue)
68 'Path %s with issue %s should have been removed.' % (path, issue)) 68 self.assertEqual(response.status, 404,
69 'Path %s with issue %s should have been removed for %s.' % (
70 path, issue, response))
69 71
70 def _AssertOk(self, path, issue): 72 def _AssertOk(self, path, issue):
71 response = self._RenderWithPatch(path, issue) 73 response = self._RenderWithPatch(path, issue)
72 self.assertEqual(response.status, 200, 74 self.assertEqual(response.status, 200,
73 'Failed to render path %s with issue %s.' % (path, issue)) 75 'Failed to render path %s with issue %s.' % (path, issue))
74 self.assertTrue(len(response.content.ToString()) > 0, 76 self.assertTrue(len(response.content.ToString()) > 0,
75 'Rendered result for path %s with issue %s should not be empty.' % 77 'Rendered result for path %s with issue %s should not be empty.' %
76 (path, issue)) 78 (path, issue))
77 79
80 def _AssertRedirect(self, path, issue, redirect_path):
81 response = self._RenderWithPatch(path, issue)
82 self.assertEqual(302, response.status)
83 self.assertEqual('/_patch/%s/%s' % (issue, redirect_path),
84 response.headers['Location'])
85
78 def testRender(self): 86 def testRender(self):
79 # '_patch' is not included in paths below because it's stripped by Handler. 87 # '_patch' is not included in paths below because it's stripped by Handler.
80 issue = '14096030' 88 issue = '14096030'
81 89
82 # extensions_sidenav.json is modified in the patch. 90 # extensions_sidenav.json is modified in the patch.
83 self._RenderAndAssertNotEqual('extensions/index.html', issue) 91 self._RenderAndAssertNotEqual('extensions/index.html', issue)
92
84 # apps_sidenav.json is not patched. 93 # apps_sidenav.json is not patched.
85 self._RenderAndAssertEqual('apps/about_apps.html', issue) 94 self._RenderAndAssertEqual('apps/about_apps.html', issue)
86 95
87 # extensions/runtime.html is removed in the patch. 96 # extensions/runtime.html is removed in the patch, should redirect to the
88 self._AssertNotFound('extensions/runtime.html', issue) 97 # apps version.
98 self._AssertRedirect('extensions/runtime.html', issue,
99 'apps/runtime.html')
100
89 # apps/runtime.html is not removed. 101 # apps/runtime.html is not removed.
90 self._RenderAndAssertEqual('apps/runtime.html', issue) 102 self._RenderAndAssertEqual('apps/runtime.html', issue)
91 103
92 # test_foo.html is added in the patch. 104 # test_foo.html is added in the patch.
93 self._AssertOk('extensions/test_foo.html', issue) 105 self._AssertOk('extensions/test_foo.html', issue)
94 106
95 # Invalid issue number results in a 404. 107 # Invalid issue number results in a 404.
96 self._AssertNotFound('extensions/index.html', '11111') 108 self._AssertNotFound('extensions/index.html', '11111')
97 109
98 # Test redirect. 110 # Test redirect.
(...skipping 18 matching lines...) Expand all
117 '%s/_patch/12345' % _ALLOWED_HOST)) 129 '%s/_patch/12345' % _ALLOWED_HOST))
118 self.assertTrue(*is_redirect('http://developers.google.com', '12345', 130 self.assertTrue(*is_redirect('http://developers.google.com', '12345',
119 '%s/_patch/12345' % _ALLOWED_HOST)) 131 '%s/_patch/12345' % _ALLOWED_HOST))
120 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345', 132 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345',
121 None)) 133 None))
122 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345', 134 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345',
123 None)) 135 None))
124 136
125 if __name__ == '__main__': 137 if __name__ == '__main__':
126 unittest.main() 138 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698