added initialise tests for base class

This commit is contained in:
seangreaves
2023-01-31 17:28:22 +00:00
parent da4959a3ed
commit a19b8a4888
4 changed files with 202 additions and 103 deletions

3
.gitignore vendored
View File

@@ -49,7 +49,8 @@ coverage.xml
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
# Testing notebook # Testing
.pytest_cache
notebooks/testing.ipynb notebooks/testing.ipynb
notebooks/investigations notebooks/investigations

View File

@@ -22,102 +22,115 @@ dependencies:
- xz=5.2.6=h775f41a_0 - xz=5.2.6=h775f41a_0
- zlib=1.2.13=hfd90126_4 - zlib=1.2.13=hfd90126_4
- pip: - pip:
- anyio==3.6.2 anyio==3.6.2
- appnope==0.1.3 appnope==0.1.3
- argon2-cffi==21.3.0 argon2-cffi==21.3.0
- argon2-cffi-bindings==21.2.0 argon2-cffi-bindings==21.2.0
- arrow==1.2.3 arrow==1.2.3
- asttokens==2.2.1 asttokens==2.2.1
- attrs==22.2.0 attrs==22.2.0
- babel==2.11.0 Babel==2.11.0
- backcall==0.2.0 backcall==0.2.0
- beautifulsoup4==4.11.1 beautifulsoup4==4.11.1
- bleach==5.0.1 bleach==5.0.1
- branca==0.6.0 branca==0.6.0
- certifi==2022.12.7 certifi==2022.12.7
- cffi==1.15.1 cffi==1.15.1
- charset-normalizer==2.1.1 charset-normalizer==2.1.1
- comm==0.1.2 comm==0.1.2
- debugpy==1.6.5 dateparser==1.1.6
- decorator==5.1.1 debugpy==1.6.5
- defusedxml==0.7.1 decorator==5.1.1
- entrypoints==0.4 defusedxml==0.7.1
- executing==1.2.0 entrypoints==0.4
- fastjsonschema==2.16.2 exceptiongroup==1.1.0
- fqdn==1.5.1 executing==1.2.0
- idna==3.4 fastjsonschema==2.16.2
- ipykernel==6.19.4 fqdn==1.5.1
- ipyleaflet==0.17.2 idna==3.4
- ipython==8.8.0 iniconfig==2.0.0
- ipython-genutils==0.2.0 ipykernel==6.19.4
- ipywidgets==8.0.4 ipyleaflet==0.17.2
- isoduration==20.11.0 ipython==8.8.0
- jedi==0.18.2 ipython-genutils==0.2.0
- jinja2==3.1.2 ipywidgets==8.0.4
- json5==0.9.11 isoduration==20.11.0
- jsonpointer==2.3 jedi==0.18.2
- jsonschema==4.17.3 Jinja2==3.1.2
- jupyter-client==7.4.1 json5==0.9.11
- jupyter-core==5.1.2 jsonpointer==2.3
- jupyter-events==0.5.0 jsonschema==4.17.3
- jupyter-server==1.23.4 jupyter_client==7.4.1
- jupyter-server-terminals==0.4.3 jupyter_core==5.1.2
- jupyterlab-pygments==0.2.2 jupyter-events==0.5.0
- jupyterlab-server==2.18.0 jupyter-server==1.23.4
- jupyterlab-widgets==3.0.5 jupyter_server_terminals==0.4.3
- markupsafe==2.1.1 jupyterlab-pygments==0.2.2
- matplotlib-inline==0.1.6 jupyterlab_server==2.18.0
- mistune==2.0.4 jupyterlab-widgets==3.0.5
- nbclassic==0.4.8 MarkupSafe==2.1.1
- nbclient==0.7.2 matplotlib-inline==0.1.6
- nbconvert==7.2.7 mistune==2.0.4
- nbformat==5.7.1 nbclassic==0.4.8
- nest-asyncio==1.5.6 nbclient==0.7.2
- notebook==6.5.2 nbconvert==7.2.7
- notebook-shim==0.2.2 nbformat==5.7.1
- numpy==1.24.1 nest-asyncio==1.5.6
- packaging==22.0 notebook==6.5.2
- pandas==1.5.2 notebook_shim==0.2.2
- pandocfilters==1.5.0 numpy==1.24.1
- parso==0.8.3 packaging==22.0
- pexpect==4.8.0 pandas==1.5.2
- pickleshare==0.7.5 pandocfilters==1.5.0
- platformdirs==2.6.2 parso==0.8.3
- prometheus-client==0.15.0 pexpect==4.8.0
- prompt-toolkit==3.0.36 pickleshare==0.7.5
- psutil==5.9.4 pip==22.3.1
- ptyprocess==0.7.0 platformdirs==2.6.2
- pure-eval==0.2.2 pluggy==1.0.0
- pycparser==2.21 prometheus-client==0.15.0
- pygments==2.14.0 prompt-toolkit==3.0.36
- pyrsistent==0.19.3 psutil==5.9.4
- python-dateutil==2.8.2 ptyprocess==0.7.0
- python-json-logger==2.0.4 pure-eval==0.2.2
- pytz==2022.7 pycparser==2.21
- pyyaml==6.0 Pygments==2.14.0
- pyzmq==24.0.1 pyrsistent==0.19.3
- ratelimit==2.2.1 pytest==7.2.1
- regex==2022.10.31 python-dateutil==2.8.2
- requests==2.28.1 python-json-logger==2.0.4
- rfc3339-validator==0.1.4 pytz==2022.7
- rfc3986-validator==0.1.1 pytz-deprecation-shim==0.1.0.post0
- send2trash==1.8.0 PyYAML==6.0
- six==1.16.0 pyzmq==24.0.1
- sniffio==1.3.0 ratelimit==2.2.1
- soupsieve==2.3.2.post1 regex==2022.10.31
- stack-data==0.6.2 requests==2.28.1
- terminado==0.17.1 rfc3339-validator==0.1.4
- tinycss2==1.2.1 rfc3986-validator==0.1.1
- tornado==6.2 Send2Trash==1.8.0
- traitlets==5.8.0 setuptools==65.6.3
- traittypes==0.2.1 six==1.16.0
- uri-template==1.2.0 sniffio==1.3.0
- urllib3==1.26.13 soupsieve==2.3.2.post1
- voila==0.4.0 stack-data==0.6.2
- wcwidth==0.2.5 sugartrail==1.0.0
- webcolors==1.12 terminado==0.17.1
- webencodings==0.5.1 tinycss2==1.2.1
- websocket-client==1.4.2 tomli==2.0.1
- websockets==10.4 tornado==6.2
- widgetsnbextension==4.0.5 traitlets==5.8.0
- xyzservices==2022.9.0 traittypes==0.2.1
tzdata==2022.7
tzlocal==4.2
uri-template==1.2.0
urllib3==1.26.13
voila==0.4.0
wcwidth==0.2.5
webcolors==1.12
webencodings==0.5.1
websocket-client==1.4.2
websockets==10.4
wheel==0.38.4
widgetsnbextension==4.0.5
xyzservices==2022.9.0

