From 5871e64681e516e1681389ba73daeff2119de509 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 1 Oct 2017 09:43:33 +0200 Subject: [PATCH] Fix unittest for mail contrib update --- evennia/contrib/mail.py | 10 +++++----- evennia/contrib/tests.py | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/evennia/contrib/mail.py b/evennia/contrib/mail.py index 48369083d1..6e8585136d 100644 --- a/evennia/contrib/mail.py +++ b/evennia/contrib/mail.py @@ -133,7 +133,7 @@ class CmdMail(default_cmds.MuxCommand): return else: all_mail = self.get_all_mail() - mind_max = all_mail.count() - 1 + mind_max = max(0, all_mail.count() - 1) mind = max(0, min(mind_max, int(self.lhs) - 1)) if all_mail[mind]: all_mail[mind].delete() @@ -154,7 +154,7 @@ class CmdMail(default_cmds.MuxCommand): return else: all_mail = self.get_all_mail() - mind_max = all_mail.count() - 1 + mind_max = max(0, all_mail.count() - 1) if "/" in self.rhs: message_number, message = self.rhs.split("/", 1) mind = max(0, min(mind_max, int(message_number) - 1)) @@ -193,7 +193,7 @@ class CmdMail(default_cmds.MuxCommand): return else: all_mail = self.get_all_mail() - mind_max = all_mail.count() - 1 + mind_max = max(0, all_mail.count() - 1) mind = max(0, min(mind_max, int(self.lhs) - 1)) if all_mail[mind]: old_message = all_mail[mind] @@ -218,9 +218,9 @@ class CmdMail(default_cmds.MuxCommand): self.send_mail(self.search_targets(self.lhslist), subject, body, self.caller) else: all_mail = self.get_all_mail() - mind_max = all_mail.count() - 1 + mind_max = max(0, all_mail.count() - 1) try: - mind = max(0, min(mind_max, self.lhs - 1)) + mind = max(0, min(mind_max, int(self.lhs) - 1)) message = all_mail[mind] except (ValueError, IndexError): self.caller.msg("'%s' is not a valid mail id." % self.lhs) diff --git a/evennia/contrib/tests.py b/evennia/contrib/tests.py index 2342c4d17a..1678d06567 100644 --- a/evennia/contrib/tests.py +++ b/evennia/contrib/tests.py @@ -661,6 +661,7 @@ from evennia.contrib import mail class TestMail(CommandTest): def test_mail(self): self.call(mail.CmdMail(), "2", "'2' is not a valid mail id.", caller=self.account) + self.call(mail.CmdMail(), "test", "'test' is not a valid mail id.") self.call(mail.CmdMail(), "", "There are no messages in your inbox.", caller=self.account) self.call(mail.CmdMail(), "Char=Message 1", "You have received a new @mail from Char|You sent your message.", caller=self.char1) self.call(mail.CmdMail(), "Char=Message 2", "You sent your message.", caller=self.char2)