From e6e37394f1d91bd3d9e8b174881f45ce25465fca Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:24:08 +0000 Subject: [PATCH 1/8] feat: add NTN support to hub.sync and hub.status Co-Authored-By: rlauer@blues.com --- notecard/hub.py | 26 ++++++++++++---- test/fluent_api/conftest.py | 8 +++++ test/fluent_api/test_hub_ntn.py | 54 +++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 test/fluent_api/test_hub_ntn.py diff --git a/notecard/hub.py b/notecard/hub.py index 0403d24..963c9dd 100644 --- a/notecard/hub.py +++ b/notecard/hub.py @@ -67,49 +67,63 @@ def set(card, product=None, sn=None, mode=None, outbound=None, @validate_card_object -def sync(card): +def sync(card, allow=None): """Initiate a sync of the Notecard to Notehub. Args: card (Notecard): The current Notecard object. + allow (bool): When True, allows syncing over a non-terrestrial + network even if the Notefile is not in compact mode. Returns: - string: The result of the Notecard request. + dict: The result of the Notecard request containing sync status. """ req = {"req": "hub.sync"} + if allow is not None: + req["allow"] = allow return card.Transaction(req) @validate_card_object -def syncStatus(card, sync=None): +def syncStatus(card, sync=None, ntn=None): """Retrieve the status of a sync request. Args: card (Notecard): The current Notecard object. sync (bool): True if sync should be auto-initiated pending outbound data. + ntn (bool): When True, returns additional status information about + non-terrestrial network sync status. Returns: - string: The result of the Notecard request. + dict: The result of the Notecard request containing sync status, + including NTN details when requested. """ req = {"req": "hub.sync.status"} if sync is not None: req["sync"] = sync + if ntn is not None: + req["ntn"] = ntn return card.Transaction(req) @validate_card_object -def status(card): +def status(card, ntn=None): """Retrieve the status of the Notecard's connection. Args: card (Notecard): The current Notecard object. + ntn (bool): When True, returns additional status information about + non-terrestrial network connectivity. Returns: - string: The result of the Notecard request. + dict: The result of the Notecard request containing connection status, + including NTN details when requested. """ req = {"req": "hub.status"} + if ntn is not None: + req["ntn"] = ntn return card.Transaction(req) diff --git a/test/fluent_api/conftest.py b/test/fluent_api/conftest.py index ced1a94..ba6dbdf 100644 --- a/test/fluent_api/conftest.py +++ b/test/fluent_api/conftest.py @@ -9,6 +9,14 @@ import notecard # noqa: E402 +@pytest.fixture +def card(): + """Create a mock Notecard instance for testing.""" + card = notecard.Notecard() + card.Transaction = MagicMock() + return card + + @pytest.fixture def run_fluent_api_notecard_api_mapping_test(): def _run_test(fluent_api, notecard_api_name, req_params, rename_map=None): diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py new file mode 100644 index 0000000..9325f1b --- /dev/null +++ b/test/fluent_api/test_hub_ntn.py @@ -0,0 +1,54 @@ +"""Test NTN support in hub module.""" +import pytest + +from notecard import hub + + +def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): + """Test hub.sync with NTN support.""" + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {"allow": True} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {"allow": False} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {} + ) + +def test_sync_status_with_ntn(run_fluent_api_notecard_api_mapping_test): + """Test hub.syncStatus with NTN support.""" + run_fluent_api_notecard_api_mapping_test( + hub.syncStatus, + "hub.sync.status", + {"ntn": True} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.syncStatus, + "hub.sync.status", + {"sync": True, "ntn": True} + ) + + +def test_status_with_ntn(run_fluent_api_notecard_api_mapping_test): + """Test hub.status with NTN support.""" + run_fluent_api_notecard_api_mapping_test( + hub.status, + "hub.status", + {"ntn": True} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.status, + "hub.status", + {} + ) From 05038d47b201742b1bdda5dcb5a1f578a764a5b9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:27:12 +0000 Subject: [PATCH 2/8] fix: add required blank lines between functions Co-Authored-By: rlauer@blues.com --- test/fluent_api/test_hub_ntn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 9325f1b..7f068c3 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -24,6 +24,7 @@ def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): {} ) + def test_sync_status_with_ntn(run_fluent_api_notecard_api_mapping_test): """Test hub.syncStatus with NTN support.""" run_fluent_api_notecard_api_mapping_test( From 47f7652064cf51054db488b2740101ee92dbe472 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:27:45 +0000 Subject: [PATCH 3/8] fix: add missing blank lines between functions Co-Authored-By: rlauer@blues.com --- test/fluent_api/test_hub_ntn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 7f068c3..5771db6 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -40,6 +40,7 @@ def test_sync_status_with_ntn(run_fluent_api_notecard_api_mapping_test): ) + def test_status_with_ntn(run_fluent_api_notecard_api_mapping_test): """Test hub.status with NTN support.""" run_fluent_api_notecard_api_mapping_test( From d5f3027ebd1d7f9093362685bb4967c98ffdbacc Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:29:36 +0000 Subject: [PATCH 4/8] fix: remove extra blank line between functions Co-Authored-By: rlauer@blues.com --- test/fluent_api/test_hub_ntn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 5771db6..7f068c3 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -40,7 +40,6 @@ def test_sync_status_with_ntn(run_fluent_api_notecard_api_mapping_test): ) - def test_status_with_ntn(run_fluent_api_notecard_api_mapping_test): """Test hub.status with NTN support.""" run_fluent_api_notecard_api_mapping_test( From ef8f2581cd63892bfdc06f486b533c4ae65d593b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:42:02 +0000 Subject: [PATCH 5/8] fix(hub): correct allow param docs, add out/in params, remove ntn param Co-Authored-By: rlauer@blues.com --- notecard/hub.py | 33 ++++++++++++++------------------- test/fluent_api/test_hub_ntn.py | 20 ++++++-------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/notecard/hub.py b/notecard/hub.py index 963c9dd..360ff28 100644 --- a/notecard/hub.py +++ b/notecard/hub.py @@ -9,7 +9,6 @@ # This module contains helper methods for calling hub.* Notecard API commands. # This module is optional and not required for use with the Notecard. -import notecard from notecard.validators import validate_card_object @@ -67,13 +66,16 @@ def set(card, product=None, sn=None, mode=None, outbound=None, @validate_card_object -def sync(card, allow=None): +def sync(card, allow=None, out=None, in_=None): """Initiate a sync of the Notecard to Notehub. Args: card (Notecard): The current Notecard object. - allow (bool): When True, allows syncing over a non-terrestrial - network even if the Notefile is not in compact mode. + allow (bool): Set to true to remove the Notecard from certain + types of penalty boxes (default is false). + out (bool): Set to true to only sync pending outbound Notefiles. + in_ (bool): Set to true to only sync pending inbound Notefiles. + Required when using NTN mode with Starnote. Returns: dict: The result of the Notecard request containing sync status. @@ -81,49 +83,42 @@ def sync(card, allow=None): req = {"req": "hub.sync"} if allow is not None: req["allow"] = allow + if out is not None: + req["out"] = out + if in_ is not None: + req["in"] = in_ return card.Transaction(req) @validate_card_object -def syncStatus(card, sync=None, ntn=None): +def syncStatus(card, sync=None): """Retrieve the status of a sync request. Args: card (Notecard): The current Notecard object. sync (bool): True if sync should be auto-initiated pending outbound data. - ntn (bool): When True, returns additional status information about - non-terrestrial network sync status. Returns: - dict: The result of the Notecard request containing sync status, - including NTN details when requested. + dict: The result of the Notecard request containing sync status. """ req = {"req": "hub.sync.status"} if sync is not None: req["sync"] = sync - if ntn is not None: - req["ntn"] = ntn - return card.Transaction(req) @validate_card_object -def status(card, ntn=None): +def status(card): """Retrieve the status of the Notecard's connection. Args: card (Notecard): The current Notecard object. - ntn (bool): When True, returns additional status information about - non-terrestrial network connectivity. Returns: - dict: The result of the Notecard request containing connection status, - including NTN details when requested. + dict: The result of the Notecard request containing connection status. """ req = {"req": "hub.status"} - if ntn is not None: - req["ntn"] = ntn return card.Transaction(req) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 7f068c3..7e5655d 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -1,6 +1,4 @@ """Test NTN support in hub module.""" -import pytest - from notecard import hub @@ -25,29 +23,23 @@ def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): ) -def test_sync_status_with_ntn(run_fluent_api_notecard_api_mapping_test): - """Test hub.syncStatus with NTN support.""" +def test_sync_status(run_fluent_api_notecard_api_mapping_test): + """Test hub.syncStatus.""" run_fluent_api_notecard_api_mapping_test( hub.syncStatus, "hub.sync.status", - {"ntn": True} + {"sync": True} ) run_fluent_api_notecard_api_mapping_test( hub.syncStatus, "hub.sync.status", - {"sync": True, "ntn": True} + {} ) -def test_status_with_ntn(run_fluent_api_notecard_api_mapping_test): - """Test hub.status with NTN support.""" - run_fluent_api_notecard_api_mapping_test( - hub.status, - "hub.status", - {"ntn": True} - ) - +def test_status(run_fluent_api_notecard_api_mapping_test): + """Test hub.status.""" run_fluent_api_notecard_api_mapping_test( hub.status, "hub.status", From d75ec8239b0a5122e8897832a96c5ff3ce8d7e47 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:48:20 +0000 Subject: [PATCH 6/8] fix: update test_hub_ntn.py to handle in_ parameter mapping Co-Authored-By: rlauer@blues.com --- test/fluent_api/test_hub_ntn.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 7e5655d..4f42c29 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -16,6 +16,26 @@ def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): {"allow": False} ) + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {"out": True} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {"in_": True}, + {"in_": "in"} + ) + + run_fluent_api_notecard_api_mapping_test( + hub.sync, + "hub.sync", + {"out": True, "in_": True}, + {"in_": "in"} + ) + run_fluent_api_notecard_api_mapping_test( hub.sync, "hub.sync", From 169d71fceb237417b267b86069d266a10af6b94c Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:56:05 +0000 Subject: [PATCH 7/8] fix: improve boolean parameter handling documentation and tests Co-Authored-By: rlauer@blues.com --- notecard/hub.py | 9 +++++++-- test/fluent_api/test_hub_ntn.py | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/notecard/hub.py b/notecard/hub.py index 360ff28..376f4d2 100644 --- a/notecard/hub.py +++ b/notecard/hub.py @@ -72,13 +72,18 @@ def sync(card, allow=None, out=None, in_=None): Args: card (Notecard): The current Notecard object. allow (bool): Set to true to remove the Notecard from certain - types of penalty boxes (default is false). + types of penalty boxes (default is false). Serialized as a JSON + boolean in the request. out (bool): Set to true to only sync pending outbound Notefiles. + Serialized as a JSON boolean in the request. in_ (bool): Set to true to only sync pending inbound Notefiles. - Required when using NTN mode with Starnote. + Required when using NTN mode with Starnote. Note: This parameter + is named 'in_' in Python code but appears as 'in' in the JSON + request to the Notecard. Serialized as a JSON boolean. Returns: dict: The result of the Notecard request containing sync status. + Example request: {"req": "hub.sync", "in": true, "out": false} """ req = {"req": "hub.sync"} if allow is not None: diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index 4f42c29..f7f2e59 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -1,4 +1,6 @@ """Test NTN support in hub module.""" +import json +from unittest.mock import ANY, call from notecard import hub @@ -43,6 +45,29 @@ def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): ) +def test_sync_boolean_serialization(card): + """Test that boolean values are properly serialized in hub.sync.""" + hub.sync(card, in_=True, out=False, allow=True) + + # Verify the Transaction was called with correct boolean values + expected_req = { + 'req': 'hub.sync', + 'in': True, + 'out': False, + 'allow': True + } + card.Transaction.assert_called_once_with(expected_req) + + # Verify JSON serialization format + args = card.Transaction.call_args + req_dict = args[0][0] + # Verify boolean values are preserved after JSON serialization + json_dict = json.loads(json.dumps(req_dict)) + assert json_dict["in"] is True + assert json_dict["out"] is False + assert json_dict["allow"] is True + + def test_sync_status(run_fluent_api_notecard_api_mapping_test): """Test hub.syncStatus.""" run_fluent_api_notecard_api_mapping_test( From 1677f7ac705c756d88957e8648482188491f0a65 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:58:34 +0000 Subject: [PATCH 8/8] fix: remove whitespace in blank lines Co-Authored-By: rlauer@blues.com --- test/fluent_api/test_hub_ntn.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/fluent_api/test_hub_ntn.py b/test/fluent_api/test_hub_ntn.py index f7f2e59..b9515d3 100644 --- a/test/fluent_api/test_hub_ntn.py +++ b/test/fluent_api/test_hub_ntn.py @@ -48,7 +48,6 @@ def test_sync_with_ntn(run_fluent_api_notecard_api_mapping_test): def test_sync_boolean_serialization(card): """Test that boolean values are properly serialized in hub.sync.""" hub.sync(card, in_=True, out=False, allow=True) - # Verify the Transaction was called with correct boolean values expected_req = { 'req': 'hub.sync', @@ -57,7 +56,6 @@ def test_sync_boolean_serialization(card): 'allow': True } card.Transaction.assert_called_once_with(expected_req) - # Verify JSON serialization format args = card.Transaction.call_args req_dict = args[0][0]