Skip to content

Commit

Permalink
add save and load tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-kleiner committed Aug 1, 2024
1 parent 5f64785 commit 8b66a15
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/test_public_interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import unittest
from datetime import datetime, timezone
from ipaddress import IPv4Network, IPv6Network
Expand Down Expand Up @@ -227,6 +228,60 @@ def test_entity_interface_1(self):
self.assertTrue(isinstance(resp["entities"]["technical"], list))
self.assertTrue(len(resp["entities"]["technical"]) > 0)

@responses.activate
# @_recorder.record(file_path=RESPONSES / 'boostrap.yaml')
def test_save_bootstrap_data(self):
responses._add_from_file(RESPONSES / "boostrap.yaml")
whoisit.bootstrap()
self.assertTrue(whoisit.is_bootstrapped())

result = whoisit.save_bootstrap_data()
self.assertTrue(isinstance(result, str))

data = json.loads(result)
self.assertTrue(bool(data))

@responses.activate
# @_recorder.record(file_path=RESPONSES / 'boostrap.yaml')
def test_save_bootstrap_data_no_json(self):
responses._add_from_file(RESPONSES / "boostrap.yaml")
whoisit.bootstrap()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data(as_json=False)
self.assertTrue(isinstance(data, dict))
self.assertTrue(bool(data))

@responses.activate
# @_recorder.record(file_path=RESPONSES / 'boostrap.yaml')
def test_load_bootstrap_data(self):
responses._add_from_file(RESPONSES / "boostrap.yaml")
whoisit.bootstrap()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data()
self.assertTrue(isinstance(data, str))

whoisit.clear_bootstrapping()

whoisit.load_bootstrap_data(data)
self.assertTrue(whoisit.is_bootstrapped())

@responses.activate
# @_recorder.record(file_path=RESPONSES / 'boostrap.yaml')
def test_load_bootstrap_data_no_json(self):
responses._add_from_file(RESPONSES / "boostrap.yaml")
whoisit.bootstrap()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data(as_json=False)
self.assertTrue(isinstance(data, dict))

whoisit.clear_bootstrapping()

whoisit.load_bootstrap_data(data, from_json=False)
self.assertTrue(whoisit.is_bootstrapped())


#############################################
################### Async ###################
Expand Down Expand Up @@ -463,3 +518,57 @@ async def test_entity_interface_1(self):
)
self.assertTrue(isinstance(resp["entities"]["technical"], list))
self.assertTrue(len(resp["entities"]["technical"]) > 0)

@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_httpx")
async def test_save_bootstrap_data(self):
load_sync_responses_to_httpx_mock(RESPONSES / "boostrap.yaml", self.httpx_mock)
await whoisit.bootstrap_async()
self.assertTrue(whoisit.is_bootstrapped())

result = whoisit.save_bootstrap_data()
self.assertTrue(isinstance(result, str))

data = json.loads(result)
self.assertTrue(bool(data))

@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_httpx")
async def test_save_bootstrap_data_no_json(self):
load_sync_responses_to_httpx_mock(RESPONSES / "boostrap.yaml", self.httpx_mock)
await whoisit.bootstrap_async()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data(as_json=False)
self.assertTrue(isinstance(data, dict))
self.assertTrue(bool(data))

@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_httpx")
async def test_load_bootstrap_data(self):
load_sync_responses_to_httpx_mock(RESPONSES / "boostrap.yaml", self.httpx_mock)
await whoisit.bootstrap_async()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data()
self.assertTrue(isinstance(data, str))

whoisit.clear_bootstrapping()

whoisit.load_bootstrap_data(data)
self.assertTrue(whoisit.is_bootstrapped())

@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_httpx")
async def test_load_bootstrap_data_no_json(self):
load_sync_responses_to_httpx_mock(RESPONSES / "boostrap.yaml", self.httpx_mock)
await whoisit.bootstrap_async()
self.assertTrue(whoisit.is_bootstrapped())

data = whoisit.save_bootstrap_data(as_json=False)
self.assertTrue(isinstance(data, dict))

whoisit.clear_bootstrapping()

whoisit.load_bootstrap_data(data, from_json=False)
self.assertTrue(whoisit.is_bootstrapped())

0 comments on commit 8b66a15

Please sign in to comment.