Ejemplo n.º 1
0
def test_anonymize_too_many_digits(ip, exp, test_file, capsys):
    f = test_file(ip)
    main([str(f), '--anonymize', '25'])
    with open(f) as x:
        assert x.read() == exp
    captured = capsys.readouterr()
    assert (
        '\u001b[33mWARNING: anonymize is set larger than 4. '
        'IPv4 will be rewritten to 0.0.0.0\u001b[0m\n'
    ) in captured.out
    assert (
        '\u001b[33mWARNING: anonymize is set larger than 8. '
        'IPv6 will be rewritten to 0:0:0:0:0:0:0:0\u001b[0m\n'
    ) in captured.out
Ejemplo n.º 2
0
def test_anonymize_ipv4_default(ip, exp, test_file):
    f = test_file(ip)
    main([str(f), '--anonymize'])
    with open(f) as x:
        assert x.read() == exp
Ejemplo n.º 3
0
def test_error_file_not_found():
    with pytest.raises(Exception):
        main(['not_existing_file.log'])
Ejemplo n.º 4
0
def test_specific_log_nr(tmpdir):
    f = tmpdir.join('test.log.7')
    f.write('foo,1.2.3.4,bar\n')
    main([str(f)[:-2], '--log-nr', '7'])
    with open(f) as x:
        assert x.read() == 'foo,-,bar\n'
Ejemplo n.º 5
0
def test_replace_ipv6(ip, test_file):
    f = test_file(ip)
    main([str(f)])
    with open(f) as x:
        assert x.read() == '-'
Ejemplo n.º 6
0
def test_dry_run(test_file):
    test_str = 'foo,bar,10.20.30.40,baz\n'
    f = test_file(test_str)
    main([str(f), '--dry-run'])
    with open(f) as x:
        assert x.read() == test_str
Ejemplo n.º 7
0
def test_show_version():
    with pytest.raises(SystemExit):
        main(['--version'])
Ejemplo n.º 8
0
def test_show_help():
    with pytest.raises(SystemExit):
        main(['--help'])
Ejemplo n.º 9
0
def test_anonymize_ipv6_multiple_digits(ip, exp, test_file):
    f = test_file(ip)
    main([str(f), '--anonymize', '2'])
    with open(f) as x:
        assert x.read() == exp