diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2022-07-06 09:48:14 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2022-07-06 10:18:39 +0200 |
| commit | 2fe86be4e3b999ec4941284274b586dd0f2fecb7 (patch) | |
| tree | 4784c380304d8d84809a4568dfcbb96da93665fd /test.py | |
| parent | 24c54bdc6a319bca554223b77851acd3e801e0c7 (diff) | |
| download | geldschieberbot-2fe86be4e3b999ec4941284274b586dd0f2fecb7.tar.gz geldschieberbot-2fe86be4e3b999ec4941284274b586dd0f2fecb7.zip | |
add alias support
Aliases can be used where one or multiple persons names can be used.
An alias is expanded to the list of users it represents.
For commands implicitly including one user (e.g., 'split') the expansion
of the implicit user can be prevented.
Diffstat (limited to 'test.py')
| -rwxr-xr-x | test.py | 96 |
1 files changed, 96 insertions, 0 deletions
@@ -419,6 +419,102 @@ alice: self.assertEqual(res.stdout, msg) +class TestAliasAdd(unittest.TestCase): + + def setUp(self): + reset_state("test/state_3users.json") + + def test_add_success(self): + res = run_bot(self, num[alice], f"!alias foo {alice} {bob}") + self.assertEqual(res.stdout, 'New alias "foo" registered') + + res = run_bot(self, num[alice], f"!alias bar {charlie}") + self.assertEqual(res.stdout, 'New alias "bar" registered') + + def test_add_invalid_aliases(self): + res = run_bot(self, num[alice], f"!alias foo {alice} {bob}") + self.assertEqual(res.stdout, 'New alias "foo" registered') + res = run_bot(self, num[alice], f"!alias foo {alice} {bob}") + self.assertEqual(res.stdout, + 'ERROR: Alias "foo" is already registered') + + res = run_bot(self, num[alice], f"!alias {alice} {alice} {bob}") + self.assertEqual(res.stdout, + f'ERROR: A user "{alice}" is already registered') + + res = run_bot(self, num[alice], f"!alias 13.23 {charlie}") + self.assertEqual(res.stdout, + 'ERROR: Pure numerical aliases are not allowed') + + res = run_bot(self, num[alice], "!alias bar ingo") + self.assertEqual(res.stdout, 'ERROR: User ingo is not registered') + + res = run_bot(self, num[alice], f"!alias all {alice}") + self.assertEqual(res.stdout, + 'ERROR: Alias "all" is already registered') + + +class TestAlias(unittest.TestCase): + + def setUp(self): + reset_state("test/state_3users.json") + + def test_list_aliases_empty_state(self): + res = run_bot(self, num[alice], "!alias") + self.assertEqual(res.stdout, f"""Aliases: +\tall: {alice} {bob} {charlie}""") + + def test_list_aliases(self): + run_bot(self, num[alice], f"!alias alob {alice} {bob}") + res = run_bot(self, num[alice], "!alias") + self.assertEqual( + res.stdout, f"""Aliases: +\tall: {alice} {bob} {charlie} +\talob: {alice} {bob}""") + + def test_add_invalid_aliases(self): + run_bot(self, num[alice], f"!alias foo {alice} {bob}") + res = run_bot(self, num[alice], f"!alias foo {alice} {bob}") + self.assertEqual(res.stdout, + 'ERROR: Alias "foo" is already registered') + + res = run_bot(self, num[alice], f"!alias {alice} {alice} {bob}") + self.assertEqual(res.stdout, + f'ERROR: A user "{alice}" is already registered') + + res = run_bot(self, num[alice], f"!alias 13.23 {charlie}") + self.assertEqual(res.stdout, + 'ERROR: Pure numerical aliases are not allowed') + + res = run_bot(self, num[alice], "!alias bar ingo") + self.assertEqual(res.stdout, 'ERROR: User ingo is not registered') + + res = run_bot(self, num[alice], f"!alias all {alice}") + self.assertEqual(res.stdout, + 'ERROR: Alias "all" is already registered') + + def test_split_all(self): + res = run_bot(self, num[alice], "!split 9 all") + self.assertEqual(res.stdout, \ +"""Split 9.00 between 3 -> 3.00 each +New Balance: +alice: +\t<- bob 3.00 +\t<- charlie 3.00 +\tBalance: 6.00""") + + def test_split_alias(self): + run_bot(self, num[alice], f"!alias alob {alice} {bob}") + res = run_bot(self, num[charlie], "!split 9 alob") + self.assertEqual(res.stdout, \ +"""Split 9.00 between 3 -> 3.00 each +New Balance: +charlie: +\t<- alice 3.00 +\t<- bob 3.00 +\tBalance: 6.00""") + + class TestCarsAdd(unittest.TestCase): def setUp(self): |
