These are tests of relocateresponse::

    >>> from deliverance.relocateresponse import *

In all these examples we'll be using ``http://old`` for the old
(to-be-replaced) URL and ``https://new`` for the new URL (note the
scheme change).  Out of laziness we'll define some keywords we use
with all these transformations::

    >>> kw = dict(base_href='http://old/base/path.html',
    ...           old_href='http://old/',
    ...           new_href='https://new/')

Now lets look at simple href rewriting.

Normal rewrite::

    >>> relocate_href('http://old/bar', **kw)
    'https://new/bar'

Note that the trailing doesn't matter in this one case (since
``http://old`` and ``http://old/`` are entirely equivalent)::

    >>> relocate_href('http://old', **kw)
    'https://new/'

It does in other cases::

    >>> relocate_href('http://old-test/foo',
    ...               base_href='',
    ...               old_href='http://old-test/foo/',
    ...               new_href='https://new')
    'http://old-test/foo'
    >>> relocate_href('http://old-test/foo/',
    ...               base_href='',
    ...               old_href='http://old-test/foo/',
    ...               new_href='https://new')
    'https://new'

Rewriting a link that doesn't match old_href is a no-op::

    >>> relocate_href('http://foo/bar', **kw)
    'http://foo/bar'

Relative links are handled::

    >>> relocate_href('index.html', **kw)
    'https://new/base/index.html'

Now we look at header rewriting.  Note that Location and Set-Cookie is
rewritten, but other headers are not::

    >>> relocate_headers(
    ...     [('X-Unknown', 'http://old'),
    ...      ('Location', 'http://old/foo/bar'),
    ...      ('Set-Cookie', 'foo=bar; domain=old')],
    ...     **kw)
    [('X-Unknown', 'http://old'), ('Location', 'https://new/foo/bar'), ('Set-Cookie', 'foo=bar; domain=new')]

We'll even rewrite wildcard domains, though that might not be a good
idea::

    >>> relocate_headers(
    ...     [('Set-Cookie', 'foo=bar; domain=*.old')],
    ...     **kw)
    [('Set-Cookie', 'foo=bar; domain=*.new')]

But the location header won't be rewritten if it points to a
third-party site::

    >>> relocate_headers([('Location', 'http://foo/bar')],
    ...                  **kw)
    [('Location', 'http://foo/bar')]

Now for content.  First, to make it easier on us, we need to trim the
normalized HTML we get from these functions::

    >>> import re
    >>> def pr_html(html):
    ...     html = re.sub(r'</?(?:html|head|body)>', '', html)
    ...     html = re.sub(r'<meta.*?>', '', html)
    ...     print html.strip()

Some basics::

    >>> pr_html(relocate_content(
    ...     '<a href="http://old/blah/blah.html">link</a>', **kw))
    <a href="https://new/blah/blah.html">link</a>
    >>> pr_html(relocate_content(
    ...     '<script src="http://old/foo.js"></script>', **kw))
    <script src="https://new/foo.js"></script>
    >>> pr_html(relocate_content(
    ...     '<link href="foo.css">', **kw))
    <link href="https://new/base/foo.css">
    >>> pr_html(relocate_content('''\
    ... <base href="http://blah/stuff/index.html">
    ... <link href="foo.css">
    ... <a href="http://old/bar.html">x</a>\
    ... ''', **kw))
    <link href="http://blah/stuff/foo.css">
    <a href="https://new/bar.html">x</a>
