From 09dddee3ebbbbbb8ed6eac74370232e76e84d7bb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 30 Jun 2026 10:58:02 +0200 Subject: feat: output emit and envelope unwrap --- tests/unit/test_output.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/unit/test_output.py (limited to 'tests') diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py new file mode 100644 index 0000000..c71a424 --- /dev/null +++ b/tests/unit/test_output.py @@ -0,0 +1,31 @@ +import io, json, unittest +from contextlib import redirect_stdout +from firefly_cli.output import unwrap, emit + +class TestOutput(unittest.TestCase): + def test_unwrap_list_returns_clean_objects(self): + resp = {"data": [ + {"id": "1", "type": "accounts", "attributes": {"name": "Checking"}}, + {"id": "2", "type": "accounts", "attributes": {"name": "Savings"}}, + ]} + self.assertEqual(unwrap(resp), + [{"id": "1", "name": "Checking"}, {"id": "2", "name": "Savings"}]) + + def test_unwrap_single_object(self): + resp = {"data": {"id": "5", "type": "accounts", + "attributes": {"name": "Wallet"}}} + self.assertEqual(unwrap(resp), {"id": "5", "name": "Wallet"}) + + def test_emit_json_default(self): + buf = io.StringIO() + with redirect_stdout(buf): + emit([{"id": "1", "name": "x"}], human=False) + self.assertEqual(json.loads(buf.getvalue()), [{"id": "1", "name": "x"}]) + + def test_emit_human_table_contains_values(self): + buf = io.StringIO() + with redirect_stdout(buf): + emit([{"id": "1", "name": "Checking"}], human=True) + out = buf.getvalue() + self.assertIn("Checking", out) + self.assertIn("id", out) -- cgit v1.2.3