diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2022-10-28 18:16:47 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-08-10 15:04:16 +0200 |
| commit | 26831dca32c471415b1afa470ac8dbfd1fd348a6 (patch) | |
| tree | d7ae2a62eedd2a2af2638c2475cc6af93ca4af51 /test.py | |
| parent | 2cf937b89e5f0bcd0b86dc75835e8a2315f01fd7 (diff) | |
| download | geldschieberbot-26831dca32c471415b1afa470ac8dbfd1fd348a6.tar.gz geldschieberbot-26831dca32c471415b1afa470ac8dbfd1fd348a6.zip | |
introduce dataclasses for the passed data
Refactor all implicit dictionaries into explicit data classes.
This makes the code more explicit, easier to check for mypy and overall
more maintainable.
Diffstat (limited to 'test.py')
| -rwxr-xr-x | test.py | 44 |
1 files changed, 32 insertions, 12 deletions
@@ -49,7 +49,7 @@ scheduled_state_template = Template(""" "num2name": {"+49123456": "alice", "+49654321": "bob", "+49615243": "charlie"}, "cars": {}, "scheduled_cmds": {"stuff": {"schedule": "$schedule", "last_time": "$last_time", - "sender": "+49123456", "cmd": ["split", "3", "bob", "charlie"]}}, + "sender": "alice", "cmd": ["split", "3", "bob", "charlie"]}}, "changes": {"alice": [], "bob": [], "charlie": []}}""") @@ -707,13 +707,13 @@ class TestCarPayCmd(unittest.TestCase): def setUp(self): reset_state("test/state_2cars.json") + self.maxDiff = None def test_alice_pays_exact(self): run_bot(self, num[bob], "!zieh foo 20") run_bot(self, num[charlie], "!zieh foo 10") - i = "!cars pay foo 30" - res = run_bot(self, num[alice], i) + res = run_bot(self, num[alice], "!cars pay foo 30") o = \ """alice payed 30.00 Transferring 100.00% of everybody's charges @@ -732,8 +732,7 @@ foo: run_bot(self, num[bob], "!zieh foo 20") run_bot(self, num[charlie], "!zieh foo 10") - i = "!cars pay foo 40" - res = run_bot(self, num[alice], i) + res = run_bot(self, num[alice], "!cars pay foo 40") o = \ """alice payed 40.00 Transferring 100.00% of everybody's charges @@ -1103,7 +1102,7 @@ Rewinding: !transfer 5 bob charlie alice -> 5.00 bob alice <- 5.00 charlie -charlie <- 5.00 bob +bob -> 5.00 charlie """ self.assertEqual(res.stdout, msg) compare_state("test/state_3users.json") @@ -1154,6 +1153,27 @@ class TestScheduleCmd(unittest.TestCase): def setUp(self): reset_state("test/state_3users.json") + def test_schedule_twice(self): + run_bot(self, num[alice], "!weekly stuff ls") + res = run_bot(self, num[alice], "!weekly stuff ls") + self.assertEqual( + res.stdout, + 'ERROR: there is already a scheduled command named "stuff"') + + def test_schedule_not_available_cmd(self): + res = run_bot(self, num[alice], "!weekly stuff foo") + self.assertEqual( + res.stdout, + 'ERROR: the command "stuff" can not be registered because "foo" is unknown' + ) + + def test_schedule_errorous_cmd(self): + res = run_bot(self, num[alice], "!weekly stuff gib foo 100") + self.assertEqual( + res.stdout, + 'ERROR: the command "stuff" failed with "recipient not known" and will not be recorded' + ) + def test_weekly(self): res = run_bot(self, num[alice], "!weekly stuff split 3 bob charlie") msg = \ @@ -1167,7 +1187,7 @@ alice: \tBalance: 2.00""" self.assertEqual(res.stdout, msg) - save_state("test/state.json_schedule_weekly") + save_state("test/state_schedule_weekly.json") res = run_bot(self, num[alice], "!fuck") msg = \ @@ -1196,7 +1216,7 @@ alice: \tBalance: 4.00""" self.assertEqual(res.stdout, msg) - compare_state("test/state.json_schedule_weekly") + compare_state("test/state_schedule_weekly.json") res = run_bot(self, num[alice], "!fuck") self.assertEqual(res.stdout, 'Nothing to rewind') @@ -1225,7 +1245,7 @@ alice: \tBalance: 6.00""" self.assertEqual(res.stdout, msg) - os.remove("test/state.json_schedule_weekly") + os.remove("test/state_schedule_weekly.json") def test_monthly(self): self.maxDiff = None @@ -1241,7 +1261,7 @@ alice: \tBalance: 2.00""" self.assertEqual(res.stdout, msg) - save_state("test/state.json_schedule_monthly") + save_state("test/state_schedule_monthly.json") res = run_bot(self, num[alice], "!fuck") msg = \ @@ -1274,7 +1294,7 @@ alice: \tBalance: 4.00""" self.assertEqual(res.stdout, msg) - compare_state("test/state.json_schedule_monthly") + compare_state("test/state_schedule_monthly.json") res = run_bot(self, num[alice], "!fuck") self.assertEqual(res.stdout, 'Nothing to rewind') @@ -1307,7 +1327,7 @@ alice: \tBalance: 6.00""" self.assertEqual(res.stdout, msg) - os.remove("test/state.json_schedule_monthly") + os.remove("test/state_schedule_monthly.json") def test_monthly_car(self): run_bot(self, num[alice], "!cars add fiat 0.5") |
