diff --git a/src/poly/cli_commands/review.py b/src/poly/cli_commands/review.py index 2238350e..d20674bb 100644 --- a/src/poly/cli_commands/review.py +++ b/src/poly/cli_commands/review.py @@ -297,6 +297,15 @@ def delete_gists(cls, gist_id: Optional[str] = None, output_json: bool = False) choices = [format_gist_choice(g) for g in gists] description_to_id = {format_gist_choice(g): g["id"] for g in gists} + if output_json: + json_print( + { + "success": False, + "error": "Please provide a gist ID to delete when using JSON output.", + } + ) + return + selected = questionary.checkbox("Select gists to delete", choices=choices).ask() if not selected: warning("No gists selected. Exiting.") diff --git a/src/poly/resources/handoff.py b/src/poly/resources/handoff.py index 096970b1..81289a35 100644 --- a/src/poly/resources/handoff.py +++ b/src/poly/resources/handoff.py @@ -136,13 +136,15 @@ def from_projection(cls, projection: dict) -> dict[str, "Handoff"]: return handoffs def to_yaml_dict(self) -> dict: - return { + result = { "name": self.name, "description": self.description, "is_default": self.is_default, "sip_config": self.sip_config.to_yaml_dict(), - "sip_headers": self.sip_headers, } + if self.sip_headers: + result["sip_headers"] = self.sip_headers + return result @property def file_path(self) -> str: diff --git a/src/poly/tests/github_api_test.py b/src/poly/tests/github_api_test.py index b222ca68..c44fbe01 100644 --- a/src/poly/tests/github_api_test.py +++ b/src/poly/tests/github_api_test.py @@ -321,15 +321,23 @@ def test_direct_gist_id_with_json_output(self, mock_json_print, mock_delete, moc @patch("poly.cli_commands.review.GitHubAPIHandler.delete_gist") @patch("questionary.checkbox") @patch("poly.cli_commands.review.json_print") - def test_json_output_prints_success(self, mock_json_print, mock_checkbox, mock_delete, mock_list): - """With output_json=True, a success JSON object is printed after deletion.""" + def test_json_output_without_gist_id_errors_without_prompting( + self, mock_json_print, mock_checkbox, mock_delete, mock_list + ): + """With output_json=True and no gist_id, a JSON error is printed and the + interactive checkbox prompt is never shown.""" mock_list.return_value = self.SAMPLE_GISTS - first_choice = format_gist_choice(self.SAMPLE_GISTS[0]) - mock_checkbox.return_value.ask.return_value = [first_choice] ReviewCommand.delete_gists(output_json=True) - mock_json_print.assert_called_once_with({"success": True}) + mock_checkbox.assert_not_called() + mock_delete.assert_not_called() + mock_json_print.assert_called_once_with( + { + "success": False, + "error": "Please provide a gist ID to delete when using JSON output.", + } + ) class ListGistsTest(unittest.TestCase):