<reponame>PinataMostGrim/hashutil
"""
- Test hashes generated using https://www.pelock.com/products/hash-calculator
- Test hashes for Blake2 generated by hashlib
"""

import pytest
import hashutil.core as core

from pathlib import Path


_TEST_STRING = 'test string'
_TEST_FILE = 'test_file'
_TEST_FILE_CONTENTS = 'test file contents'


# Helper methods
def get_test_file_path():
    return Path(__file__).parent / _TEST_FILE


def create_test_file():
    file1 = get_test_file_path()
    file1.write_text(_TEST_FILE_CONTENTS)


def delete_test_file():
    file = get_test_file_path()
    if file.exists():
        file.unlink()


# Fixtures
@pytest.fixture
def fixture_test_file():
    create_test_file()
    yield 'fixture_test_file'
    delete_test_file()


# Tests
def test_get_available_algorithms():
    available_algorithms = [
        'blake2b',
        'blake2s',
        'md5',
        'sha1',
        'sha224',
        'sha256',
        'sha384',
        'sha3_224',
        'sha3_256',
        'sha3_384',
        'sha3_512',
        'sha512',
    ]
    assert available_algorithms == core.get_available_algorithms()


def test_hash_string_blake2b():

    hash = core.get_string_hash(_TEST_STRING, 'blake2b')
    assert (
        hash
        == '5709d01ec434335daae198ad06158a9d51be5026c166e6935ca2cb924e7341ff2e5b0671c378325bfee70e503082df5b55ef0b0e9ea4c27e7f776b2e8c6ac179'
    )


def test_hash_string_blake2s():

    hash = core.get_string_hash(_TEST_STRING, 'blake2s')
    assert hash == '7f38f448a819f8bedd8712ef459a9fe83be9ea9368ee3f350f197590becea37e'


def test_hash_string_md5():

    hash = core.get_string_hash(_TEST_STRING, 'md5')
    assert hash == '6f8db599de986fab7a21625b7916589c'


def test_hash_string_sha1():

    hash = core.get_string_hash(_TEST_STRING, 'sha1')
    assert hash == '661295c9cbf9d6b2f6428414504a8deed3020641'


def test_hash_string_sha224():

    hash = core.get_string_hash(_TEST_STRING, 'sha224')
    assert hash == 'dd8a1f5793f157323ccb28fe953bb8abb659bd61b7e9fae10be26f7a'


def test_hash_string_sha256():

    hash = core.get_string_hash(_TEST_STRING, 'sha256')
    assert hash == 'd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b'


def test_hash_string_sha384():

    hash = core.get_string_hash(_TEST_STRING, 'sha384')
    assert (
        hash
        == 'e213dccb3221e0b8fdd995dcc1d04e218fc649981038bfac81abc98932369bac0efb758b92eccd80321df8eb64efae87'
    )


def test_hash_string_sha3_224():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_224')
    assert hash == '1425c038d444826ae20daf2278029db10db8452f816c575282366805'


def test_hash_string_sha3_256():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_256')
    assert hash == '77e9f353431833c316bd41dc88670d9ad21d2e5950d6f5e2346f2e8859f4fc9b'


def test_hash_string_sha3_384():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_384')
    assert (
        hash
        == 'd31c6a449362712e691534004552c29ce9ce946be8b94fb2fa8dcef52d861d607fd09b804d0cbf9604e4b7c8db2fb73c'
    )


def test_hash_string_sha3_512():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_512')
    assert (
        hash
        == 'f6ae3079ef6c5deacb44e03bf7a5d220fac38351279a79da22fa7331fcd39141f4807a121327910f21ad666660a0a327842ffca6c91f221e413c9cc246ea8d92'
    )


def test_hash_string_512():

    hash = core.get_string_hash(_TEST_STRING, 'sha512')
    assert (
        hash
        == '10e6d647af44624442f388c2c14a787ff8b17e6165b83d767ec047768d8cbcb71a1a3226e7cc7816bc79c0427d94a9da688c41a3992c7bf5e4d7cc3e0be5dbac'
    )


def test_hash_file_blake2b(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'blake2b')
    assert (
        hash
        == 'e867d368cdff9eac88085b7f8286af42743a1f3774b3815101493cba4731408157563b178d565a57fe18deddba102171e9c40e9e2e2f786780fa4367d06f277a'
    )


def test_hash_file_blake2s(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'blake2s')
    assert hash == '2fa4dfad632d7421c85bc1f6b414cf4dd96650954f6b285325ad5e386034f468'


