Ejemplo n.º 1
0
def test_link_nl(server):
    """ browsers ignore new line in links so should do that too. """

    address = server.router({
        '^/$': Page("<a href='/li\nnk'>a</a>").exists(),
        '^/link$': Page("ok").exists(),
    })

    l = Link(address)
    l.exists()
    assert "/link" in l.links
Ejemplo n.º 2
0
def test_redirected_page(server):
    """ Should raise IgnoredURL if Ignored """
    address = server.router({
        '^/$': Page("").redirects(pattern="https://example.com/?%s"),
    })

    l = Link(address)
    assert l.status == Status.UNDEFINED
    with pytest.raises(DeadlinksRedirectionURL):
        l.exists()

    with pytest.raises(TypeError):
        l.status = 0
Ejemplo n.º 3
0
def test_ignored_page(server):
    """ Should raise IgnoredURL if Ignored """
    address = server.router({
        '^/$': Page("").exists(),
    })

    l = Link(address)
    assert l.status == Status.UNDEFINED
    l.status = Status.IGNORED
    assert l.status == Status.IGNORED
    with pytest.raises(DeadlinksIgnoredURL):
        l.exists()

    with pytest.raises(TypeError):
        l.status = 3
Ejemplo n.º 4
0
def test_existing_page(server):
    """ emulating slow server (responds after 1s) """

    address = server.router({
        '^/$': Page("").slow().exists(),
    })

    l = Link(address)
    assert l.status == Status.UNDEFINED
    assert l.exists()
    l.status = Status.FOUND
    assert l.exists()

    with pytest.raises(TypeError):
        l.status = 1
Ejemplo n.º 5
0
def test_not_available_page():
    """ ok server, but ip with error """

    l = Link("http://127.0.0.1:79")
    assert l.status == Status.UNDEFINED
    assert not l.exists()
    assert "Failed to establish a new connection" in l.message
Ejemplo n.º 6
0
def test_same_url(server):
    page = "<a href='http://{}:{}'>same link</a>, <a href='/'>a</a>"
    address = server.router({
        '^/$': Page(page.format(*server.sa)).exists(),
        '^/link$': Page("ok").exists(),
    })
    l = Link(address)
    assert l.exists()
    assert address in l.links
Ejemplo n.º 7
0
def test_not_existing_page(server):
    """ emulating slow broken server """

    address = server.router({
        '^/$': Page("").unlock_after(3).slow().exists(),
    })

    l = Link(address)
    assert l.status == Status.UNDEFINED

    # timed out
    assert not l.exists(retries=2)
    # setting new status
    l.status = Status.NOT_FOUND

    # page is unlocked, but response is cached!
    assert not l.exists()

    with pytest.raises(TypeError):
        l.status = 2
Ejemplo n.º 8
0
def test_links(server):
    """ General testing for link. """

    url = server.router({
        '^/$': Page('<a href="https://example.com/">test</a>').exists(),
    })

    l = Link(url)

    assert l.exists()
    assert len(l.links) == 1
    assert str(l) == url
    assert l.url() == url