Example #1
0
 def test_good_invul(self):
     """ GOOD test """
     medic = self.p1c
     now = Util.utc_to_chi(datetime.now())
     params = self.default_params
     Invul.handler(medic, params)
     self.assertEqual(len(self.invul_queue),1)
Example #2
0
 def test_not_same_team(self):
     """ MEDIC can only INVUL same team """
     medic = self.p1c
     params = self.default_params
     with self.assertRaises(TeamError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, \
             "Invalid Team. You cannot do that action to someone on that team.")
     self.assertEqual(len(self.invul_queue), 0)
Example #3
0
 def test_invul_not_medic(self):
     """ INVUL command must come from medic """
     medic = self.p1a
     params = self.default_params 
     params[0] = "p1c"
     with self.assertRaises(MeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You are not MEDIC")
     self.assertEqual(len(self.invul_queue), 0)
Example #4
0
 def test_invul_medic_not_alive(self):
     """ MEDIC must be arrive when invoking command """
     medic = self.p1c
     medic.state = "DEAD"
     medic.put()
     params = self.default_params
     with self.assertRaises(MeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You are DEAD")
     self.assertEqual(len(self.invul_queue), 0)
Example #5
0
 def test_invul_error_time_before_valid_time(self):
     """ MEDIC can only INVUL one person per 24 hour period """
     medic = self.p1c
     medic.can_set_after = Util.next_day()
     medic.put()
     params = self.default_params
     with self.assertRaises(TimeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You cannot set invul before time {}."\
             .format(Util.utc_to_chi(medic.can_set_after).strftime("%m-%d %I:%M%p")))
     self.assertEqual(len(self.invul_queue), 0)
Example #6
0
 def test_invul_target_not_alive(self):
     """ Target must be alive """
     medic = self.p1c
     target = self.p1a
     target.state = "DEAD"
     target.put()
     params = self.default_params
     with self.assertRaises(TargetError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "Your target is DEAD")
     self.assertEqual(len(self.invul_queue), 0)
Example #7
0
 def test_invul_error_time_before_now(self):
     """ MEDIC can only INVUL a time in the future """
     medic = self.p1c
     now = Util.utc_to_chi(datetime.now()) - timedelta(hours=1)
     params = ["p1a", str(now.month), str(now.day),\
             str(now.hour), str(now.minute)]
     with self.assertRaises(TimeError) as e:
         Invul.handler(medic, params)
     self.assertEqual(e.exception.message, "You cannot set {} before time {}."\
             .format(now.strftime("%m-%d %I:%M%p"),\
             Util.utc_to_chi(datetime.now()).strftime("%m-%d %I:%M%p")))
     self.assertEqual(len(self.invul_queue), 0)
Example #8
0
    def inner_handler(cls, message):
        """ Return [(number, msg),...]"""
        action, params = CommandHandler.get_command(message.Body)
        attacker = Util.get_attacker(message.From)

        if action == "KILL":
            return Kill.handler(attacker, params)
        elif action[1:] == "REPLY":
            ref = params.pop(0)[:-1]
            return Reply.handler(ref, params, attacker)
        elif action == "BOMB":
            return Bomb.handler(attacker, params)
        elif action == "INVUL":
            return Invul.handler(attacker, params)
        elif action == "DISARM":
            return Disarm.handler(attacker, params)
        elif action == "SNIPE":
            if message.From != WEI_HAN:
                raise CommandError(action)
            sniper = Player.query(Player.codename == params[0]).get()
            if sniper == None:
                raise DbError(params[0])
            return Snipe.handler(sniper, params[1])
        elif action == "?":
            msg = "Guide for SAMSU Assassins:\n"
            msg += "KILL <target codename>\n"
            msg += "BOMB <mm> <dd> <hour> <min> <place>\n"
            msg += "INVUL <target codename> <mm> <dd> <hour> <min>\n"
            msg += "DISARM <target codename>\n"
            msg += "SNIPE - send message and picture to {}\n".format(WEI_HAN)
            msg += "REPLY - [REPLY <number>] Y or [REPLY <number>] N\n"
            msg += "If you receive an UNKNOWN ERROR or don't get a message that you expect, contact Wei Han at 312-731-0539."
            return [(attacker.key.id(), msg)]
        else:
            raise CommandError(action)