From ac224fe92b075e45fee9a59f6be20be4eb5c9694 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 14 Sep 2020 17:07:22 +0200 Subject: add list-changes command --- test.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'test.py') diff --git a/test.py b/test.py index 56f6949..b26fc89 100755 --- a/test.py +++ b/test.py @@ -708,6 +708,85 @@ New Balance: bob -> 5.00 charlie #TODO: tanken, transfer, cars pay +class TestListChangesCmd(unittest.TestCase): + + def setUp(self): + reset_state("test/state.json_3users") + + def test_list_changes_unregistered(self): + res = run_bot(self, "+4971576357", "!list-changes") + self.assertEqual(res.stdout, 'ERROR: you must register first') + + def test_list_changes_single_change(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + res = run_bot(self, num[alice], "!list-changes") + msg = \ +"""Changes from alice 1-1 +Change 1: +!schieb bob 10 +alice <- 10.00 bob +""" + self.assertEqual(res.stdout, msg) + + def test_list_changes_single_change_invalid_amount(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + res = run_bot(self, num[alice], "!list-changes foo") + msg = \ +"""ERROR: the amount of changes to list must be a number""" + self.assertEqual(res.stdout, msg) + + def test_list_changes_single_change_invalid_offset(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + res = run_bot(self, num[alice], "!list-changes 1 foo") + msg = \ +"""ERROR: the first change to list must be a number""" + self.assertEqual(res.stdout, msg) + + res = run_bot(self, num[alice], "!list-changes 1 20") + msg = \ +"""ERROR: the first change to list is bigger than there are changes""" + self.assertEqual(res.stdout, msg) + + def test_list_changes_two_changes(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + run_bot(self, num[alice], f"!zieh {charlie} 5") + res = run_bot(self, num[alice], "!list-changes") + msg = \ +"""Changes from alice 1-2 +Change 1: +!schieb bob 10 +alice <- 10.00 bob +Change 2: +!zieh charlie 5 +alice -> 5.00 charlie +""" + self.assertEqual(res.stdout, msg) + + def test_list_changes_one_of_two(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + run_bot(self, num[alice], f"!zieh {charlie} 5") + res = run_bot(self, num[alice], "!list-changes 1") + msg = \ +"""Changes from alice 2-2 +Change 2: +!zieh charlie 5 +alice -> 5.00 charlie +""" + self.assertEqual(res.stdout, msg) + + def test_list_changes_only_second(self): + run_bot(self, num[alice], f"!schieb {bob} 10") + run_bot(self, num[alice], f"!zieh {charlie} 5") + run_bot(self, num[alice], f"!split 9 {bob} {charlie}") + res = run_bot(self, num[alice], "!list-changes 1 2") + msg = \ +"""Changes from alice 2-2 +Change 2: +!zieh charlie 5 +alice -> 5.00 charlie +""" + self.assertEqual(res.stdout, msg) + class TestFuckCmd(unittest.TestCase): def setUp(self): -- cgit v1.2.3