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

Side by Side Diff: chrome/common/extensions/docs/server2/fake_fetchers.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: 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # These are fake fetchers that are used for testing and the preview server. 5 # These are fake fetchers that are used for testing and the preview server.
6 # They return canned responses for URLs. appengine_wrappers.py uses the fake 6 # They return canned responses for URLs. appengine_wrappers.py uses the fake
7 # fetchers if the App Engine imports fail. 7 # fetchers if the App Engine imports fail.
8 8
9 import os 9 import os
10 import re 10 import re
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 def fetch(self, url): 97 def fetch(self, url):
98 try: 98 try:
99 return self._ReadFile(os.path.join('server2', 99 return self._ReadFile(os.path.join('server2',
100 'test_data', 100 'test_data',
101 'github_file_system', 101 'github_file_system',
102 'apps_samples.zip'), 102 'apps_samples.zip'),
103 mode='rb') 103 mode='rb')
104 except IOError: 104 except IOError:
105 return None 105 return None
106 106
107 class FakeIssuesFetcher(_FakeFetcher): 107 class FakeRietveldAPI(_FakeFetcher):
108 def __init__(self, base_path):
109 _FakeFetcher.__init__(self, base_path)
110 self._base_pattern = re.compile(r'.*/(api/.*)')
111
108 def fetch(self, url): 112 def fetch(self, url):
109 return 'Status,Summary,ID' 113 try:
114 return self._ReadFile(
115 os.path.join('server2',
116 'test_data',
117 'rietveld_file_system',
118 self._base_pattern.match(url).group(1),
119 'json'))
120 except IOError:
121 return None
122
123 class FakeRietveldTarball(_FakeFetcher):
124 def __init__(self, base_path):
125 _FakeFetcher.__init__(self, base_path)
126 self._base_pattern = re.compile(r'.*/(tarball/\d+/\d+)')
127
128 def fetch(self, url):
129 try:
130 return self._ReadFile(
131 os.path.join('server2',
132 'test_data',
133 'rietveld_file_system',
134 self._base_pattern.match(url).group(1) + '.tar.bz2'))
135 except IOError:
136 return None
110 137
111 def ConfigureFakeFetchers(docs): 138 def ConfigureFakeFetchers(docs):
112 '''Configure the fake fetcher paths relative to the docs directory. 139 '''Configure the fake fetcher paths relative to the docs directory.
113 ''' 140 '''
114 appengine_wrappers.ConfigureFakeUrlFetch({ 141 appengine_wrappers.ConfigureFakeUrlFetch({
115 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs), 142 url_constants.OMAHA_PROXY_URL: FakeOmahaProxy(docs),
116 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs), 143 '%s/.*' % url_constants.SVN_URL: FakeSubversionServer(docs),
117 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs), 144 '%s/.*' % url_constants.VIEWVC_URL: FakeViewvcServer(docs),
118 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs), 145 '%s/commits/.*' % url_constants.GITHUB_URL: FakeGithubStat(docs),
119 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs), 146 '%s/zipball' % url_constants.GITHUB_URL: FakeGithubZip(docs),
120 re.escape(url_constants.OPEN_ISSUES_CSV_URL): FakeIssuesFetcher(docs), 147 '%s/api/.*' % url_constants.CODEREVIEW_SERVER: FakeRietveldAPI(docs),
121 re.escape(url_constants.CLOSED_ISSUES_CSV_URL): FakeIssuesFetcher(docs) 148 '%s/tarball/.*' % url_constants.CODEREVIEW_SERVER:
149 FakeRietveldTarball(docs),
122 }) 150 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698