Beispiel #1
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")
Beispiel #2
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")
Beispiel #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")
Beispiel #4
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.")
Beispiel #5
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")
Beispiel #6
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")
Beispiel #7
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")
Beispiel #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")
Beispiel #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.")
Beispiel #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")
Beispiel #11
0
 def test_kill_reply_y(self):
     """ Kill reply y response """
     ret = Kill.reply_handler(self.action, "y")
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0][0], "*")
     self.assertEqual(ret[0][1], "p2a has been killed")
     self.assertEqual(self.p2a.state, "DEAD")
Beispiel #12
0
 def test_kill_reply_y(self):
     """ Kill reply y response """
     ret = Kill.reply_handler(self.action, "y")
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0][0], "*")
     self.assertEqual(ret[0][1], "p2a has been killed")
     self.assertEqual(self.p2a.state, "DEAD")
Beispiel #13
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)
Beispiel #14
0
 def test_kill_reply_n(self):
     """ Kill reply n response """
     ret = Kill.reply_handler(self.action, "n")
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0][0], "+1")
     self.assertEqual(ret[0][1], "Your victim claims that he/she was not "
         "killed. Please check that you have the correct codename")
     self.assertEqual(self.p2a.state, "ALIVE")
Beispiel #15
0
    def handler(cls, attacker, victim_codename):
        logging.info("SNIPE start.")

        victim = Util.get_victim(victim_codename)

        logging.info("Attacker {}".format(attacker))
        logging.info("Victim {}".format(victim))

        """ validation """
        outgoing = []
        try:
            Kill.validate_kill(attacker, victim)
            if attacker.role != "SNIPER":
                raise MeError("not SNIPER")
        except (TeamError, MeError, TargetError) as message:
            outgoing.append((WEI_HAN, message.message))
            outgoing.append((attacker.key.id(), message.message))
            return outgoing
        except:
            message = "[ERR] Unknown Error in SNIPE"
            outgoing.append((WEI_HAN, message))
            outgoing.append((attacker.key.id(), message))
            return outgoing

        action = Action()
        action.attacker = attacker.key.id()
        action.action = "SNIPE"
        action.victim = victim.key.id()
        action.datetime = datetime.now()
        action_key = action.put()

        attacker = Player.get_by_id(action.attacker)
        attacker.killed.append(str(action_key.id()))
        attacker.put()

        victim.state = "DEAD"
        victim.killed_by = str(action_key.id())
        victim.put()

        message = "{} has been SNIPED.".format(victim_codename)
        outgoing.append((victim.key.id(), "You have been SNIPED. (Ref {}).".\
                format(action_key.id())))
        outgoing.append(("*", message))
        outgoing += Team.push(Team.get_by_id(victim.team))
        return outgoing
Beispiel #16
0
 def test_kill_reply_n(self):
     """ Kill reply n response """
     ret = Kill.reply_handler(self.action, "n")
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0][0], "+1")
     self.assertEqual(
         ret[0][1], "Your victim claims that he/she was not "
         "killed. Please check that you have the correct codename")
     self.assertEqual(self.p2a.state, "ALIVE")
Beispiel #17
0
    def handler(cls, attacker, victim_codename):
        logging.info("SNIPE start.")

        victim = Util.get_victim(victim_codename)

        logging.info("Attacker {}".format(attacker))
        logging.info("Victim {}".format(victim))
        """ validation """
        outgoing = []
        try:
            Kill.validate_kill(attacker, victim)
            if attacker.role != "SNIPER":
                raise MeError("not SNIPER")
        except (TeamError, MeError, TargetError) as message:
            outgoing.append((WEI_HAN, message.message))
            outgoing.append((attacker.key.id(), message.message))
            return outgoing
        except:
            message = "[ERR] Unknown Error in SNIPE"
            outgoing.append((WEI_HAN, message))
            outgoing.append((attacker.key.id(), message))
            return outgoing

        action = Action()
        action.attacker = attacker.key.id()
        action.action = "SNIPE"
        action.victim = victim.key.id()
        action.datetime = datetime.now()
        action_key = action.put()

        attacker = Player.get_by_id(action.attacker)
        attacker.killed.append(str(action_key.id()))
        attacker.put()

        victim.state = "DEAD"
        victim.killed_by = str(action_key.id())
        victim.put()

        message = "{} has been SNIPED.".format(victim_codename)
        outgoing.append((victim.key.id(), "You have been SNIPED. (Ref {}).".\
                format(action_key.id())))
        outgoing.append(("*", message))
        outgoing += Team.push(Team.get_by_id(victim.team))
        return outgoing
Beispiel #18
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]))
Beispiel #19
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]))
Beispiel #20
0
    def handler(cls, ref, params, From):
        logging.debug("REPLY {}".format(ref))
        lookup = Action.get_by_id(int(ref))
        if not lookup:
            raise ReplyError("ref num", ref)

        response = params[0]
        if response != "Y" and response != "y" and response != "N" and response != "n":
            raise ReplyError(response, ref)

        if lookup.action == "DISARM":
            return Disarm.reply_handler(lookup, response)
        else:
            output_msg = []
            if lookup.action == "KILL":
                output_msg += Kill.reply_handler(lookup, response)
            elif lookup.action == "BOMB":
                output_msg += Bomb.reply_handler(lookup, response, From)
            """ Generate push if necessary """
            output_msg += Team.push(Team.get_by_id(From.team))
            return output_msg
        raise ReplyError(response, ref)