def test_hash_file_md5(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'md5')
    assert hash == '891bcd3700619af5151bf95b836ff9b1'


def test_hash_file_sha1(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha1')
    assert hash == 'cbaedccfded0c768295aae27c8e5b3a0025ef340'


def test_hash_file_sha224(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha224')
    assert hash == 'd07d8afe2d2b60e25dbe7a99427ddfa53cd9b34f9065bdbf5382cb6b'


def test_hash_file_sha256(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha256')
    assert hash == 'c4fa968a745586faaa030054f51fb1cafd5e9ae25fa6b137ac6477715fdc81b1'


def test_hash_file_sha384(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha384')
    assert (
        hash
        == '516493a2791e0bf2602511ba546567185f26295c0f048483ce5ec73f616834a7b5523d3fa6bdef7a039fe32b8fe515b9'
    )


def test_hash_file_sha3_224(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_224')
    assert hash == '99c6b717b9b3c9545f4478f58b401ccc8f1cf4d8ba90864c07dce587'


def test_hash_file_sha3_256(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_256')
    assert hash == 'd631d36b8deb8d436738601cc459180d27b4d43aeb229d5260278e78e7e25502'


def test_hash_file_sha3_384(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_384')
    assert (
        hash
        == 'd33d0222a9881dc030bc04c1e9dd24a61013e9cabba86cd9222addad6173c1d14d6c4b013a52b815daf70d728413cca7'
    )


def test_hash_file_sha3_512(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_512')
    assert (
        hash
        == 'e1f841504b679806bd07ba1a1d4844dcf1abc854280400d9b16ddde4e145a51c1e072f581428ac17381d791695ff8f519250857dc2ce45e14ba872c1e9f04e72'
    )


def test_hash_file_sha512(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha512')
    assert (
        hash
        == 'f2bb7acec79f2ce98adb0968dc9d41d344135463a486221dc8302684d7138455f72c94040d4096327e2d9f14f31c4db1b9044173572dfc5c1f03c8066adc44ff'
    )

"""
- Test hashes generated using https://www.pelock.com/products/hash-calculator
- Test hashes for Blake2 generated by hashlib
"""

import pytest
import hashutil.core as core

from pathlib import Path


_TEST_STRING = 'test string'
_TEST_FILE = 'test_file'
_TEST_FILE_CONTENTS = 'test file contents'


# Helper methods
def get_test_file_path():
    return Path(__file__).parent / _TEST_FILE


def create_test_file():
    file1 = get_test_file_path()
    file1.write_text(_TEST_FILE_CONTENTS)


def delete_test_file():
    file = get_test_file_path()
    if file.exists():
        file.unlink()


# Fixtures
@pytest.fixture
def fixture_test_file():
    create_test_file()
    yield 'fixture_test_file'
    delete_test_file()


# Tests
def test_get_available_algorithms():
    available_algorithms = [
        'blake2b',
        'blake2s',
        'md5',
        'sha1',
        'sha224',
        'sha256',
        'sha384',
        'sha3_224',
        'sha3_256',
        'sha3_384',
        'sha3_512',
        'sha512',
    ]
    assert available_algorithms == core.get_available_algorithms()


def test_hash_string_blake2b():

    hash = core.get_string_hash(_TEST_STRING, 'blake2b')
    assert (
        hash
        == '5709d01ec434335daae198ad06158a9d51be5026c166e6935ca2cb924e7341ff2e5b0671c378325bfee70e503082df5b55ef0b0e9ea4c27e7f776b2e8c6ac179'
    )


def test_hash_string_blake2s():

    hash = core.get_string_hash(_TEST_STRING, 'blake2s')
    assert hash == '7f38f448a819f8bedd8712ef459a9fe83be9ea9368ee3f350f197590becea37e'


def test_hash_string_md5():

    hash = core.get_string_hash(_TEST_STRING, 'md5')
    assert hash == '6f8db599de986fab7a21625b7916589c'


def test_hash_string_sha1():

    hash = core.get_string_hash(_TEST_STRING, 'sha1')
    assert hash == '661295c9cbf9d6b2f6428414504a8deed3020641'


def test_hash_string_sha224():

    hash = core.get_string_hash(_TEST_STRING, 'sha224')
    assert hash == 'dd8a1f5793f157323ccb28fe953bb8abb659bd61b7e9fae10be26f7a'


def test_hash_string_sha256():

    hash = core.get_string_hash(_TEST_STRING, 'sha256')
    assert hash == 'd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b'


def test_hash_string_sha384():

    hash = core.get_string_hash(_TEST_STRING, 'sha384')
    assert (
        hash
        == 'e213dccb3221e0b8fdd995dcc1d04e218fc649981038bfac81abc98932369bac0efb758b92eccd80321df8eb64efae87'
    )


def test_hash_string_sha3_224():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_224')
    assert hash == '1425c038d444826ae20daf2278029db10db8452f816c575282366805'


def test_hash_string_sha3_256():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_256')
    assert hash == '77e9f353431833c316bd41dc88670d9ad21d2e5950d6f5e2346f2e8859f4fc9b'


def test_hash_string_sha3_384():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_384')
    assert (
        hash
        == 'd31c6a449362712e691534004552c29ce9ce946be8b94fb2fa8dcef52d861d607fd09b804d0cbf9604e4b7c8db2fb73c'
    )


def test_hash_string_sha3_512():

    hash = core.get_string_hash(_TEST_STRING, 'sha3_512')
    assert (
        hash
        == 'f6ae3079ef6c5deacb44e03bf7a5d220fac38351279a79da22fa7331fcd39141f4807a121327910f21ad666660a0a327842ffca6c91f221e413c9cc246ea8d92'
    )


def test_hash_string_512():

    hash = core.get_string_hash(_TEST_STRING, 'sha512')
    assert (
        hash
        == '10e6d647af44624442f388c2c14a787ff8b17e6165b83d767ec047768d8cbcb71a1a3226e7cc7816bc79c0427d94a9da688c41a3992c7bf5e4d7cc3e0be5dbac'
    )


def test_hash_file_blake2b(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'blake2b')
    assert (
        hash
        == 'e867d368cdff9eac88085b7f8286af42743a1f3774b3815101493cba4731408157563b178d565a57fe18deddba102171e9c40e9e2e2f786780fa4367d06f277a'
    )


def test_hash_file_blake2s(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'blake2s')
    assert hash == '2fa4dfad632d7421c85bc1f6b414cf4dd96650954f6b285325ad5e386034f468'


def test_hash_file_md5(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'md5')
    assert hash == '891bcd3700619af5151bf95b836ff9b1'


def test_hash_file_sha1(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha1')
    assert hash == 'cbaedccfded0c768295aae27c8e5b3a0025ef340'


def test_hash_file_sha224(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha224')
    assert hash == 'd07d8afe2d2b60e25dbe7a99427ddfa53cd9b34f9065bdbf5382cb6b'


def test_hash_file_sha256(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha256')
    assert hash == 'c4fa968a745586faaa030054f51fb1cafd5e9ae25fa6b137ac6477715fdc81b1'


def test_hash_file_sha384(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha384')
    assert (
        hash
        == '516493a2791e0bf2602511ba546567185f26295c0f048483ce5ec73f616834a7b5523d3fa6bdef7a039fe32b8fe515b9'
    )


def test_hash_file_sha3_224(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_224')
    assert hash == '99c6b717b9b3c9545f4478f58b401ccc8f1cf4d8ba90864c07dce587'


def test_hash_file_sha3_256(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_256')
    assert hash == 'd631d36b8deb8d436738601cc459180d27b4d43aeb229d5260278e78e7e25502'


def test_hash_file_sha3_384(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_384')
    assert (
        hash
        == 'd33d0222a9881dc030bc04c1e9dd24a61013e9cabba86cd9222addad6173c1d14d6c4b013a52b815daf70d728413cca7'
    )


def test_hash_file_sha3_512(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha3_512')
    assert (
        hash
        == 'e1f841504b679806bd07ba1a1d4844dcf1abc854280400d9b16ddde4e145a51c1e072f581428ac17381d791695ff8f519250857dc2ce45e14ba872c1e9f04e72'
    )


def test_hash_file_sha512(fixture_test_file):

    hash = core.get_file_hash(get_test_file_path(), 'sha512')
    assert (
        hash
        == 'f2bb7acec79f2ce98adb0968dc9d41d344135463a486221dc8302684d7138455f72c94040d4096327e2d9f14f31c4db1b9044173572dfc5c1f03c8066adc44ff'
    )
- Test hashes generated using https://www.pelock.com/products/hash-calculator - Test hashes for Blake2 generated by hashlib # Helper methods # Fixtures # Tests