示例#1
0
def test_other_links():
    with open("tests/data/other_links.html") as data_body:
        url = "http://perdu.com/"
        responses.add(
            responses.GET,
            url,
            body=data_body.read(),
            adding_headers={
                "Location": "https://perdu.com/login"
            },
            status=301
        )

        resp = requests.get(url, allow_redirects=False)
        page = Page(resp)

        assert sorted(page.iter_frames()) == [
            "http://perdu.com/frame1.html",
            "http://perdu.com/frame2.html",
            "http://perdu.com/iframe.html"
        ]
        assert page.scripts == ["http://perdu.com/script.js"]
        assert page.redirection_url == "https://perdu.com/login"
        assert set(page.images_urls) == {
            "http://perdu.com/img/logo.png",
            "http://perdu.com/img/header.png",
            "http://perdu.com/img/ads.php?id=5878545"
        }
        assert page.js_redirections == ["http://perdu.com/maintenance.html"]
        assert page.favicon_url == "http://perdu.com/favicon.ico"
        assert page.html_redirections == ["http://perdu.com/adblock.html"]
示例#2
0
def test_base_other_links():
    with open("tests/data/base_other_links.html") as data_body:
        url = "http://perdu.com/"
        respx.get(url).mock(return_value=httpx.Response(
            301,
            text=data_body.read(),
            headers={"Location": "https://perdu.com/login"}))

        resp = httpx.get(url, follow_redirects=False)
        page = Page(resp)

        assert sorted(page.iter_frames()) == [
            "http://perdu.com/blog/frame1.html",
            "http://perdu.com/blog/frame2.html",
            "http://perdu.com/blog/iframe.html"
        ]

        assert page.scripts == ["http://perdu.com/blog/script.js"]
        assert page.redirection_url == "https://perdu.com/login"
        assert set(page.images_urls) == {"http://perdu.com/blog/img/logo.png"}

        assert page.html_redirections == ["http://perdu.com/blog/adblock.html"]
示例#3
0
def test_other_links():
    with open("tests/data/other_links.html") as data_body:
        url = "http://perdu.com/"
        respx.get(url).mock(return_value=httpx.Response(
            301,
            text=data_body.read(),
            headers={"Location": "https://perdu.com/login"}))

        resp = httpx.get(url, allow_redirects=False)
        page = Page(resp)

        assert sorted(page.iter_frames()) == [
            "http://perdu.com/frame1.html", "http://perdu.com/frame2.html",
            "http://perdu.com/iframe.html"
        ]
        assert page.scripts == ["http://perdu.com/script.js"]
        assert page.redirection_url == "https://perdu.com/login"
        assert set(page.images_urls) == {
            "http://perdu.com/img/logo.png", "http://perdu.com/img/header.png",
            "http://perdu.com/img/ads.php?id=5878545"
        }
        assert page.js_redirections == ["http://perdu.com/maintenance.html"]
        assert page.favicon_url == "http://perdu.com/favicon.ico"
        assert page.html_redirections == ["http://perdu.com/adblock.html"]