Skip to content

Commit

Permalink
Added tests to get coverage up to 98% for added code
Browse files Browse the repository at this point in the history
  • Loading branch information
abodeuis committed Jul 16, 2024
1 parent daf9efb commit 52cd606
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 17 deletions.
12 changes: 11 additions & 1 deletion tests/data/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ def __eq__(self, other):


def get_mock_connector():
return MockConnector("mock_connector", "0.1", "mock_token")
con = MockConnector(
system_name="mock_connector",
system_version="0.1",
token="my_super_secret_mock_token_12345",
callback_url="https://mockurl.org/",
callback_secret="my_super_secret_mock_secret_54321",
callback_username="mock_username",
callback_password="password_99999",
registration="my_super_secret_mock_registration_67890"
)
return con
53 changes: 53 additions & 0 deletions tests/test_cdrhook/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from tests.utilities import init_test_log
from cdrhook.connector import CdrConnector
from tests.data.mock_data import get_mock_connector

load_dotenv()

Expand All @@ -12,6 +13,7 @@ class TestCDRConnector:
system_version = "0.1"
token = os.getenv("CDR_TOKEN")
callback_url = "https://criticalmaas.ncsa.illinois.edu/"


def test_constructor(self):
log = init_test_log("TestCDRConnector/test_constructor")
Expand Down Expand Up @@ -42,3 +44,54 @@ def test_registration(self):
con.unregister()
assert con.registration is None
log.info("Test passed successfully")

def test_repr(self):
log = init_test_log("TestCDRConnector/test_repr")
con = get_mock_connector()

con_repr = con.__repr__()
log.debug(f"Connector repr : {con_repr}")
# Fields that should be displayed
assert con.system_name in con_repr
assert con.system_version in con_repr
assert str(con.callback_url) in con_repr
assert con.callback_username in con_repr
assert con.cdr_url in con_repr
# Fields that should NOT be displayed
assert con.callback_password not in con_repr
assert con.callback_secret not in con_repr
assert con.token not in con_repr
assert con.registration not in con_repr

log.info("Test passed successfully")

def test_str(self):
log = init_test_log("TestCDRConnector/test_str")
con = get_mock_connector()

con_str = con.__str__()
log.debug(f"Connector str : {con_str}")
# Fields that should be displayed
assert con.system_name in con_str
assert con.system_version in con_str
assert str(con.callback_url) in con_str
assert con.callback_username in con_str
assert con.cdr_url in con_str
# Fields that should NOT be displayed
assert con.callback_password not in con_str
assert con.callback_secret not in con_str
assert con.token not in con_str
assert con.registration not in con_str

log.info("Test passed successfully")

def test_del(self):
log = init_test_log("TestCDRConnector/test_del")
con = get_mock_connector()
con.register()
del con

con = get_mock_connector()
del con

log.info("Test passed successfully")
50 changes: 34 additions & 16 deletions tests/test_cdrhook/test_retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import cdrhook.retrieve as rt
from cdrhook.connector import CdrConnector
from cdrhook.cdr_endpoint_schemas import SystemId
from tests.utilities import init_test_log

class TestRetrieveCog:
Expand Down Expand Up @@ -51,14 +52,23 @@ def test_retrieve_cog_area_extraction(self):
assert response_data
log.info("Test passed successfully")

# def test_retrieve_cog_area_extraction_by_system_id(self):
# log = init_test_log('TestRetrieveCog/test_retrieve_cog_area_extraction_by_system_id')
# json_data = rt.retrieve_cog_area_extraction(self.con, self.cog_id, system_id=SystemId('polymer', '0.0.1'))
# json_path = 'tests/logs/TestRetrieveCog/test_retrieve_cog_area_extraction_by_system_id.json'
# log.info(f'Saving result to {json_path}')
# with open(json_path, 'w') as fh:
# fh.write(json.dumps(json_data))
# log.info('Test passed successfully')
def test_retrieve_cog_area_extraction_by_system_id(self):
log = init_test_log('TestRetrieveCog/test_retrieve_cog_area_extraction_by_system_id')
cog_id = "5a06544690b6611f419f0c6f244776a536ad52915555555555515545c9b1ddb9"
test_system = SystemId(name='uncharted', version='0.0.4')
response_data = rt.retrieve_cog_area_extraction(self.con, cog_id, system_id=test_system)
cog_area_extraction = rt.validate_cog_area_extraction_response(response_data)
# Save Response
json_path = 'tests/logs/TestRetrieveCog/test_retrieve_cog_area_extraction_by_system_id.json'
log.info(f'Saving result to {json_path}')
with open(json_path, 'w') as fh:
fh.write(json.dumps(response_data))
# Check only the requested system data is returned
assert len(cog_area_extraction) > 0
for area_system in cog_area_extraction:
assert area_system.system == test_system.name
assert area_system.system_version == test_system.version
log.info('Test passed successfully')

def test_retrieve_cog_legend_items(self):
log = init_test_log("TestRetrieveCog/test_retrieve_cog_legend_items")
Expand All @@ -72,14 +82,22 @@ def test_retrieve_cog_legend_items(self):
assert response_data
log.info("Test passed successfully")

# def test_retrieve_cog_legend_items_by_system_id(self):
# log = init_test_log('TestRetrieveCog/test_retrieve_cog_legend_items_by_system_id')
# json_data = rt.retrieve_cog_legend_items(self.con, self.cog_id, system_id=SystemId('polymer', '0.0.1'))
# json_path = 'tests/logs/TestRetrieveCog/test_cog_legend_items_by_system_id.json'
# log.info(f'Saving result to {json_path}')
# with open(json_path, 'w') as fh:
# fh.write(json.dumps(json_data))
# log.info('Test passed successfully')
def test_retrieve_cog_legend_items_by_system_id(self):
log = init_test_log('TestRetrieveCog/test_retrieve_cog_legend_items_by_system_id')
test_system = SystemId(name='polymer', version='0.0.1')
response_data = rt.retrieve_cog_legend_items(self.con, self.cog_id, system_id=test_system)
cog_legend_items = rt.validate_cog_legend_items_response(response_data)
# Save Response
json_path = 'tests/logs/TestRetrieveCog/test_cog_legend_items_by_system_id.json'
log.info(f'Saving result to {json_path}')
with open(json_path, 'w') as fh:
fh.write(json.dumps(response_data))
# Check only the requested system data is returned
assert len(cog_legend_items) > 0
for legend_system in cog_legend_items:
assert legend_system.system == test_system.name
assert legend_system.system_version == test_system.version
log.info('Test passed successfully')

def test_retrieve_cog_metadata(self):
log = init_test_log("TestRetrieveCog/test_retrieve_cog_metadata")
Expand Down

0 comments on commit 52cd606

Please sign in to comment.