aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geldschieberbot.py18
-rwxr-xr-xtest.py15
2 files changed, 31 insertions, 2 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index 875ab30..9c622bd 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -181,7 +181,8 @@ Commands:
ls | list - print all registered members
help - print this help message
reg name - register the sender with the name: name
-sum [name] - print a summary
+sum [name] - print summary of specific users
+full-sum - print summary of all users
split amount person [persons] - split amount between the sender and persons
teil amount person [persons] - split amount between the sender and persons
@@ -250,7 +251,10 @@ cmds["register"] = register
def summary(sender, args, msg): # pylint: disable=unused-argument
if len(args) == 1:
- return create_total_summary(), None
+ if not sender in num2name:
+ return None, "You must register first to print your summary"
+ name = num2name[sender]
+ return f"Summary:\n{create_summary(name)}", None
err = None
msg = "Summary:\n"
@@ -265,6 +269,16 @@ def summary(sender, args, msg): # pylint: disable=unused-argument
cmds["sum"] = summary
cmds["summary"] = summary
+def full_summary(sender, args, msg): # pylint: disable=unused-argument
+ if len(args) == 1:
+ return create_total_summary(), None
+ else:
+ return None, f"{args[0][1:]} takes no arguments"
+
+
+cmds["full-sum"] = full_summary
+cmds["full-summary"] = full_summary
+
def list_users(sender, args, msg): # pylint: disable=unused-argument
return create_members(), None
diff --git a/test.py b/test.py
index 3f74559..0120c89 100755
--- a/test.py
+++ b/test.py
@@ -277,6 +277,14 @@ bob:
def test_summary(self):
reset_state("test/state.json_transactions1")
res = run_bot(self, num[alice], "!sum")
+ self.assertEqual(
+ res.stdout,
+ 'Summary:\nalice:\n\t-> bob 0.01\n\t-> charlie 1.00\n\tBalance: -1.01'
+ )
+
+ def test_full_summary(self):
+ reset_state("test/state.json_transactions1")
+ res = run_bot(self, num[alice], "!full-sum")
summary = \
"""Summary:
alice:
@@ -293,6 +301,11 @@ charlie:
\tBalance: 43.00"""
self.assertEqual(res.stdout, summary)
+ def test_full_summary_with_args(self):
+ reset_state("test/state.json_transactions1")
+ res = run_bot(self, num[alice], "!full-sum foo")
+ self.assertEqual(res.stdout, 'ERROR: full-sum takes no arguments')
+
class TestMisc(unittest.TestCase):
def test_unknown_command(self):
@@ -717,6 +730,7 @@ Car foo:
\tBalance: 1.20"""
self.assertEqual(res.stdout, o)
+
class TestTransferCmd(unittest.TestCase):
def setUp(self):
reset_state("test/state.json_3users")
@@ -925,6 +939,7 @@ alice <- 1.00 charlie
self.assertEqual(res.stdout, msg)
compare_state("test/state.json_3users")
+
class TestScheduleCmd(unittest.TestCase):
def setUp(self):
reset_state("test/state.json_3users")