Exemple #1
0
def test_hash_sum_good(capfd):
    hash_value = 'fefb677369d7894997575b0e448c40e3'
    file = 'files/file_03.txt'
    hash_actual = hashlib.new("md5", file.encode()).hexdigest()
    CheckHash('data.txt', '').check_hash(hash_value, hash_actual, file)
    captured, err = capfd.readouterr()
    assert captured == f'{file} OK\n'
Exemple #2
0
def test_path_bad(capfd):
    path = 'file_03.txt'
    f = CheckHash('data.txt', '').check_path_file(path)
    captured, err = capfd.readouterr()

    assert f == False
    assert captured == f'{path} NOT FOUND\n'
Exemple #3
0
def test_hash_type_not_support(capfd, line):
    num_line = 10
    type = line.split(' ')[1].lower()
    f = CheckHash('data.txt', '').check_hash_type(line, num_line, type)
    captured, err = capfd.readouterr()
    assert f == False
    assert captured == 'This type "test" is not supported\n'
Exemple #4
0
def test_name_file_bad(capfd, line):
    num_line = 10
    name = line.split(' ')[0]
    f = CheckHash('data.txt', '').check_name_file(line, num_line, name)
    captured, err = capfd.readouterr()

    assert f == False
    assert captured == f"File name error \n--- {line} ---\n in line {num_line}. Check the filename: {name}\n"
Exemple #5
0
def test_hash_type_bad(capfd, line):
    num_line = 10
    hash_type = ['md5', 'sha1', 'sha256', 'test']
    type = line.split(' ')[1].lower()
    f = CheckHash('data.txt', '').check_hash_type(line, num_line, type)
    captured, err = capfd.readouterr()
    assert f == False
    assert captured == f"\nInvalid encoding method: {type}\n--- {line} ---\nin line {num_line}. Available encoding: {hash_type}\n"
Exemple #6
0
def test_columns_bad(capfd, line):
    columns_in_row = 3
    id_line = 10
    separate_line = line.split(' ')
    f = CheckHash('data.txt',
                  '').validation_line_in_file(line, id_line, separate_line)
    captured, err = capfd.readouterr()

    assert f == False
    assert captured == f"Invalid string \n--- {line} ---\nin line {id_line}. Count columns must be: {columns_in_row}\n"
Exemple #7
0
def test_path_input_name_file():
    path = 'no.txt'
    assert CheckHash(path, '').create_path(path) == 'no.txt'
Exemple #8
0
def test_path_input_folder():
    path = 'folder'
    assert CheckHash(path, '').create_path(path) == 'folder/'
Exemple #9
0
def test_path_input_empty():
    path = '/'
    assert CheckHash(path, '').create_path(path) == '/'
Exemple #10
0
def test_path_input_file_slash():
    path = 'folder/no.txt'
    assert CheckHash(path, '').create_path(path) == 'folder/no.txt'
Exemple #11
0
def test_path_main_file_open():
    path = 'files/data.txt'
    CheckHash(path, '').read_file()
Exemple #12
0
def test_path_main_file_empty(capfd):
    path = 'files/empty.txt'
    with pytest.raises(SystemExit):
        CheckHash(path, '').read_file()
        captured, err = capfd.readouterr()
        assert captured == f"File {path} empty\n"
Exemple #13
0
def test_path_main_file_raises_not_found(capfd, path):
    with pytest.raises(FileNotFoundError):
        CheckHash(path, '').read_file()
        captured, err = capfd.readouterr()
        assert captured == f"File {path} not found\n"
Exemple #14
0
def test_hash_type_good(capfd, line):
    num_line = 10
    type = line.split(' ')[1].lower()
    f = CheckHash('data.txt', '').check_hash_type(line, num_line, type)
    assert f == True
Exemple #15
0
def test_name_file_good(line):
    num_line = 10
    name = line.split(' ')[0]
    f = CheckHash('data.txt', '').check_name_file(line, num_line, name)
    assert f == True
Exemple #16
0
def test_good():
    path = 'files/file_03.txt'
    assert CheckHash('files/data.txt', '').check_path_file(path) == True
Exemple #17
0
def test_empty_line():
    path = 'files/data.txt'
    assert CheckHash(path, '').read_file() == None
Exemple #18
0
def test_good(line):
    id_line = 5
    separate_line = line.split(' ')
    assert CheckHash('data.txt',
                     '').validation_line_in_file(line, id_line,
                                                 separate_line) == True