aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_commands_transaction.py67
-rw-r--r--tests/unit/test_output.py38
2 files changed, 105 insertions, 0 deletions
diff --git a/tests/unit/test_commands_transaction.py b/tests/unit/test_commands_transaction.py
index 7301002..325dcb7 100644
--- a/tests/unit/test_commands_transaction.py
+++ b/tests/unit/test_commands_transaction.py
@@ -67,6 +67,73 @@ class TestTxAdd(unittest.TestCase):
self.assertEqual(split["category_name"], "Brand New Cat")
resolver.category.assert_not_called()
+class TestTxEdit(unittest.TestCase):
+ def test_edit_sends_only_provided_fields(self):
+ ctx, client, resolver = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ args = MagicMock(id="9", amount="12.00", date=None, desc="fixed",
+ source=None, dest=None, category=None, tags=None, type=None)
+ rc = tx.cmd_edit(args, ctx)
+ self.assertEqual(rc, 0)
+ method, path = client.request.call_args[0][:2]
+ split = client.request.call_args[1]["body"]["transactions"][0]
+ self.assertEqual((method, path), ("PUT", "/api/v1/transactions/9"))
+ self.assertEqual(split, {"amount": "12.00", "description": "fixed"})
+ resolver.account.assert_not_called()
+
+ def test_edit_resolves_accounts_when_given(self):
+ ctx, client, resolver = make_ctx()
+ resolver.account.side_effect = lambda n: {
+ "BBVA": {"id": "3", "name": "BBVA", "type": "asset"},
+ "Medio": {"id": "4", "name": "Medio", "type": "asset"},
+ }[n]
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ args = MagicMock(id="9", amount=None, date=None, desc=None,
+ source="BBVA", dest="Medio", category=None, tags=None, type=None)
+ tx.cmd_edit(args, ctx)
+ split = client.request.call_args[1]["body"]["transactions"][0]
+ self.assertEqual(split, {"source_id": "3", "destination_id": "4"})
+
+ def test_edit_category_raw_and_tags_split(self):
+ ctx, client, resolver = make_ctx()
+ client.request.return_value = {"data": {"id": "9", "attributes": {}}}
+ args = MagicMock(id="9", amount=None, date=None, desc=None, source=None,
+ dest=None, category="Cat", tags="a, b", type="transfer")
+ tx.cmd_edit(args, ctx)
+ split = client.request.call_args[1]["body"]["transactions"][0]
+ self.assertEqual(split,
+ {"category_name": "Cat", "tags": ["a", "b"], "type": "transfer"})
+ resolver.category.assert_not_called()
+
+ def test_edit_with_no_fields_errors(self):
+ from firefly_cli.errors import FireflyError
+ ctx, client, _ = make_ctx()
+ args = MagicMock(id="9", amount=None, date=None, desc=None, source=None,
+ dest=None, category=None, tags=None, type=None)
+ with self.assertRaises(FireflyError):
+ tx.cmd_edit(args, ctx)
+ client.request.assert_not_called()
+
+
+class TestTxDelete(unittest.TestCase):
+ def test_delete_requires_yes(self):
+ from firefly_cli.errors import FireflyError
+ ctx, client, _ = make_ctx()
+ args = MagicMock(id="9", yes=False)
+ with self.assertRaises(FireflyError):
+ tx.cmd_delete(args, ctx)
+ client.request.assert_not_called()
+
+ def test_delete_with_yes(self):
+ ctx, client, _ = make_ctx()
+ client.request.return_value = {}
+ args = MagicMock(id="9", yes=True)
+ rc = tx.cmd_delete(args, ctx)
+ self.assertEqual(rc, 0)
+ method, path = client.request.call_args[0][:2]
+ self.assertEqual((method, path), ("DELETE", "/api/v1/transactions/9"))
+
+
class TestTxList(unittest.TestCase):
def test_list_passes_date_params(self):
ctx, client, _ = make_ctx()
diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py
index 5b154d9..2e3e5ea 100644
--- a/tests/unit/test_output.py
+++ b/tests/unit/test_output.py
@@ -75,3 +75,41 @@ class TestOutput(unittest.TestCase):
tty = TTY()
emit([tx], human=True, stream=tty)
self.assertIn("\033[31m", tty.getvalue()) # tty: withdrawal is red
+
+ def _emit(self, row):
+ buf = io.StringIO()
+ emit([row], human=True, stream=buf)
+ return buf.getvalue()
+
+ def test_view_account_shows_balance_drops_plumbing(self):
+ # account_role signature -> the account view.
+ out = self._emit({"id": "6", "name": "BBVA", "type": "asset",
+ "account_role": "defaultAsset",
+ "current_balance": "1590.92", "currency_code": "EUR",
+ "active": True, "iban": "IT68...", "notes": "secret"})
+ self.assertIn("BBVA", out)
+ self.assertIn("1590.92", out)
+ self.assertIn("currency_code", out)
+ self.assertNotIn("iban", out) # plumbing column dropped
+ self.assertNotIn("secret", out)
+
+ def test_view_tag(self):
+ out = self._emit({"id": "9", "tag": "2026", "description": "yr",
+ "zoom_level": None, "latitude": None})
+ self.assertIn("2026", out)
+ self.assertIn("description", out)
+ self.assertNotIn("zoom_level", out)
+
+ def test_view_account_balance(self):
+ # The balance handler emits id+name+current_balance (no account_role).
+ out = self._emit({"id": "6", "name": "BBVA",
+ "current_balance": "1590.92"})
+ self.assertIn("current_balance", out)
+ self.assertIn("1590.92", out)
+
+ def test_view_category_name_only(self):
+ out = self._emit({"id": "2", "name": "Food", "spent": [],
+ "primary_currency_code": "EUR", "notes": "junk"})
+ self.assertIn("Food", out)
+ self.assertNotIn("primary_currency_code", out)
+ self.assertNotIn("spent", out)