コード例 #1
0
ファイル: test_hostman.py プロジェクト: jonhadfield/hostman
def test_add_new_ipv4_host(tmpdir):
    """
    Test successful addition of an ipv4 host
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("127.0.0.1\tlocalhost\n")
    new_entry = '3.4.5.6 bob jane.com'
    output = add(entry_line=new_entry, hosts_path=hosts_file.strpath, force_add=False)
    assert output.get('result') == 'success'
コード例 #2
0
ファイル: test_hostman.py プロジェクト: jonhadfield/hostman
def test_add_add_duplicate_ipv4_host_with_force(tmpdir):
    """
    Test that an ipv4 type host is replaced with force set
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("3.4.5.6\tlocalhost\n")
    new_entry = '3.4.5.6 bob jane.com'
    output = add(entry_line=new_entry, hosts_path=hosts_file.strpath, force_add=True)
    assert output.get('result') == 'success'
    assert output.get('message').startswith('Entry added. Matching entries replaced.')
コード例 #3
0
def test_add_new_ipv4_host(tmpdir):
    """
    Test successful addition of an ipv4 host
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("127.0.0.1\tlocalhost\n")
    new_entry = '3.4.5.6 bob jane.com'
    output = add(entry_line=new_entry,
                 hosts_path=hosts_file.strpath,
                 force_add=False)
    assert output.get('result') == 'success'
コード例 #4
0
ファイル: test_hostman.py プロジェクト: jonhadfield/hostman
def test_add_duplicate_ipv4_host_without_force(tmpdir):
    """
    Test that nothing is added when attempt to replace a similar
    entry without using force option
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("9.9.9.9\tgeorge\n")
    new_entry = '9.9.9.9 george bungle.com'
    output = add(entry_line=new_entry, hosts_path=hosts_file.strpath, force_add=False)
    assert output.get('result') == 'failed'
    assert output.get('message').startswith('New entry matches')
コード例 #5
0
def test_add_duplicate_ipv4_host_without_force(tmpdir):
    """
    Test that nothing is added when attempt to replace a similar
    entry without using force option
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("9.9.9.9\tgeorge\n")
    new_entry = '9.9.9.9 george bungle.com'
    output = add(entry_line=new_entry,
                 hosts_path=hosts_file.strpath,
                 force_add=False)
    assert output.get('result') == 'failed'
    assert output.get('message').startswith('New entry matches')
コード例 #6
0
def test_add_add_duplicate_ipv4_host_with_force(tmpdir):
    """
    Test that an ipv4 type host is replaced with force set
    """
    hosts_file = tmpdir.mkdir("etc").join("hosts")
    hosts_file.write("3.4.5.6\tlocalhost\n")
    new_entry = '3.4.5.6 bob jane.com'
    output = add(entry_line=new_entry,
                 hosts_path=hosts_file.strpath,
                 force_add=True)
    assert output.get('result') == 'success'
    assert output.get('message').startswith(
        'Entry added. Matching entries replaced.')
コード例 #7
0
def test_failure_with_invalid_host_entry():
    with pytest.raises(SystemExit) as cm:
        add(entry_line='256.255.255.255 badaddr.com')
    assert cm.value.code == 1
コード例 #8
0
ファイル: test_hostman.py プロジェクト: jonhadfield/hostman
def test_failure_with_invalid_host_entry():
    with pytest.raises(SystemExit) as cm:
        add(entry_line='256.255.255.255 badaddr.com')
    assert cm.value.code == 1