mirror of
https://github.com/bellingcat/sugartrail.git
synced 2026-06-07 19:18:30 +03:00
added initialise tests for base class
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -49,7 +49,8 @@ coverage.xml
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# Testing notebook
|
||||
# Testing
|
||||
.pytest_cache
|
||||
notebooks/testing.ipynb
|
||||
notebooks/investigations
|
||||
|
||||
|
||||
@@ -22,102 +22,115 @@ dependencies:
|
||||
- xz=5.2.6=h775f41a_0
|
||||
- zlib=1.2.13=hfd90126_4
|
||||
- pip:
|
||||
- anyio==3.6.2
|
||||
- appnope==0.1.3
|
||||
- argon2-cffi==21.3.0
|
||||
- argon2-cffi-bindings==21.2.0
|
||||
- arrow==1.2.3
|
||||
- asttokens==2.2.1
|
||||
- attrs==22.2.0
|
||||
- babel==2.11.0
|
||||
- backcall==0.2.0
|
||||
- beautifulsoup4==4.11.1
|
||||
- bleach==5.0.1
|
||||
- branca==0.6.0
|
||||
- certifi==2022.12.7
|
||||
- cffi==1.15.1
|
||||
- charset-normalizer==2.1.1
|
||||
- comm==0.1.2
|
||||
- debugpy==1.6.5
|
||||
- decorator==5.1.1
|
||||
- defusedxml==0.7.1
|
||||
- entrypoints==0.4
|
||||
- executing==1.2.0
|
||||
- fastjsonschema==2.16.2
|
||||
- fqdn==1.5.1
|
||||
- idna==3.4
|
||||
- ipykernel==6.19.4
|
||||
- ipyleaflet==0.17.2
|
||||
- ipython==8.8.0
|
||||
- ipython-genutils==0.2.0
|
||||
- ipywidgets==8.0.4
|
||||
- isoduration==20.11.0
|
||||
- jedi==0.18.2
|
||||
- jinja2==3.1.2
|
||||
- json5==0.9.11
|
||||
- jsonpointer==2.3
|
||||
- jsonschema==4.17.3
|
||||
- jupyter-client==7.4.1
|
||||
- jupyter-core==5.1.2
|
||||
- jupyter-events==0.5.0
|
||||
- jupyter-server==1.23.4
|
||||
- jupyter-server-terminals==0.4.3
|
||||
- jupyterlab-pygments==0.2.2
|
||||
- jupyterlab-server==2.18.0
|
||||
- jupyterlab-widgets==3.0.5
|
||||
- markupsafe==2.1.1
|
||||
- matplotlib-inline==0.1.6
|
||||
- mistune==2.0.4
|
||||
- nbclassic==0.4.8
|
||||
- nbclient==0.7.2
|
||||
- nbconvert==7.2.7
|
||||
- nbformat==5.7.1
|
||||
- nest-asyncio==1.5.6
|
||||
- notebook==6.5.2
|
||||
- notebook-shim==0.2.2
|
||||
- numpy==1.24.1
|
||||
- packaging==22.0
|
||||
- pandas==1.5.2
|
||||
- pandocfilters==1.5.0
|
||||
- parso==0.8.3
|
||||
- pexpect==4.8.0
|
||||
- pickleshare==0.7.5
|
||||
- platformdirs==2.6.2
|
||||
- prometheus-client==0.15.0
|
||||
- prompt-toolkit==3.0.36
|
||||
- psutil==5.9.4
|
||||
- ptyprocess==0.7.0
|
||||
- pure-eval==0.2.2
|
||||
- pycparser==2.21
|
||||
- pygments==2.14.0
|
||||
- pyrsistent==0.19.3
|
||||
- python-dateutil==2.8.2
|
||||
- python-json-logger==2.0.4
|
||||
- pytz==2022.7
|
||||
- pyyaml==6.0
|
||||
- pyzmq==24.0.1
|
||||
- ratelimit==2.2.1
|
||||
- regex==2022.10.31
|
||||
- requests==2.28.1
|
||||
- rfc3339-validator==0.1.4
|
||||
- rfc3986-validator==0.1.1
|
||||
- send2trash==1.8.0
|
||||
- six==1.16.0
|
||||
- sniffio==1.3.0
|
||||
- soupsieve==2.3.2.post1
|
||||
- stack-data==0.6.2
|
||||
- terminado==0.17.1
|
||||
- tinycss2==1.2.1
|
||||
- tornado==6.2
|
||||
- traitlets==5.8.0
|
||||
- traittypes==0.2.1
|
||||
- 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
|
||||
- widgetsnbextension==4.0.5
|
||||
- xyzservices==2022.9.0
|
||||
anyio==3.6.2
|
||||
appnope==0.1.3
|
||||
argon2-cffi==21.3.0
|
||||
argon2-cffi-bindings==21.2.0
|
||||
arrow==1.2.3
|
||||
asttokens==2.2.1
|
||||
attrs==22.2.0
|
||||
Babel==2.11.0
|
||||
backcall==0.2.0
|
||||
beautifulsoup4==4.11.1
|
||||
bleach==5.0.1
|
||||
branca==0.6.0
|
||||
certifi==2022.12.7
|
||||
cffi==1.15.1
|
||||
charset-normalizer==2.1.1
|
||||
comm==0.1.2
|
||||
dateparser==1.1.6
|
||||
debugpy==1.6.5
|
||||
decorator==5.1.1
|
||||
defusedxml==0.7.1
|
||||
entrypoints==0.4
|
||||
exceptiongroup==1.1.0
|
||||
executing==1.2.0
|
||||
fastjsonschema==2.16.2
|
||||
fqdn==1.5.1
|
||||
idna==3.4
|
||||
iniconfig==2.0.0
|
||||
ipykernel==6.19.4
|
||||
ipyleaflet==0.17.2
|
||||
ipython==8.8.0
|
||||
ipython-genutils==0.2.0
|
||||
ipywidgets==8.0.4
|
||||
isoduration==20.11.0
|
||||
jedi==0.18.2
|
||||
Jinja2==3.1.2
|
||||
json5==0.9.11
|
||||
jsonpointer==2.3
|
||||
jsonschema==4.17.3
|
||||
jupyter_client==7.4.1
|
||||
jupyter_core==5.1.2
|
||||
jupyter-events==0.5.0
|
||||
jupyter-server==1.23.4
|
||||
jupyter_server_terminals==0.4.3
|
||||
jupyterlab-pygments==0.2.2
|
||||
jupyterlab_server==2.18.0
|
||||
jupyterlab-widgets==3.0.5
|
||||
MarkupSafe==2.1.1
|
||||
matplotlib-inline==0.1.6
|
||||
mistune==2.0.4
|
||||
nbclassic==0.4.8
|
||||
nbclient==0.7.2
|
||||
nbconvert==7.2.7
|
||||
nbformat==5.7.1
|
||||
nest-asyncio==1.5.6
|
||||
notebook==6.5.2
|
||||
notebook_shim==0.2.2
|
||||
numpy==1.24.1
|
||||
packaging==22.0
|
||||
pandas==1.5.2
|
||||
pandocfilters==1.5.0
|
||||
parso==0.8.3
|
||||
pexpect==4.8.0
|
||||
pickleshare==0.7.5
|
||||
pip==22.3.1
|
||||
platformdirs==2.6.2
|
||||
pluggy==1.0.0
|
||||
prometheus-client==0.15.0
|
||||
prompt-toolkit==3.0.36
|
||||
psutil==5.9.4
|
||||
ptyprocess==0.7.0
|
||||
pure-eval==0.2.2
|
||||
pycparser==2.21
|
||||
Pygments==2.14.0
|
||||
pyrsistent==0.19.3
|
||||
pytest==7.2.1
|
||||
python-dateutil==2.8.2
|
||||
python-json-logger==2.0.4
|
||||
pytz==2022.7
|
||||
pytz-deprecation-shim==0.1.0.post0
|
||||
PyYAML==6.0
|
||||
pyzmq==24.0.1
|
||||
ratelimit==2.2.1
|
||||
regex==2022.10.31
|
||||
requests==2.28.1
|
||||
rfc3339-validator==0.1.4
|
||||
rfc3986-validator==0.1.1
|
||||
Send2Trash==1.8.0
|
||||
setuptools==65.6.3
|
||||
six==1.16.0
|
||||
sniffio==1.3.0
|
||||
soupsieve==2.3.2.post1
|
||||
stack-data==0.6.2
|
||||
sugartrail==1.0.0
|
||||
terminado==0.17.1
|
||||
tinycss2==1.2.1
|
||||
tomli==2.0.1
|
||||
tornado==6.2
|
||||
traitlets==5.8.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
|
||||
|
||||
@@ -14,14 +14,17 @@ certifi==2022.12.7
|
||||
cffi==1.15.1
|
||||
charset-normalizer==2.1.1
|
||||
comm==0.1.2
|
||||
dateparser==1.1.6
|
||||
debugpy==1.6.5
|
||||
decorator==5.1.1
|
||||
defusedxml==0.7.1
|
||||
entrypoints==0.4
|
||||
exceptiongroup==1.1.0
|
||||
executing==1.2.0
|
||||
fastjsonschema==2.16.2
|
||||
fqdn==1.5.1
|
||||
idna==3.4
|
||||
iniconfig==2.0.0
|
||||
ipykernel==6.19.4
|
||||
ipyleaflet==0.17.2
|
||||
ipython==8.8.0
|
||||
@@ -33,14 +36,14 @@ Jinja2==3.1.2
|
||||
json5==0.9.11
|
||||
jsonpointer==2.3
|
||||
jsonschema==4.17.3
|
||||
jupyter-events==0.5.0
|
||||
jupyter-server==1.23.4
|
||||
jupyter_client==7.4.1
|
||||
jupyter_core==5.1.2
|
||||
jupyter-events==0.5.0
|
||||
jupyter-server==1.23.4
|
||||
jupyter_server_terminals==0.4.3
|
||||
jupyterlab-pygments==0.2.2
|
||||
jupyterlab-widgets==3.0.5
|
||||
jupyterlab_server==2.18.0
|
||||
jupyterlab-widgets==3.0.5
|
||||
MarkupSafe==2.1.1
|
||||
matplotlib-inline==0.1.6
|
||||
mistune==2.0.4
|
||||
@@ -58,7 +61,9 @@ pandocfilters==1.5.0
|
||||
parso==0.8.3
|
||||
pexpect==4.8.0
|
||||
pickleshare==0.7.5
|
||||
pip==22.3.1
|
||||
platformdirs==2.6.2
|
||||
pluggy==1.0.0
|
||||
prometheus-client==0.15.0
|
||||
prompt-toolkit==3.0.36
|
||||
psutil==5.9.4
|
||||
@@ -67,9 +72,11 @@ pure-eval==0.2.2
|
||||
pycparser==2.21
|
||||
Pygments==2.14.0
|
||||
pyrsistent==0.19.3
|
||||
pytest==7.2.1
|
||||
python-dateutil==2.8.2
|
||||
python-json-logger==2.0.4
|
||||
pytz==2022.7
|
||||
pytz-deprecation-shim==0.1.0.post0
|
||||
PyYAML==6.0
|
||||
pyzmq==24.0.1
|
||||
ratelimit==2.2.1
|
||||
@@ -78,15 +85,20 @@ requests==2.28.1
|
||||
rfc3339-validator==0.1.4
|
||||
rfc3986-validator==0.1.1
|
||||
Send2Trash==1.8.0
|
||||
setuptools==65.6.3
|
||||
six==1.16.0
|
||||
sniffio==1.3.0
|
||||
soupsieve==2.3.2.post1
|
||||
stack-data==0.6.2
|
||||
sugartrail==1.0.0
|
||||
terminado==0.17.1
|
||||
tinycss2==1.2.1
|
||||
tomli==2.0.1
|
||||
tornado==6.2
|
||||
traitlets==5.8.0
|
||||
traittypes==0.2.1
|
||||
tzdata==2022.7
|
||||
tzlocal==4.2
|
||||
uri-template==1.2.0
|
||||
urllib3==1.26.13
|
||||
voila==0.4.0
|
||||
@@ -95,5 +107,6 @@ 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
|
||||
|
||||
72
test/test_base.py
Normal file
72
test/test_base.py
Normal 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]
|
||||
Reference in New Issue
Block a user