예제 #1
0
 def test_good_attacker_invul_target(self):
     """ Good attacker invul target: p1a attacks p2c """
     attacker = self.p1a
     params = ["p2c"]
     with self.assertRaises(TargetError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "Your target is INVUL")
예제 #2
0
 def test_good_attacker_target_wrong_team(self):
     """ Target is on the wrong team """
     attacker = self.p1a
     params = ["p3b"]
     with self.assertRaises(TeamError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "Invalid Team. You cannot do that action to someone on that team.")
예제 #3
0
 def test_disarm_attacker_good_target(self):
     """ Disarm attacker good target: p1b attacks p2a """
     attacker = self.p1b
     params = ["p2a"]
     with self.assertRaises(MeError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "You are DISARM")
예제 #4
0
 def test_disarm_attacker_good_target(self):
     """ Disarm attacker good target: p1b attacks p2a """
     attacker = self.p1b
     params = ["p2a"]
     with self.assertRaises(MeError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "You are DISARM")
예제 #5
0
 def test_good_attacker_dead_target(self):
     """ Good attacker dead target: p1a attacks p2b """
     attacker = self.p1a
     params = ["p2b"]
     with self.assertRaises(TargetError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "Your target is DEAD")
예제 #6
0
 def test_good_attacker_invul_target(self):
     """ Good attacker invul target: p1a attacks p2c """
     attacker = self.p1a
     params = ["p2c"]
     with self.assertRaises(TargetError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "Your target is INVUL")
예제 #7
0
 def test_good_attacker_dead_target(self):
     """ Good attacker dead target: p1a attacks p2b """
     attacker = self.p1a
     params = ["p2b"]
     with self.assertRaises(TargetError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "Your target is DEAD")
예제 #8
0
 def test_dead_attacker_bad_target(self):
     """ Dead attacker dead target: p1a attack p2b """
     attacker = self.p1a
     attacker.state = "DEAD"
     attacker.put()
     params = ["p2b"]
     with self.assertRaises(MeError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "You are DEAD")
예제 #9
0
 def test_good_attacker_target_wrong_team(self):
     """ Target is on the wrong team """
     attacker = self.p1a
     params = ["p3b"]
     with self.assertRaises(TeamError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(
         e.exception.message,
         "Invalid Team. You cannot do that action to someone on that team.")
예제 #10
0
 def test_dead_attacker_bad_target(self):
     """ Dead attacker dead target: p1a attack p2b """
     attacker = self.p1a
     attacker.state = "DEAD"
     attacker.put()
     params = ["p2b"]
     with self.assertRaises(MeError) as e:
         Kill.handler(attacker, params)
     self.assertEqual(e.exception.message, "You are DEAD")
예제 #11
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)
예제 #12
0
 def test_good_attacker_good_target(self):
     """ Good attacker good target: p1a attacks p2a """
     attacker = self.p1a
     params = ["p2a"]
     ret = Kill.handler(attacker, params)
     self.assertEqual(1, len(ret))
     self.assertEqual("+4", ret[0][0])
     self.assertRegexpMatches(ret[0][1], \
             r"\[REPLY \d*\] player1a claimed to have killed you. Reply Y\/N.",\
             "Msg was: {}".format(ret[0][1]))
예제 #13
0
 def test_good_attacker_good_target(self):
     """ Good attacker good target: p1a attacks p2a """
     attacker = self.p1a
     params = ["p2a"]
     ret = Kill.handler(attacker, params)
     self.assertEqual(1, len(ret))
     self.assertEqual("+4", ret[0][0])
     self.assertRegexpMatches(ret[0][1], \
             r"\[REPLY \d*\] player1a claimed to have killed you. Reply Y\/N.",\
             "Msg was: {}".format(ret[0][1]))