1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test the search result PageMatch class."""
8
from canonical.testing.layers import DatabaseFunctionalLayer
9
from lp.services.googlesearch import PageMatch
10
from lp.testing import TestCaseWithFactory
13
class TestPageMatchURLHandling(TestCaseWithFactory):
15
layer = DatabaseFunctionalLayer
17
def test_rewrite_url_handles_invalid_data(self):
18
# Given a bad url, pagematch can get a valid one.
19
bad_url = ("http://launchpad.dev/+search?"
20
"field.text=WUSB54GC+ karmic&"
21
"field.actions.search=Search")
22
p = PageMatch('Bad,', bad_url, 'Bad data')
23
expected = ("http://launchpad.dev/+search?"
24
"field.text=WUSB54GC++karmic&"
25
"field.actions.search=Search")
26
self.assertEqual(expected, p.url)
28
def test_rewrite_url_handles_invalid_data_partial_escaped(self):
29
# Given a url with partial escaped values, pagematch does not error.
30
partial_encoded_url = (
31
"http://launchpad.dev/+search?"
32
"field.text=WUSB54GC+%2Bkarmic&"
33
"field.actions.search=Search")
34
p = PageMatch('Weird.', partial_encoded_url, 'Weird data')
36
"http://launchpad.dev/+search?"
37
"field.text=WUSB54GC+%2Bkarmic&"
38
"field.actions.search=Search")
39
self.assertEqual(expected, p.url)