View File

@@ -14,14 +14,17 @@ certifi==2022.12.7
cffi==1.15.1 cffi==1.15.1
charset-normalizer==2.1.1 charset-normalizer==2.1.1
comm==0.1.2 comm==0.1.2
dateparser==1.1.6
debugpy==1.6.5 debugpy==1.6.5
decorator==5.1.1 decorator==5.1.1
defusedxml==0.7.1 defusedxml==0.7.1
entrypoints==0.4 entrypoints==0.4
exceptiongroup==1.1.0
executing==1.2.0 executing==1.2.0
fastjsonschema==2.16.2 fastjsonschema==2.16.2
fqdn==1.5.1 fqdn==1.5.1
idna==3.4 idna==3.4
iniconfig==2.0.0
ipykernel==6.19.4 ipykernel==6.19.4
ipyleaflet==0.17.2 ipyleaflet==0.17.2
ipython==8.8.0 ipython==8.8.0
@@ -33,14 +36,14 @@ Jinja2==3.1.2
json5==0.9.11 json5==0.9.11
jsonpointer==2.3 jsonpointer==2.3
jsonschema==4.17.3 jsonschema==4.17.3
jupyter-events==0.5.0
jupyter-server==1.23.4
jupyter_client==7.4.1 jupyter_client==7.4.1
jupyter_core==5.1.2 jupyter_core==5.1.2
jupyter-events==0.5.0
jupyter-server==1.23.4
jupyter_server_terminals==0.4.3 jupyter_server_terminals==0.4.3
jupyterlab-pygments==0.2.2 jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.5
jupyterlab_server==2.18.0 jupyterlab_server==2.18.0
jupyterlab-widgets==3.0.5
MarkupSafe==2.1.1 MarkupSafe==2.1.1
matplotlib-inline==0.1.6 matplotlib-inline==0.1.6
mistune==2.0.4 mistune==2.0.4
@@ -58,7 +61,9 @@ pandocfilters==1.5.0
parso==0.8.3 parso==0.8.3
pexpect==4.8.0 pexpect==4.8.0
pickleshare==0.7.5 pickleshare==0.7.5
pip==22.3.1
platformdirs==2.6.2 platformdirs==2.6.2
pluggy==1.0.0
prometheus-client==0.15.0 prometheus-client==0.15.0
prompt-toolkit==3.0.36 prompt-toolkit==3.0.36
psutil==5.9.4 psutil==5.9.4
@@ -67,9 +72,11 @@ pure-eval==0.2.2
pycparser==2.21 pycparser==2.21
Pygments==2.14.0 Pygments==2.14.0
pyrsistent==0.19.3 pyrsistent==0.19.3
pytest==7.2.1
python-dateutil==2.8.2 python-dateutil==2.8.2
python-json-logger==2.0.4 python-json-logger==2.0.4
pytz==2022.7 pytz==2022.7
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0 PyYAML==6.0
pyzmq==24.0.1 pyzmq==24.0.1
ratelimit==2.2.1 ratelimit==2.2.1
@@ -78,15 +85,20 @@ requests==2.28.1
rfc3339-validator==0.1.4 rfc3339-validator==0.1.4
rfc3986-validator==0.1.1 rfc3986-validator==0.1.1
Send2Trash==1.8.0 Send2Trash==1.8.0
setuptools==65.6.3
six==1.16.0 six==1.16.0
sniffio==1.3.0 sniffio==1.3.0
soupsieve==2.3.2.post1 soupsieve==2.3.2.post1
stack-data==0.6.2 stack-data==0.6.2
sugartrail==1.0.0
terminado==0.17.1 terminado==0.17.1
tinycss2==1.2.1 tinycss2==1.2.1
tomli==2.0.1
tornado==6.2 tornado==6.2
traitlets==5.8.0 traitlets==5.8.0
traittypes==0.2.1 traittypes==0.2.1
tzdata==2022.7
tzlocal==4.2
uri-template==1.2.0 uri-template==1.2.0
urllib3==1.26.13 urllib3==1.26.13
voila==0.4.0 voila==0.4.0
@@ -95,5 +107,6 @@ webcolors==1.12
webencodings==0.5.1 webencodings==0.5.1
websocket-client==1.4.2 websocket-client==1.4.2
websockets==10.4 websockets==10.4
wheel==0.38.4
widgetsnbextension==4.0.5 widgetsnbextension==4.0.5
xyzservices==2022.9.0 xyzservices==2022.9.0

