Merge lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra into lp:launchpad
- rename-google-as-sitesearch-extra
- Merge into devel
Proposed by
Maximiliano Bertacchini
Status: | Merged |
---|---|
Merged at revision: | 18593 |
Proposed branch: | lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra |
Merge into: | lp:launchpad |
Diff against target: |
268 lines (+34/-33) 6 files modified
lib/lp/app/browser/root.py (+5/-5) lib/lp/app/browser/tests/launchpad-search-pages.txt (+9/-9) lib/lp/services/sitesearch/__init__.py (+5/-4) lib/lp/services/sitesearch/doc/google-searchservice.txt (+1/-1) lib/lp/services/sitesearch/interfaces.py (+3/-3) lib/lp/services/sitesearch/tests/test_google.py (+11/-11) |
To merge this branch: | bzr merge lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Colin Watson (community) | Approve | ||
Review via email: mp+342148@code.launchpad.net |
Commit message
A few extra renamed classes from Google* to SiteSearch*.
Description of the change
A few extra renamed classes from Google* to SiteSearch*.
- Rename GoogleBatchNavi
- Rename GoogleResponseError as SiteSearchRespo
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/lp/app/browser/root.py' | |||
2 | --- lib/lp/app/browser/root.py 2018-03-16 14:50:01 +0000 | |||
3 | +++ lib/lp/app/browser/root.py 2018-03-27 14:32:46 +0000 | |||
4 | @@ -42,8 +42,8 @@ | |||
5 | 42 | from lp.services.memcache.interfaces import IMemcacheClient | 42 | from lp.services.memcache.interfaces import IMemcacheClient |
6 | 43 | from lp.services.propertycache import cachedproperty | 43 | from lp.services.propertycache import cachedproperty |
7 | 44 | from lp.services.sitesearch.interfaces import ( | 44 | from lp.services.sitesearch.interfaces import ( |
8 | 45 | GoogleResponseError, | ||
9 | 46 | ISearchService, | 45 | ISearchService, |
10 | 46 | SiteSearchResponseError, | ||
11 | 47 | ) | 47 | ) |
12 | 48 | from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet | 48 | from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet |
13 | 49 | from lp.services.timeout import urlfetch | 49 | from lp.services.timeout import urlfetch |
14 | @@ -520,14 +520,14 @@ | |||
15 | 520 | try: | 520 | try: |
16 | 521 | page_matches = google_search.search( | 521 | page_matches = google_search.search( |
17 | 522 | terms=query_terms, start=start) | 522 | terms=query_terms, start=start) |
19 | 523 | except GoogleResponseError: | 523 | except SiteSearchResponseError: |
20 | 524 | # There was a connectivity or Google service issue that means | 524 | # There was a connectivity or Google service issue that means |
21 | 525 | # there is no data available at this moment. | 525 | # there is no data available at this moment. |
22 | 526 | self.has_page_service = False | 526 | self.has_page_service = False |
23 | 527 | return None | 527 | return None |
24 | 528 | if len(page_matches) == 0: | 528 | if len(page_matches) == 0: |
25 | 529 | return None | 529 | return None |
27 | 530 | navigator = GoogleBatchNavigator( | 530 | navigator = SiteSearchBatchNavigator( |
28 | 531 | page_matches, self.request, start=start) | 531 | page_matches, self.request, start=start) |
29 | 532 | navigator.setHeadings(*self.batch_heading) | 532 | navigator.setHeadings(*self.batch_heading) |
30 | 533 | return navigator | 533 | return navigator |
31 | @@ -589,7 +589,7 @@ | |||
32 | 589 | return self.start + len(self.list._window) | 589 | return self.start + len(self.list._window) |
33 | 590 | 590 | ||
34 | 591 | 591 | ||
36 | 592 | class GoogleBatchNavigator(BatchNavigator): | 592 | class SiteSearchBatchNavigator(BatchNavigator): |
37 | 593 | """A batch navigator with a fixed size of 20 items per batch.""" | 593 | """A batch navigator with a fixed size of 20 items per batch.""" |
38 | 594 | 594 | ||
39 | 595 | _batch_factory = WindowedListBatch | 595 | _batch_factory = WindowedListBatch |
40 | @@ -614,7 +614,7 @@ | |||
41 | 614 | :param callback: Not used. | 614 | :param callback: Not used. |
42 | 615 | """ | 615 | """ |
43 | 616 | results = WindowedList(results, start, results.total) | 616 | results = WindowedList(results, start, results.total) |
45 | 617 | super(GoogleBatchNavigator, self).__init__(results, request, | 617 | super(SiteSearchBatchNavigator, self).__init__(results, request, |
46 | 618 | start=start, size=size, callback=callback, | 618 | start=start, size=size, callback=callback, |
47 | 619 | transient_parameters=transient_parameters, | 619 | transient_parameters=transient_parameters, |
48 | 620 | force_start=force_start, range_factory=range_factory) | 620 | force_start=force_start, range_factory=range_factory) |
49 | 621 | 621 | ||
50 | === modified file 'lib/lp/app/browser/tests/launchpad-search-pages.txt' | |||
51 | --- lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-16 14:02:16 +0000 | |||
52 | +++ lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-27 14:32:46 +0000 | |||
53 | @@ -416,7 +416,7 @@ | |||
54 | 416 | >>> search_view.has_matches | 416 | >>> search_view.has_matches |
55 | 417 | True | 417 | True |
56 | 418 | >>> search_view.pages | 418 | >>> search_view.pages |
58 | 419 | <...GoogleBatchNavigator ...> | 419 | <...SiteSearchBatchNavigator ...> |
59 | 420 | 420 | ||
60 | 421 | The GoogleSearchService may not be available due to connectivity problems. | 421 | The GoogleSearchService may not be available due to connectivity problems. |
61 | 422 | The view's has_page_service attribute reports when the search was performed | 422 | The view's has_page_service attribute reports when the search was performed |
62 | @@ -444,7 +444,7 @@ | |||
63 | 444 | >>> search_view.batch_heading | 444 | >>> search_view.batch_heading |
64 | 445 | (u'other page matching "launchpad"', u'other pages matching "launchpad"') | 445 | (u'other page matching "launchpad"', u'other pages matching "launchpad"') |
65 | 446 | 446 | ||
67 | 447 | The GoogleBatchNavigator behaves like most BatchNavigators, except that | 447 | The SiteSearchBatchNavigator behaves like most BatchNavigators, except that |
68 | 448 | its batch size is always 20. The size restriction conforms to Google's | 448 | its batch size is always 20. The size restriction conforms to Google's |
69 | 449 | maximum number of results that can be returned per request. | 449 | maximum number of results that can be returned per request. |
70 | 450 | 450 | ||
71 | @@ -625,7 +625,7 @@ | |||
72 | 625 | </div> | 625 | </div> |
73 | 626 | </form> | 626 | </form> |
74 | 627 | 627 | ||
76 | 628 | WindowedList and GoogleBatchNavigator | 628 | WindowedList and SiteSearchBatchNavigator |
77 | 629 | ------------------------------------- | 629 | ------------------------------------- |
78 | 630 | 630 | ||
79 | 631 | The LaunchpadSearchView uses two helper classes to work with | 631 | The LaunchpadSearchView uses two helper classes to work with |
80 | @@ -635,7 +635,7 @@ | |||
81 | 635 | or fewer PageMatches of what could be thousands of matches. Google | 635 | or fewer PageMatches of what could be thousands of matches. Google |
82 | 636 | requires client's to make repeats request to step though the batches of | 636 | requires client's to make repeats request to step though the batches of |
83 | 637 | matches. The Windowed list is a list that contains only a subset of its | 637 | matches. The Windowed list is a list that contains only a subset of its |
85 | 638 | reported size. It is used to make batches in the GoogleBatchNavigator. | 638 | reported size. It is used to make batches in the SiteSearchBatchNavigator. |
86 | 639 | 639 | ||
87 | 640 | For example, the last batch of the 'bug' search contained 5 of the 25 | 640 | For example, the last batch of the 'bug' search contained 5 of the 25 |
88 | 641 | matching pages. The WindowList claims to be 25 items in length, but | 641 | matching pages. The WindowList claims to be 25 items in length, but |
89 | @@ -657,14 +657,14 @@ | |||
90 | 657 | >>> results[18, 22] | 657 | >>> results[18, 22] |
91 | 658 | [None, None, <...PageMatch ...>, <...PageMatch ...>] | 658 | [None, None, <...PageMatch ...>, <...PageMatch ...>] |
92 | 659 | 659 | ||
94 | 660 | The GoogleBatchNavigator restricts the batch size to 20. the 'batch' | 660 | The SiteSearchBatchNavigator restricts the batch size to 20. the 'batch' |
95 | 661 | parameter that comes from the URL is ignored. For example, setting | 661 | parameter that comes from the URL is ignored. For example, setting |
96 | 662 | the 'batch' parameter to 100 has no affect upon the Google search | 662 | the 'batch' parameter to 100 has no affect upon the Google search |
97 | 663 | or on the navigator object. | 663 | or on the navigator object. |
98 | 664 | 664 | ||
100 | 665 | >>> from lp.app.browser.root import GoogleBatchNavigator | 665 | >>> from lp.app.browser.root import SiteSearchBatchNavigator |
101 | 666 | 666 | ||
103 | 667 | >>> GoogleBatchNavigator.batch_variable_name | 667 | >>> SiteSearchBatchNavigator.batch_variable_name |
104 | 668 | 'batch' | 668 | 'batch' |
105 | 669 | 669 | ||
106 | 670 | >>> search_view = getSearchView( | 670 | >>> search_view = getSearchView( |
107 | @@ -687,7 +687,7 @@ | |||
108 | 687 | >>> page_matches._matches = matches | 687 | >>> page_matches._matches = matches |
109 | 688 | >>> page_matches.start = 0 | 688 | >>> page_matches.start = 0 |
110 | 689 | >>> page_matches.total = 100 | 689 | >>> page_matches.total = 100 |
112 | 690 | >>> navigator = GoogleBatchNavigator( | 690 | >>> navigator = SiteSearchBatchNavigator( |
113 | 691 | ... page_matches, search_view.request, page_matches.start, size=100) | 691 | ... page_matches, search_view.request, page_matches.start, size=100) |
114 | 692 | >>> navigator.currentBatch().size | 692 | >>> navigator.currentBatch().size |
115 | 693 | 20 | 693 | 20 |
116 | @@ -705,7 +705,7 @@ | |||
117 | 705 | 705 | ||
118 | 706 | >>> matches = list(range(0, 3)) | 706 | >>> matches = list(range(0, 3)) |
119 | 707 | >>> page_matches._matches = matches | 707 | >>> page_matches._matches = matches |
121 | 708 | >>> navigator = GoogleBatchNavigator( | 708 | >>> navigator = SiteSearchBatchNavigator( |
122 | 709 | ... page_matches, search_view.request, page_matches.start, size=100) | 709 | ... page_matches, search_view.request, page_matches.start, size=100) |
123 | 710 | >>> batch = navigator.currentBatch() | 710 | >>> batch = navigator.currentBatch() |
124 | 711 | >>> batch.size | 711 | >>> batch.size |
125 | 712 | 712 | ||
126 | === modified file 'lib/lp/services/sitesearch/__init__.py' | |||
127 | --- lib/lp/services/sitesearch/__init__.py 2018-03-26 21:56:11 +0000 | |||
128 | +++ lib/lp/services/sitesearch/__init__.py 2018-03-27 14:32:46 +0000 | |||
129 | @@ -25,11 +25,11 @@ | |||
130 | 25 | 25 | ||
131 | 26 | from lp.services.config import config | 26 | from lp.services.config import config |
132 | 27 | from lp.services.sitesearch.interfaces import ( | 27 | from lp.services.sitesearch.interfaces import ( |
133 | 28 | GoogleResponseError, | ||
134 | 29 | GoogleWrongGSPVersion, | 28 | GoogleWrongGSPVersion, |
135 | 30 | ISearchResult, | 29 | ISearchResult, |
136 | 31 | ISearchResults, | 30 | ISearchResults, |
137 | 32 | ISearchService, | 31 | ISearchService, |
138 | 32 | SiteSearchResponseError, | ||
139 | 33 | ) | 33 | ) |
140 | 34 | from lp.services.timeline.requesttimeline import get_request_timeline | 34 | from lp.services.timeline.requesttimeline import get_request_timeline |
141 | 35 | from lp.services.timeout import ( | 35 | from lp.services.timeout import ( |
142 | @@ -214,7 +214,7 @@ | |||
143 | 214 | except (TimeoutError, requests.RequestException) as error: | 214 | except (TimeoutError, requests.RequestException) as error: |
144 | 215 | # Google search service errors are not code errors. Let the | 215 | # Google search service errors are not code errors. Let the |
145 | 216 | # call site choose to handle the unavailable service. | 216 | # call site choose to handle the unavailable service. |
147 | 217 | raise GoogleResponseError( | 217 | raise SiteSearchResponseError( |
148 | 218 | "The response errored: %s" % str(error)) | 218 | "The response errored: %s" % str(error)) |
149 | 219 | finally: | 219 | finally: |
150 | 220 | action.finish() | 220 | action.finish() |
151 | @@ -276,7 +276,7 @@ | |||
152 | 276 | version 3.2 XML. There is no guarantee that other GSP versions | 276 | version 3.2 XML. There is no guarantee that other GSP versions |
153 | 277 | can be parsed. | 277 | can be parsed. |
154 | 278 | :return: `ISearchResults` (PageMatches). | 278 | :return: `ISearchResults` (PageMatches). |
156 | 279 | :raise: `GoogleResponseError` if the xml is incomplete. | 279 | :raise: `SiteSearchResponseError` if the xml is incomplete. |
157 | 280 | :raise: `GoogleWrongGSPVersion` if the xml cannot be parsed. | 280 | :raise: `GoogleWrongGSPVersion` if the xml cannot be parsed. |
158 | 281 | """ | 281 | """ |
159 | 282 | try: | 282 | try: |
160 | @@ -284,7 +284,8 @@ | |||
161 | 284 | start_param = self._getElementByAttributeValue( | 284 | start_param = self._getElementByAttributeValue( |
162 | 285 | gsp_doc, './PARAM', 'name', 'start') | 285 | gsp_doc, './PARAM', 'name', 'start') |
163 | 286 | except (SyntaxError, IndexError): | 286 | except (SyntaxError, IndexError): |
165 | 287 | raise GoogleResponseError("The response was incomplete, no xml.") | 287 | raise SiteSearchResponseError( |
166 | 288 | "The response was incomplete, no xml.") | ||
167 | 288 | try: | 289 | try: |
168 | 289 | start = int(start_param.get('value')) | 290 | start = int(start_param.get('value')) |
169 | 290 | except (AttributeError, ValueError): | 291 | except (AttributeError, ValueError): |
170 | 291 | 292 | ||
171 | === modified file 'lib/lp/services/sitesearch/doc/google-searchservice.txt' | |||
172 | --- lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-26 20:41:30 +0000 | |||
173 | +++ lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-27 14:32:46 +0000 | |||
174 | @@ -617,7 +617,7 @@ | |||
175 | 617 | >>> google_search.search(terms='bug') | 617 | >>> google_search.search(terms='bug') |
176 | 618 | Traceback (most recent call last): | 618 | Traceback (most recent call last): |
177 | 619 | ... | 619 | ... |
179 | 620 | GoogleResponseError: ... timeout exceeded. | 620 | SiteSearchResponseError: ... timeout exceeded. |
180 | 621 | 621 | ||
181 | 622 | # Restore the configuration and the timeout state. | 622 | # Restore the configuration and the timeout state. |
182 | 623 | >>> timeout_data = config.pop('timeout_data') | 623 | >>> timeout_data = config.pop('timeout_data') |
183 | 624 | 624 | ||
184 | === modified file 'lib/lp/services/sitesearch/interfaces.py' | |||
185 | --- lib/lp/services/sitesearch/interfaces.py 2013-01-07 02:40:55 +0000 | |||
186 | +++ lib/lp/services/sitesearch/interfaces.py 2018-03-27 14:32:46 +0000 | |||
187 | @@ -9,8 +9,8 @@ | |||
188 | 9 | 'ISearchResult', | 9 | 'ISearchResult', |
189 | 10 | 'ISearchResults', | 10 | 'ISearchResults', |
190 | 11 | 'ISearchService', | 11 | 'ISearchService', |
191 | 12 | 'GoogleResponseError', | ||
192 | 13 | 'GoogleWrongGSPVersion', | 12 | 'GoogleWrongGSPVersion', |
193 | 13 | 'SiteSearchResponseError', | ||
194 | 14 | ] | 14 | ] |
195 | 15 | 15 | ||
196 | 16 | from zope.interface import Interface | 16 | from zope.interface import Interface |
197 | @@ -74,8 +74,8 @@ | |||
198 | 74 | """Raised when the content is not parsable Google Search Protocol XML.""" | 74 | """Raised when the content is not parsable Google Search Protocol XML.""" |
199 | 75 | 75 | ||
200 | 76 | 76 | ||
203 | 77 | class GoogleResponseError(SyntaxError): | 77 | class SiteSearchResponseError(ValueError): |
204 | 78 | """Raised when Google's response is not contain valid XML.""" | 78 | """Raised when the search engine's response cannot be parsed.""" |
205 | 79 | 79 | ||
206 | 80 | 80 | ||
207 | 81 | class ISearchService(Interface): | 81 | class ISearchService(Interface): |
208 | 82 | 82 | ||
209 | === modified file 'lib/lp/services/sitesearch/tests/test_google.py' | |||
210 | --- lib/lp/services/sitesearch/tests/test_google.py 2018-03-16 14:02:16 +0000 | |||
211 | +++ lib/lp/services/sitesearch/tests/test_google.py 2018-03-27 14:32:46 +0000 | |||
212 | @@ -13,7 +13,7 @@ | |||
213 | 13 | ) | 13 | ) |
214 | 14 | 14 | ||
215 | 15 | from lp.services.sitesearch import GoogleSearchService | 15 | from lp.services.sitesearch import GoogleSearchService |
217 | 16 | from lp.services.sitesearch.interfaces import GoogleResponseError | 16 | from lp.services.sitesearch.interfaces import SiteSearchResponseError |
218 | 17 | from lp.services.timeout import TimeoutError | 17 | from lp.services.timeout import TimeoutError |
219 | 18 | from lp.testing import TestCase | 18 | from lp.testing import TestCase |
220 | 19 | from lp.testing.layers import LaunchpadFunctionalLayer | 19 | from lp.testing.layers import LaunchpadFunctionalLayer |
221 | @@ -49,37 +49,37 @@ | |||
222 | 49 | self.search_service = GoogleSearchService() | 49 | self.search_service = GoogleSearchService() |
223 | 50 | 50 | ||
224 | 51 | def test_search_converts_HTTPError(self): | 51 | def test_search_converts_HTTPError(self): |
226 | 52 | # The method converts HTTPError to GoogleResponseError. | 52 | # The method converts HTTPError to SiteSearchResponseError. |
227 | 53 | args = ('url', 500, 'oops', {}, None) | 53 | args = ('url', 500, 'oops', {}, None) |
228 | 54 | with urlfetch_exception(HTTPError, *args): | 54 | with urlfetch_exception(HTTPError, *args): |
229 | 55 | self.assertRaises( | 55 | self.assertRaises( |
231 | 56 | GoogleResponseError, self.search_service.search, 'fnord') | 56 | SiteSearchResponseError, self.search_service.search, 'fnord') |
232 | 57 | 57 | ||
233 | 58 | def test_search_converts_ConnectionError(self): | 58 | def test_search_converts_ConnectionError(self): |
235 | 59 | # The method converts ConnectionError to GoogleResponseError. | 59 | # The method converts ConnectionError to SiteSearchResponseError. |
236 | 60 | with urlfetch_exception(ConnectionError, 'oops'): | 60 | with urlfetch_exception(ConnectionError, 'oops'): |
237 | 61 | self.assertRaises( | 61 | self.assertRaises( |
239 | 62 | GoogleResponseError, self.search_service.search, 'fnord') | 62 | SiteSearchResponseError, self.search_service.search, 'fnord') |
240 | 63 | 63 | ||
241 | 64 | def test_search_converts_TimeoutError(self): | 64 | def test_search_converts_TimeoutError(self): |
243 | 65 | # The method converts TimeoutError to GoogleResponseError. | 65 | # The method converts TimeoutError to SiteSearchResponseError. |
244 | 66 | with urlfetch_exception(TimeoutError, 'oops'): | 66 | with urlfetch_exception(TimeoutError, 'oops'): |
245 | 67 | self.assertRaises( | 67 | self.assertRaises( |
247 | 68 | GoogleResponseError, self.search_service.search, 'fnord') | 68 | SiteSearchResponseError, self.search_service.search, 'fnord') |
248 | 69 | 69 | ||
249 | 70 | def test___parse_google_search_protocol_SyntaxError(self): | 70 | def test___parse_google_search_protocol_SyntaxError(self): |
251 | 71 | # The method converts SyntaxError to GoogleResponseError. | 71 | # The method converts SyntaxError to SiteSearchResponseError. |
252 | 72 | with urlfetch_exception(SyntaxError, 'oops'): | 72 | with urlfetch_exception(SyntaxError, 'oops'): |
253 | 73 | self.assertRaises( | 73 | self.assertRaises( |
255 | 74 | GoogleResponseError, | 74 | SiteSearchResponseError, |
256 | 75 | self.search_service._parse_google_search_protocol, '') | 75 | self.search_service._parse_google_search_protocol, '') |
257 | 76 | 76 | ||
258 | 77 | def test___parse_google_search_protocol_IndexError(self): | 77 | def test___parse_google_search_protocol_IndexError(self): |
260 | 78 | # The method converts IndexError to GoogleResponseError. | 78 | # The method converts IndexError to SiteSearchResponseError. |
261 | 79 | with urlfetch_exception(IndexError, 'oops'): | 79 | with urlfetch_exception(IndexError, 'oops'): |
262 | 80 | data = ( | 80 | data = ( |
263 | 81 | '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' | 81 | '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' |
264 | 82 | '<GSP VER="3.2"></GSP>') | 82 | '<GSP VER="3.2"></GSP>') |
265 | 83 | self.assertRaises( | 83 | self.assertRaises( |
267 | 84 | GoogleResponseError, | 84 | SiteSearchResponseError, |
268 | 85 | self.search_service._parse_google_search_protocol, data) | 85 | self.search_service._parse_google_search_protocol, data) |