コード例 #1
0
def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app,
                                     status, warning):
    intersphinx_setup(app)
    _read_from_url(
    ).readline.return_value = '# Sphinx inventory version 2'.encode()

    # same uri and inv, not redirected
    _read_from_url().url = 'http://hostname/' + INVENTORY_FILENAME
    fetch_inventory(app, 'http://hostname/',
                    'http://hostname/' + INVENTORY_FILENAME)
    assert 'intersphinx inventory has moved' not in status.getvalue()
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'

    # same uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/',
                    'http://hostname/' + INVENTORY_FILENAME)
    assert status.getvalue() == (
        'intersphinx inventory has moved: '
        'http://hostname/%s -> http://hostname/new/%s\n' %
        (INVENTORY_FILENAME, INVENTORY_FILENAME))
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/new'

    # different uri and inv, not redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/',
                    'http://hostname/new/' + INVENTORY_FILENAME)
    assert 'intersphinx inventory has moved' not in status.getvalue()
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'

    # different uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/other/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/',
                    'http://hostname/new/' + INVENTORY_FILENAME)
    assert status.getvalue() == (
        'intersphinx inventory has moved: '
        'http://hostname/new/%s -> http://hostname/other/%s\n' %
        (INVENTORY_FILENAME, INVENTORY_FILENAME))
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
コード例 #2
0
def test_fetch_inventory_redirection(app, status, warning, _read_from_url, read_inventory):
    intersphinx_setup(app)
    _read_from_url().readline.return_value = "# Sphinx inventory version 2".encode("utf-8")

    # same uri and inv, not redirected
    _read_from_url().url = "http://hostname/" + INVENTORY_FILENAME
    fetch_inventory(app, "http://hostname/", "http://hostname/" + INVENTORY_FILENAME)
    assert "intersphinx inventory has moved" not in status.getvalue()
    assert read_inventory.call_args[0][1] == "http://hostname/"

    # same uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = "http://hostname/new/" + INVENTORY_FILENAME

    fetch_inventory(app, "http://hostname/", "http://hostname/" + INVENTORY_FILENAME)
    assert status.getvalue() == (
        "intersphinx inventory has moved: "
        "http://hostname/%s -> http://hostname/new/%s\n" % (INVENTORY_FILENAME, INVENTORY_FILENAME)
    )
    assert read_inventory.call_args[0][1] == "http://hostname/new"

    # different uri and inv, not redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = "http://hostname/new/" + INVENTORY_FILENAME

    fetch_inventory(app, "http://hostname/", "http://hostname/new/" + INVENTORY_FILENAME)
    assert "intersphinx inventory has moved" not in status.getvalue()
    assert read_inventory.call_args[0][1] == "http://hostname/"

    # different uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = "http://hostname/other/" + INVENTORY_FILENAME

    fetch_inventory(app, "http://hostname/", "http://hostname/new/" + INVENTORY_FILENAME)
    assert status.getvalue() == (
        "intersphinx inventory has moved: "
        "http://hostname/new/%s -> http://hostname/other/%s\n" % (INVENTORY_FILENAME, INVENTORY_FILENAME)
    )
    assert read_inventory.call_args[0][1] == "http://hostname/"
コード例 #3
0
def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status, warning):
    intersphinx_setup(app)
    _read_from_url().readline.return_value = '# Sphinx inventory version 2'.encode('utf-8')

    # same uri and inv, not redirected
    _read_from_url().url = 'http://hostname/' + INVENTORY_FILENAME
    fetch_inventory(app, 'http://hostname/', 'http://hostname/' + INVENTORY_FILENAME)
    assert 'intersphinx inventory has moved' not in status.getvalue()
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'

    # same uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/', 'http://hostname/' + INVENTORY_FILENAME)
    assert status.getvalue() == ('intersphinx inventory has moved: '
                                 'http://hostname/%s -> http://hostname/new/%s\n' %
                                 (INVENTORY_FILENAME, INVENTORY_FILENAME))
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/new'

    # different uri and inv, not redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/', 'http://hostname/new/' + INVENTORY_FILENAME)
    assert 'intersphinx inventory has moved' not in status.getvalue()
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'

    # different uri and inv, redirected
    status.seek(0)
    status.truncate(0)
    _read_from_url().url = 'http://hostname/other/' + INVENTORY_FILENAME

    fetch_inventory(app, 'http://hostname/', 'http://hostname/new/' + INVENTORY_FILENAME)
    assert status.getvalue() == ('intersphinx inventory has moved: '
                                 'http://hostname/new/%s -> http://hostname/other/%s\n' %
                                 (INVENTORY_FILENAME, INVENTORY_FILENAME))
    assert InventoryFile.load.call_args[0][1] == 'http://hostname/'