72
test/test_base.py Normal file
View File

@@ -0,0 +1,72 @@
import sugartrail
import pytest
import json
# test 1: network initialised without auth and without arguments:
def test_init_without_arguments(capsys):
sugartrail.base.Network()
captured = capsys.readouterr()
assert captured.out == 'No input provided. Please provide either officer_id, company_id, address or file as input.\n'
# test 2: network initialised without auth and with arguments prints auth requirement:
def test_init_officer_without_auth(capsys):
sugartrail.base.Network(officer_id = '_')
captured = capsys.readouterr()
assert captured.out == 'Authentication required\n'
def test_init_company_without_auth(capsys):
sugartrail.base.Network(company_id = '_')
captured = capsys.readouterr()
assert captured.out == 'Authentication required\n'
def test_init_address_without_auth(capsys):
sugartrail.base.Network(address = '_')
captured = capsys.readouterr()
assert captured.out == 'Authentication required\n'
# test 3: network initialised without auth and with arguments remains stateless:
def test_empty_officer_without_auth(capsys):
network = sugartrail.base.Network(officer_id = '_')
assert network._officer_id == None
def test_empty_company_without_auth(capsys):
network = sugartrail.base.Network(company_id = '_')
assert network._company_id == None
def test_empty_address_without_auth(capsys):
network = sugartrail.base.Network(address = '_')
assert network._address == None
# test 4: network initialised with 'file' arg without auth loads network:
def test_file_init_without_auth():
network = sugartrail.base.Network(file ='./assets/networks/domain_corp_network.json')
with open('./assets/networks/domain_corp_network.json') as f:
network_json = json.load(f)
for key in network.__dict__.keys():
if key != 'hop' and key != '_file':
assert network.__dict__[key] == network_json[key]
# test 5: network initialised with 'file' arg without auth loads network:
def test_file_init_without_auth():
network = sugartrail.base.Network(file ='./assets/networks/domain_corp_network.json')
with open('./assets/networks/domain_corp_network.json') as f:
network_json = json.load(f)
for key in network.__dict__.keys():
if key != 'hop' and key != '_file':
assert network.__dict__[key] == network_json[key]
# test 5: network loads network from file without auth:
def test_file_load_without_auth():
network = sugartrail.base.Network()
network.load('./assets/networks/domain_corp_network.json')
with open('./assets/networks/domain_corp_network.json') as f:
network_json = json.load(f)
for key in network.__dict__.keys():
if key != 'hop' and key != '_file':
assert network.__dict__[key] == network_json[key]