def test_import_from_url_with_force(tmpdir): """ Test that a bare import from URL does replace names in existing entry """ hosts_file = tmpdir.mkdir("etc").join("hosts") hosts_file.write("1.2.3.4\texample1.com example2.com example3.com\n") hosts = Hosts(path=hosts_file.strpath) import_url = "https://raw.githubusercontent.com/jonhadfield/python-hosts/devel/test_files/hosts_win3" hosts.import_url(url=import_url, force=True) assert not hosts.exists(names=['example3.com'])
def test_import_from_url_without_force(tmpdir): """ Test that a bare import from URL does not replace names in existing entry """ hosts_file = tmpdir.mkdir("etc").join("hosts") hosts_file.write("1.2.3.4\texample1.com example2.com example3.com\n") hosts = Hosts(path=hosts_file.strpath) import_url = "https://raw.githubusercontent.com/jonhadfield/python-hosts/devel/test_files/hosts_win3" hosts.import_url(url=import_url) assert hosts.exists(names=['example3.com'])
def test_import_from_url_with_force(tmpdir): """ Test that a bare import from URL does replace names in existing entry """ hosts_file = tmpdir.mkdir("etc").join("hosts") hosts_file.write("1.2.3.4\texample1.com example2.com example3.com\n") hosts = Hosts(path=hosts_file.strpath) import_url = "https://dl.dropboxusercontent.com/u/167103/hosts_win3" hosts.import_url(url=import_url, force=True) assert not hosts.exists(names=['example3.com'])
def test_import_from_url_counters_for_part_success(tmpdir): """ Test that correct counters are returned when there is at least a single successful imported host entry There will be a single entry written before import. Importing file will include three valid IPV4 entries and an invalid entry. One of the three valid import lines will include a duplicate set of names. """ hosts_file = tmpdir.mkdir("etc").join("hosts") hosts_file.write("6.6.6.6\texample.com\n") hosts = Hosts(path=hosts_file.strpath) import_url = "https://raw.githubusercontent.com/jonhadfield/python-hosts/devel/test_files/hosts" result = hosts.import_url(url=import_url) add_result = result.get('add_result') write_result = result.get('write_result') assert add_result.get('ipv4_count') == 4 assert write_result.get('total_written') == 5
def test_import_from_url(tmpdir): """ Test that correct counters values are returned when a text file of host entries is imported via url Existing host file has: 1 entry URL has: 24 entries with 1 duplicate Add should return 23 ipv4 (to add) and 1 duplicate Write will write new 23 plus existing 1 (23 + 1 = 24) """ hosts_file = tmpdir.mkdir("etc").join("hosts") hosts_file.write("6.6.6.6\texample.com\n") hosts = Hosts(path=hosts_file.strpath) import_url = "https://raw.githubusercontent.com/jonhadfield/python-hosts/devel/test_files/hosts_win" import_url_result = hosts.import_url(url=import_url) import_url_add_result = import_url_result.get('add_result') import_url_write_result = import_url_result.get('write_result') assert not import_url_result == 'failed' assert import_url_add_result.get('ipv4_count') == 24 assert import_url_write_result.get('ipv4_entries_written') == 25 assert import_url_write_result.get('total_written') == 25