| OLD | NEW |
| 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 from HTMLParser import HTMLParser | 6 from HTMLParser import HTMLParser |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from fake_fetchers import ConfigureFakeFetchers | 9 from fake_fetchers import ConfigureFakeFetchers |
| 10 from github_file_system_provider import GithubFileSystemProvider | 10 from github_file_system_provider import GithubFileSystemProvider |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST), | 66 return RenderServlet(Request.ForTest(path, host=_ALLOWED_HOST), |
| 67 _RenderServletDelegate()).Get() | 67 _RenderServletDelegate()).Get() |
| 68 | 68 |
| 69 def _RenderAndCheck(self, path, issue, expected_equal): | 69 def _RenderAndCheck(self, path, issue, expected_equal): |
| 70 '''Renders |path| with |issue| patched in and asserts that the result is | 70 '''Renders |path| with |issue| patched in and asserts that the result is |
| 71 the same as |expected_equal| modulo any links that get rewritten to | 71 the same as |expected_equal| modulo any links that get rewritten to |
| 72 "_patch/issue". | 72 "_patch/issue". |
| 73 ''' | 73 ''' |
| 74 patched_response = self._RenderWithPatch(path, issue) | 74 patched_response = self._RenderWithPatch(path, issue) |
| 75 unpatched_response = self._RenderWithoutPatch(path) | 75 unpatched_response = self._RenderWithoutPatch(path) |
| 76 patched_response.headers.pop('cache-control', None) | 76 for header in ('Cache-Control', 'ETag'): |
| 77 unpatched_response.headers.pop('cache-control', None) | 77 patched_response.headers.pop(header, None) |
| 78 unpatched_response.headers.pop(header, None) |
| 78 unpatched_content = unpatched_response.content.ToString() | 79 unpatched_content = unpatched_response.content.ToString() |
| 79 | 80 |
| 80 # Check that all links in the patched content are qualified with | 81 # Check that all links in the patched content are qualified with |
| 81 # the patch URL, then strip them out for checking (in)equality. | 82 # the patch URL, then strip them out for checking (in)equality. |
| 82 patched_content = patched_response.content.ToString() | 83 patched_content = patched_response.content.ToString() |
| 83 patch_servlet_path = '_patch/%s' % issue | 84 patch_servlet_path = '_patch/%s' % issue |
| 84 errors = _CheckURLsArePatched(patched_content, patch_servlet_path) | 85 errors = _CheckURLsArePatched(patched_content, patch_servlet_path) |
| 85 self.assertFalse(errors, | 86 self.assertFalse(errors, |
| 86 '%s\nFound errors:\n * %s' % (patched_content, '\n * '.join(errors))) | 87 '%s\nFound errors:\n * %s' % (patched_content, '\n * '.join(errors))) |
| 87 patched_content = patched_content.replace('/%s' % patch_servlet_path, '') | 88 patched_content = patched_content.replace('/%s' % patch_servlet_path, '') |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 '%s/_patch/12345' % _ALLOWED_HOST)) | 158 '%s/_patch/12345' % _ALLOWED_HOST)) |
| 158 self.assertTrue(*is_redirect('http://developers.google.com', '12345', | 159 self.assertTrue(*is_redirect('http://developers.google.com', '12345', |
| 159 '%s/_patch/12345' % _ALLOWED_HOST)) | 160 '%s/_patch/12345' % _ALLOWED_HOST)) |
| 160 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345', | 161 self.assertFalse(*is_redirect('http://chrome-apps-doc.appspot.com', '12345', |
| 161 None)) | 162 None)) |
| 162 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345', | 163 self.assertFalse(*is_redirect('http://some-other-app.appspot.com', '12345', |
| 163 None)) | 164 None)) |
| 164 | 165 |
| 165 if __name__ == '__main__': | 166 if __name__ == '__main__': |
| 166 unittest.main() | 167 unittest.main() |
| OLD | NEW |