Skip to content

Commit

Permalink
Full coverage identity unit tests
Browse files Browse the repository at this point in the history
Wrote some during a demo with Peter and co, and finished the last couple after.
  • Loading branch information
gcglinton committed Aug 1, 2023
1 parent 08e7046 commit 3645504
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 7 deletions.
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=='

5 changes: 1 addition & 4 deletions tests/sarracenia/identity/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions tests/sarracenia/identity/sha512_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3645504

Please sign in to comment.