Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity Unit tests #739

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/sarracenia/__init___test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
42 changes: 42 additions & 0 deletions tests/sarracenia/identity/_identity_test.py
Original file line number Diff line number Diff line change
@@ -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=='
47 changes: 47 additions & 0 deletions tests/sarracenia/identity/arbitrary_test.py
Original file line number Diff line number Diff line change
@@ -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'

36 changes: 36 additions & 0 deletions tests/sarracenia/identity/md5_test.py
Original file line number Diff line number Diff line change
@@ -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=='

32 changes: 32 additions & 0 deletions tests/sarracenia/identity/random_test.py
Original file line number Diff line number Diff line change
@@ -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'

36 changes: 36 additions & 0 deletions tests/sarracenia/identity/sha512_test.py
Original file line number Diff line number Diff line change
@@ -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=='