~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/googlesearch/tests/test_pagematch.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-23 18:43:31 UTC
  • mfrom: (13084.2.6 page-match-rewrite-url)
  • Revision ID: launchpad@pqm.canonical.com-20110523184331-dhd2c7cgfuu49epw
[r=sinzui][bug=784273] Adds facility to the PageMatch to handle bad
        URIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Test the search result PageMatch class."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
from canonical.testing.layers import DatabaseFunctionalLayer
 
9
from lp.services.googlesearch import PageMatch
 
10
from lp.testing import TestCaseWithFactory
 
11
 
 
12
 
 
13
class TestPageMatchURLHandling(TestCaseWithFactory):
 
14
 
 
15
    layer = DatabaseFunctionalLayer
 
16
 
 
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)
 
27
 
 
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')
 
35
        expected = (
 
36
            "http://launchpad.dev/+search?"
 
37
            "field.text=WUSB54GC+%2Bkarmic&"
 
38
            "field.actions.search=Search")
 
39
        self.assertEqual(expected, p.url)