diff --git a/tests/sarracenia/__init___test.py b/tests/sarracenia/__init___test.py index 1f9ec63f5..fa5aeafb8 100644 --- a/tests/sarracenia/__init___test.py +++ b/tests/sarracenia/__init___test.py @@ -363,7 +363,6 @@ def test_updatePaths(self, tmp_path, mocker): assert msg['new_file'] == new_file #Test set 2 - pretty(options.post_format) options = sarracenia.config.default_config() options.post_baseUrl = 'https://post_baseurl.com' options.fixed_headers = {'fixed_headers__Key1': 'fixed_headers__Val1'} 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 new file mode 100644 index 000000000..d5afce50f --- /dev/null +++ b/tests/sarracenia/identity/random_test.py @@ -0,0 +1,32 @@ +import pytest +import os +#from unittest.mock import Mock + +import logging + +import sarracenia +import sarracenia.identity.random + +#useful for debugging tests +import pprint +pretty = pprint.PrettyPrinter(indent=2, width=200).pprint + + +def test_registered_as(): + hash = sarracenia.identity.random.Random() + assert hash.registered_as() == '0' + +def test_set_path(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + hash = sarracenia.identity.random.Random() + hash.set_path(path1) + assert True + +@pytest.mark.depends(on=['test_set_path']) +def test___Property_value(tmp_path, mocker): + path1 = str(tmp_path) + os.sep + "file1.txt" + hash = sarracenia.identity.random.Random() + hash.set_path(path1) + mocker.patch('random.randint', return_value=1000) + assert hash.value == '1000' + diff --git a/tests/sarracenia/identity/sha512_test.py b/tests/sarracenia/identity/sha512_test.py new file mode 100644 index 000000000..7c602a1c1 --- /dev/null +++ b/tests/sarracenia/identity/sha512_test.py @@ -0,0 +1,36 @@ +import pytest +import os +#from unittest.mock import Mock + +import logging + +import sarracenia +import sarracenia.identity.sha512 + +#useful for debugging tests +import pprint +pretty = pprint.PrettyPrinter(indent=2, width=200).pprint + + +def test_registered_as(): + # Set 1 + hash = sarracenia.identity.sha512.Sha512() + assert hash.registered_as() == 's' + +def test_set_path(tmp_path): + path1 = str(tmp_path) + os.sep + "file1.txt" + hash = sarracenia.identity.sha512.Sha512() + hash.set_path(path1) + assert hash.filehash.name == "sha512" + +@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.sha512.Sha512() + hash.set_path(path1) + hash.update('randomstring') + assert hash.value == 'kkUPxxKfR72my8noS5yekWcdFnmIJSvDJIvtSF7uTyvnhtm0saERCXReIcNDAk2B7gET3o+tQY3gTbd36ynoDA==' + hash.update(b'randombytes') + assert hash.value == 'pPhNwHi6/lnnslx41G9BZ/5bEwpE+GbPTf9+6Rj7j76UeO7wT0c+Dlc2VioFI9Fy66G0pCszFkB/8cfrBFBRRw==' +