From 3645504d353e469eb956480b0a54e0e9ddda22a9 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Tue, 1 Aug 2023 14:30:22 -0400 Subject: [PATCH] Full coverage identity unit tests Wrote some during a demo with Peter and co, and finished the last couple after. --- tests/sarracenia/identity/_identity_test.py | 42 ++++++++++++++++++ tests/sarracenia/identity/arbitrary_test.py | 47 +++++++++++++++++++++ tests/sarracenia/identity/md5_test.py | 36 ++++++++++++++++ tests/sarracenia/identity/random_test.py | 5 +-- tests/sarracenia/identity/sha512_test.py | 3 -- 5 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 tests/sarracenia/identity/_identity_test.py create mode 100644 tests/sarracenia/identity/arbitrary_test.py create mode 100644 tests/sarracenia/identity/md5_test.py diff --git a/tests/sarracenia/identity/_identity_test.py b/tests/sarracenia/identity/_identity_test.py new file mode 100644 index 000000000..596ec2007 --- /dev/null +++ b/tests/sarracenia/identity/_identity_test.py @@ -0,0 +1,42 @@ +import pytest +import os +#from unittest.mock import Mock + +import logging + +import sarracenia +import sarracenia.identity + +#useful for debugging tests +import pprint +pretty = pprint.PrettyPrinter(indent=2, width=200).pprint + + +def test_factory(): + identity = sarracenia.identity.Identity().factory('foobar') + assert identity == None + + identity = sarracenia.identity.Identity().factory() + assert identity.registered_as() == 's' + +def test_get_method(): + identity = sarracenia.identity.Identity().factory() + assert identity.get_method() == 'sha512' + + +def test_update_file(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + open(path1, 'a').write('randomstring') + identity = sarracenia.identity.Identity().factory() + identity.update_file(path1) + + assert identity.filehash.name == "sha512" + +@pytest.mark.depends(on=['test_update_file']) +def test___Property_value(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + open(path1, 'a').write('randomstring') + identity = sarracenia.identity.Identity().factory() + identity.update_file(path1) + + assert identity.value == 'kkUPxxKfR72my8noS5yekWcdFnmIJSvDJIvtSF7uTyvnhtm0saERCXReIcNDAk2B7gET3o+tQY3gTbd36ynoDA==' \ No newline at end of file diff --git a/tests/sarracenia/identity/arbitrary_test.py b/tests/sarracenia/identity/arbitrary_test.py new file mode 100644 index 000000000..3cc00b8ed --- /dev/null +++ b/tests/sarracenia/identity/arbitrary_test.py @@ -0,0 +1,47 @@ +import pytest +import os +#from unittest.mock import Mock + +import logging + +import sarracenia +import sarracenia.identity.arbitrary + +#useful for debugging tests +import pprint +pretty = pprint.PrettyPrinter(indent=2, width=200).pprint + + +def test___init__(): + hash = sarracenia.identity.arbitrary.Arbitrary() + assert hash._value == 'None' + + +def test_registered_as(): + # Set 1 + hash = sarracenia.identity.arbitrary.Arbitrary() + assert hash.registered_as() == 'a' + +def test_set_path(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + hash = sarracenia.identity.arbitrary.Arbitrary() + hash.set_path(path1) + assert True + + +def test_update(): + hash = sarracenia.identity.arbitrary.Arbitrary() + hash.update('randomstring') + assert True + +@pytest.mark.depends() +def test___Property_value(): + sarracenia.identity.arbitrary.set_default_value('default') + + hash = sarracenia.identity.arbitrary.Arbitrary() + assert hash.value == 'default' + + # test the setter + hash.value = 'new' + assert hash.value == 'new' + diff --git a/tests/sarracenia/identity/md5_test.py b/tests/sarracenia/identity/md5_test.py new file mode 100644 index 000000000..a8254fe8a --- /dev/null +++ b/tests/sarracenia/identity/md5_test.py @@ -0,0 +1,36 @@ +import pytest +import os +#from unittest.mock import Mock + +import logging + +import sarracenia +import sarracenia.identity.md5 + +#useful for debugging tests +import pprint +pretty = pprint.PrettyPrinter(indent=2, width=200).pprint + + +def test_registered_as(): + # Set 1 + hash = sarracenia.identity.md5.Md5() + assert hash.registered_as() == 'd' + +def test_set_path(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + hash = sarracenia.identity.md5.Md5() + hash.set_path(path1) + assert hash.filehash.name == "md5" + +@pytest.mark.depends(on=['test_set_path']) +def test_update(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + # Set 1 + hash = sarracenia.identity.md5.Md5() + hash.set_path(path1) + hash.update('randomstring') + assert hash.value == 'tpDC1B4RAL5h8WAs1C1OFg==' + hash.update(b'randombytes') + assert hash.value == '+sILUpRAJFq9hB7p8kx1xA==' + diff --git a/tests/sarracenia/identity/random_test.py b/tests/sarracenia/identity/random_test.py index fbf6faa42..d5afce50f 100644 --- a/tests/sarracenia/identity/random_test.py +++ b/tests/sarracenia/identity/random_test.py @@ -12,9 +12,6 @@ pretty = pprint.PrettyPrinter(indent=2, width=200).pprint -logger = logging.getLogger('sarracenia') -logger.setLevel('DEBUG') - def test_registered_as(): hash = sarracenia.identity.random.Random() assert hash.registered_as() == '0' @@ -26,7 +23,7 @@ def test_set_path(tmp_path): assert True @pytest.mark.depends(on=['test_set_path']) -def test_prop__value(tmp_path, mocker): +def test___Property_value(tmp_path, mocker): path1 = str(tmp_path) + os.sep + "file1.txt" hash = sarracenia.identity.random.Random() hash.set_path(path1) diff --git a/tests/sarracenia/identity/sha512_test.py b/tests/sarracenia/identity/sha512_test.py index ebf5cd87c..7c602a1c1 100644 --- a/tests/sarracenia/identity/sha512_test.py +++ b/tests/sarracenia/identity/sha512_test.py @@ -12,9 +12,6 @@ pretty = pprint.PrettyPrinter(indent=2, width=200).pprint -logger = logging.getLogger('sarracenia') -logger.setLevel('DEBUG') - def test_registered_as(): # Set 1 hash = sarracenia.identity.sha512.Sha512()