Esempio n. 1
0
class GetRewardTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetReward test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getReward"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'GetReward test complete.....close socket'

    def test_get_reward_normal(self):
        """
        获取悬赏令信息:普通悬赏令,被悬赏者被攻击后,剩余悬赏攻击次数-1\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        res = self.ar_con3.get_user_coin()
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        res = self.ar_con3.upgrade_pet_part(part_3)
        res_data = json.loads(res)
        coin_after = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用者通缉攻击者:"
        self.ar_con.get_rev()
        self.ar_con.reward_player(0, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(5), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(0), "response left_times mismatch...")
        assert_that(res_data, has_key("total_toll"), "no total_toll response...")
        assert_that(res_data["total_toll"], equal_to(0), "response total_toll mismatch...")
        assert_that(res_data, has_key("total_attack"), "no total_attack response...")
        assert_that(res_data["total_attack"], equal_to(0), "response total_attack mismatch...")

        print "悬赏令使用者自己攻击被悬赏者:"
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.attack_pet(part_3, user_id_3, reward_id)
        self.ar_con.get_rev()
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(4), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(0), "response left_times mismatch...")
        assert_that(res_data, has_key("total_toll"), "no total_toll response...")
        assert_that(res_data["total_toll"], equal_to(int((coin_before-coin_after)*0.5)), "response total_toll mismatch...")
        assert_that(res_data, has_key("total_attack"), "no total_attack response...")
        assert_that(res_data["total_attack"], equal_to(1), "response total_attack mismatch...")

    def test_get_reward_advance(self):
        """
        获取悬赏令信息:高级悬赏令\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.get_user_coin()
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        res = self.ar_con3.upgrade_pet_part(part_3)
        res_data = json.loads(res)
        coin_after = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用者通缉攻击者,并攻击:"
        self.ar_con.get_rev()
        self.ar_con.reward_player(1, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.pm_set_role_data("lotteryType", 104)
        self.ar_con.attack_pet(part_3, user_id_3, reward_id)
        self.ar_con.get_rev()
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(9), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(1), "response left_times mismatch...")
        assert_that(res_data, has_key("total_toll"), "no total_toll response...")
        assert_that(res_data["total_toll"], equal_to(int((coin_before - coin_after) * 0.5)),
                    "response total_toll mismatch...")
        assert_that(res_data, has_key("total_attack"), "no total_attack response...")
        assert_that(res_data["total_attack"], equal_to(1), "response total_attack mismatch...")

    def test_get_reward_others(self):
        """
        获取悬赏令信息:获取其他玩家悬赏令信息\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用者通缉攻击者:"
        self.ar_con.get_rev()
        self.ar_con.reward_player(1, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]

        print "创建其他玩家:"
        account_id_4 = CoRand.get_rand_int(100001)
        uc_id_4 = CoRand.get_rand_int()
        self.ar_con4 = ARControl()
        self.ar_con4.connect_server()
        res = self.ar_con4.login(account_id_4, "im", uc_id_4)
        res_data = json.loads(res)
        user_id_4 = res_data["user_id"]
        nick_name_4 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con4.modify_info(nick_name_4)
        res = self.ar_con4.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(10), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(1), "response left_times mismatch...")

    def test_get_reward_error_reward_id(self):
        """
        获取悬赏令信息:错误的reward_id\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        reward_id = CoRand.get_rand_int()
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_INVALID_REQUEST_PARAM["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]), "response msg mismatching...")

    def test_get_reward_without_params(self):
        """
        获取悬赏令信息:未传参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        json_body = {}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_INVALID_REQUEST_PARAM["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]), "response msg mismatching...")

    def test_get_reward_add_reward(self):
        """
        获取悬赏令信息--获取追加悬赏令信息\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "悬赏令使用者登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用者使用普通通缉令通缉攻击者:"
        self.ar_con.get_rev()
        res = self.ar_con.reward_player(0, user_id_3)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        self.ar_con.get_enemy_list()
        print "追加高级悬赏令:"
        self.ar_con.reward_player(1, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.evil_rank_list(0)
        # print "悬赏令使用者自己攻击被悬赏者:"
        # self.sql = ModifySql()
        # self.sql.update_user(user_id_1, "lottery_type", 104)
        # self.ar_con.gm_reload_user_data(user_id_1)
        # self.ar_con.attack_pet(part_3, user_id_3, reward_id)
        # self.ar_con.get_rev()
        print"获取悬赏令信息:"
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)

        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(15), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(0), "response left_times mismatch...")

    def test_get_reward_add_reward_attack(self):
        """
        获取悬赏令信息--获取追加悬赏令信息,包含追加前和追加后的信息\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "悬赏令使用者A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "A同意添加好友B:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)

        print "B收到消息:"
        self.ar_con2.get_rev()
        print "创建好友玩家D:"
        account_id_4 = CoRand.get_rand_int(100001)
        uc_id_4 = CoRand.get_rand_int()
        self.ar_con4 = ARControl()
        self.ar_con4.connect_server()
        res = self.ar_con4.login(account_id_4, "im", uc_id_4)
        res_data = json.loads(res)
        user_id_4 = res_data["user_id"]
        nick_name_4 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con4.modify_info(nick_name_4)
        self.ar_con4.add_friend(user_id_1)
        print "A同意添加好友D:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_4, 1)

        print "D收到消息:"
        self.ar_con4.get_rev()

        print "创建攻击者玩家C:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "A使用普通通缉令通缉C:"
        self.ar_con.get_rev()
        res = self.ar_con.reward_player(0, user_id_3)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.evil_rank_list(0)
        print "好友玩家B收到消息,攻击被悬赏者C:"
        self.ar_con2.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con2.attack_pet(part_3, user_id_3, reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(300000), "response win_coin mismatch...")
        assert_that(res_data, has_key("reward_coin"), "no reward_coin response...")
        assert_that(res_data["reward_coin"], equal_to(300000), "response reward_coin mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(coin_before + 600000), "response reward_coin mismatch...")
        print"A获取悬赏令信息:"
        time.sleep(1)
        self.ar_con.get_rev()
        res = self.ar_con.get_reward_attack(reward_id)
        res_data = json.loads(res)

        assert_that(res_data[0], has_key("attack_time"), "no attack_time response...")
        assert_that(res_data[0], has_key("user_id"), "no user_id response...")
        assert_that(res_data[0]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data[0], has_key("nick_name"), "no nick_name response...")
        assert_that(res_data[0]["nick_name"], equal_to(nick_name_2), "response nick_name mismatch...")
        assert_that(res_data[0], has_key("toll"), "no toll response...")

        print "A追加高级悬赏令:"
        self.ar_con.reward_player(1, user_id_3)
        print "好友玩家D收到消息,攻击被悬赏者C:"
        self.ar_con4.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "guidance", 131071)
        self.ar_con4.gm_reload_user_data(user_id_4)
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "lottery_type", 104)
        self.ar_con4.gm_reload_user_data(user_id_4)
        res = self.ar_con4.attack_pet(part_3, user_id_3, reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(300000), "response win_coin mismatch...")
        assert_that(res_data, has_key("reward_coin"), "no reward_coin response...")
        assert_that(res_data["reward_coin"], equal_to(300000), "response reward_coin mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")

        # print "A自己攻击被悬赏者C:"
        # self.sql = ModifySql()
        # self.sql.update_user(user_id_1, "lottery_type", 104)
        # self.ar_con.gm_reload_user_data(user_id_1)
        # res = self.ar_con.attack_pet(part_3, user_id_3, reward_id)
        # res_data = json.loads(res)
        # assert_that(res_data[0], has_key("reward_coin"), "no reward_coin response...")
        # assert_that(res_data[0]["reward_coin"], equal_to(300000), "response reward_coin mismatch...")
        self.ar_con.get_rev()
        print"获取悬赏令信息:"
        time.sleep(1)
        res = self.ar_con.get_reward_attack(reward_id)
        res_data = json.loads(res)

        assert_that(res_data[0], has_key("attack_time"), "no attack_time response...")
        assert_that(res_data[0], has_key("user_id"), "no user_id response...")
        assert_that(res_data[0]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data[0], has_key("nick_name"), "no nick_name response...")
        assert_that(res_data[0]["nick_name"], equal_to(nick_name_2), "response nick_name mismatch...")
        assert_that(res_data[0], has_key("toll"), "no toll response...")
        assert_that(res_data[1], has_key("attack_time"), "no attack_time response...")
        assert_that(res_data[1], has_key("user_id"), "no user_id response...")
        assert_that(res_data[1]["user_id"], equal_to(user_id_4), "response user_id mismatch...")
        assert_that(res_data[1], has_key("nick_name"), "no nick_name response...")
        assert_that(res_data[1]["nick_name"], equal_to(nick_name_4), "response nick_name mismatch...")
        assert_that(res_data[1], has_key("toll"), "no toll response...")

    def test_get_reward_total_toll_statistics(self):
        """
        获取悬赏令信息--验证累计损失、累计攻击次数数据正确性\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "悬赏令使用者A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "A同意添加好友B:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)

        print "B收到消息:"
        self.ar_con2.get_rev()
        print "创建好友玩家D:"
        account_id_4 = CoRand.get_rand_int(100001)
        uc_id_4 = CoRand.get_rand_int()
        self.ar_con4 = ARControl()
        self.ar_con4.connect_server()
        res = self.ar_con4.login(account_id_4, "im", uc_id_4)
        res_data = json.loads(res)
        user_id_4 = res_data["user_id"]
        nick_name_4 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con4.modify_info(nick_name_4)
        self.ar_con4.add_friend(user_id_1)
        print "A同意添加好友D:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_4, 1)

        print "D收到消息:"
        self.ar_con4.get_rev()

        print "创建攻击者玩家C:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.get_user_coin()
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)

        part_attacker_1 = 1
        res = self.ar_con3.upgrade_pet_part(part_attacker_1)
        res_data = json.loads(res)
        coin_part_1_level_1 = coin_before - res_data["coin"]

        res = self.ar_con3.upgrade_pet_part(part_attacker_1)
        res_data = json.loads(res)
        coin_part_1_level_2 = coin_before - res_data["coin"] - coin_part_1_level_1

        part_attacker_2 = 2
        res = self.ar_con3.upgrade_pet_part(part_attacker_2)
        res_data = json.loads(res)
        coin_part_2_level_1 = coin_before - res_data["coin"] - coin_part_1_level_1 - coin_part_1_level_2

        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "A使用普通通缉令通缉C:"
        self.ar_con.get_rev()
        res = self.ar_con.reward_player(0, user_id_3)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.evil_rank_list(0)

        print "好友玩家B收到消息,攻击被悬赏者C,打坏部件2:"
        self.ar_con2.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.pm_set_role_data("lotteryType", 104)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con2.attack_pet(part_attacker_2, user_id_3, reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(300000), "response win_coin mismatch...")
        assert_that(res_data, has_key("reward_coin"), "no reward_coin response...")
        assert_that(res_data["reward_coin"], equal_to(300000), "response reward_coin mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(coin_before + 600000), "response reward_coin mismatch...")
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_part_2_level_1*0.5)))

        print "好友玩家D收到消息,攻击被悬赏者C,打坏部件1:"
        self.ar_con4.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "guidance", 131071)
        self.ar_con4.gm_reload_user_data(user_id_4)
        self.ar_con4.pm_set_role_data("lotteryType", 104)
        self.ar_con4.attack_pet(part_attacker_1, user_id_3, reward_id)
        print "A收到消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_part_1_level_2 * 0.5)))
        print "好友玩家D再次攻击被悬赏者C,打爆部件1:"
        self.ar_con4.pm_set_role_data("lotteryType", 104)
        self.ar_con4.attack_pet(part_attacker_1, user_id_3, reward_id)
        print "A收到消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_part_1_level_2 * 0.5)+coin_part_1_level_1))

        print "A自己攻击被悬赏者C,打爆部件2:"
        self.ar_con.pm_set_role_data("lotteryType", 104)
        self.ar_con.attack_pet(part_attacker_2, user_id_3, reward_id)
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_part_2_level_1*0.5)))
        print"获取悬赏令信息:"
        time.sleep(1)
        res = self.ar_con.get_reward(reward_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("end_time"), "no end_time response...")
        assert_that(res_data, has_key("left_times"), "no left_times response...")
        assert_that(res_data["left_times"], equal_to(1), "response left_times mismatch...")
        assert_that(res_data, has_key("reward_type"), "no left_times response...")
        assert_that(res_data["reward_type"], equal_to(0), "response left_times mismatch...")
        assert_that(res_data, has_key("total_toll"), "no total_toll response...")
        assert_that(res_data["total_toll"], equal_to(coin_part_1_level_1+coin_part_1_level_2+coin_part_2_level_1), "response total_toll mismatch...")
        assert_that(res_data, has_key("total_attack"), "no total_attack response...")
        assert_that(res_data["total_attack"], equal_to(4), "response total_attack mismatch...")
class GetRichPlayerListTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetRichPlayerList test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getRichPlayerList"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'GetRichPlayerList test complete.....close socket'

    def test_get_rich_player_list_no_steal(self):
        """
        获取富豪列表--未抽中偷袭\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ALLOW_STEAL["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ALLOW_STEAL["err_msg"]),
                    "response msg mismatching...")

    def test_get_rich_player_list_success(self):
        """
        获取富豪列表--获取8位玩家,富豪金币>=10w,富豪金币>其余玩家金币>=1w,排除玩家本人\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        assert res_data != []
        user_ids = []
        coins = []
        for i in res_data:
            assert_that(i, has_key("nick_name"), "no nick_name response...")
            assert_that(i, has_key("name"), "no name response...")
            assert_that(i, has_key("icon"), "no icon response...")
            assert_that(i, has_key("has_glass"), "no has_glass response...")
            assert_that(i, has_key("head_status"),
                        "no head_status response...")
            assert_that(i, has_key("head_level"), "no head_level response...")
            assert_that(i, has_key("arm_status"), "no arm_status response...")
            assert_that(i, has_key("arm_level"), "no arm_level response...")
            assert_that(i, has_key("clothes_status"),
                        "no clothes_status response...")
            assert_that(i, has_key("clothes_level"),
                        "no clothes_level response...")
            assert_that(i, has_key("skirt_status"),
                        "no skirt_status response...")
            assert_that(i, has_key("skirt_level"),
                        "no skirt_level response...")
            assert_that(i, has_key("shoes_status"),
                        "no shoes_status response...")
            assert_that(i, has_key("shoes_level"),
                        "no shoes_level response...")
            assert_that(i, has_key("pet_code"), "no pet_code response...")
            assert_that(i, has_key("pet_id"), "no pet_id response...")
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
            res_info = self.ar_con.get_user_info(i["user_id"])
            res_info_data = json.loads(res_info)
            coins.append(res_info_data["coin"])
            assert_that(res_info_data, has_key("pet_idx"),
                        "no pet_idx response...")
            assert_that(res_info_data["pet_idx"], not_(0),
                        "response pet_idx mismatch...")
        coin_max = max(coins)
        coin_min = min(coins)
        assert_that(coin_max, greater_than(100000),
                    "response coin less than 10w...")
        assert_that(coin_min, greater_than_or_equal_to(10000),
                    "response coin less than 1w...")
        assert user_id not in user_ids
        assert_that(res_data, has_length(4), "response length mismatch...")

    def test_get_rich_player_list_friend_rich(self):
        """
        获取富豪列表--有好友金币>10w,抽取概率好友50%、陌生人50%\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con2.capture_pet(pet_id)
        self.ar_con2.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part)
        print "创建好友玩家B:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.add_friend(user_id_2)
        print "A同意添加好友:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "B执行50次获取富豪操作:"
        self.ar_con.get_rev()
        friend_num = 0
        rand_num = 0
        for i in range(0, 50):
            user_total_ids = []
            coins = []
            self.sql = ModifySql()
            self.sql.update_user(user_id_1, "lottery_type", 105)
            self.ar_con.gm_reload_user_data(user_id_1)
            res = self.ar_con.get_rich_player_list()
            res_data = json.loads(res)
            for j in res_data:
                assert_that(j, has_key("user_id"), "no user_id response...")
                user_total_ids.append(j["user_id"])
                res_info = self.ar_con.get_user_info(j["user_id"])
                res_info_data = json.loads(res_info)
                coins.append(res_info_data["coin"])
            print user_total_ids
            if user_id_2 in user_total_ids:
                friend_num += 1
            else:
                rand_num += 1
            rich_user_index = coins.index(max(coins))
            rich_user_id = user_total_ids[rich_user_index]
            user_ids = [rich_user_id]
            self.ar_con.catch_player_list(user_ids)
            self.sql = ModifySql()
            self.sql.update_user(user_id_2, "coin", 1000000)
            self.ar_con2.gm_reload_user_data(user_id_2)
        print "转盘50次,抽中好友次数:" + str(friend_num)
        print "转盘50次,抽中随机玩家次数:" + str(rand_num)
        # assert_that(abs(friend_num-rand_num), less_than(10), "draw probability mismatch")

    def test_get_rich_player_list_friend_poor(self):
        """
        获取富豪列表--好友金币<10w,从陌生人中随机抽取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "coin", 100)
        self.ar_con2.gm_reload_user_data(user_id_2)
        print "创建好友玩家B:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.add_friend(user_id_2)
        print "A同意添加好友:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "B获取富豪列表:"
        self.ar_con.get_rev()
        user_ids = []
        for i in range(0, 10):
            self.sql = ModifySql()
            self.sql.update_user(user_id_1, "lottery_type", 105)
            self.ar_con.gm_reload_user_data(user_id_1)
            res = self.ar_con.get_rich_player_list()
            res_data = json.loads(res)
            for j in res_data:
                assert_that(j, has_key("user_id"), "no user_id response...")
                user_ids.append(j["user_id"])
        print user_ids
        assert user_id_2 not in user_ids

    def test_get_rich_player_list_not_catch_rich_third(self):
        """
        捕捉富豪--第一次未捕捉到富豪,第二三次获取富豪列表仍是同一个富豪,第四次重新获取富豪\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        print "第一次获取富豪列表"
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        user_total_ids = []
        coins = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_total_ids.append(i["user_id"])
            res_info = self.ar_con.get_user_info(i["user_id"])
            res_info_data = json.loads(res_info)
            coins.append(res_info_data["coin"])
        #   获取富豪和非富豪的user_id和coin
        rich_user_index_1 = coins.index(max(coins))
        rich_user_id_1 = user_total_ids[rich_user_index_1]
        poor_user_index_1 = coins.index(min(coins))
        poor_user_id_1 = user_total_ids[poor_user_index_1]
        user_ids_1 = [poor_user_id_1]
        if poor_user_id_1 != rich_user_id_1:
            print "第一次获取富豪id是:" + str(rich_user_id_1)
            print "第一次捕捉非富豪:"
            self.ar_con.catch_player_list(user_ids_1)
            print "第二次获取富豪列表:"
            self.sql = ModifySql()
            self.sql.update_user(user_id, "lottery_type", 105)
            self.ar_con.gm_reload_user_data(user_id)
            res = self.ar_con.get_rich_player_list()
            res_data = json.loads(res)
            user_total_ids = []
            coins = []
            for i in res_data:
                assert_that(i, has_key("user_id"), "no user_id response...")
                user_total_ids.append(i["user_id"])
                res_info = self.ar_con.get_user_info(i["user_id"])
                res_info_data = json.loads(res_info)
                coins.append(res_info_data["coin"])
            # 获取富豪和非富豪的user_id和coin
            rich_user_index_2 = coins.index(max(coins))
            rich_user_id_2 = user_total_ids[rich_user_index_2]
            poor_user_index_2 = coins.index(min(coins))
            poor_user_id_2 = user_total_ids[poor_user_index_2]
            user_ids_2 = [poor_user_id_2]
            res = self.ar_con.get_user_info(rich_user_id_1)
            res_data = json.loads(res)
            assert_that(res_data, has_key("coin"), "no coin response...")
            if res_data["coin"] >= 100000:
                assert_that(rich_user_id_2, equal_to(rich_user_id_1),
                            "rich user changed...")
                if poor_user_id_2 != rich_user_id_2:
                    print "第二次获取富豪id是:" + str(rich_user_id_2)
                    print "第二次捕捉非富豪:"
                    self.ar_con.catch_player_list(user_ids_2)
                    print "第三次获取富豪列表:"
                    self.sql = ModifySql()
                    self.sql.update_user(user_id, "lottery_type", 105)
                    self.ar_con.gm_reload_user_data(user_id)
                    res = self.ar_con.get_rich_player_list()
                    res_data = json.loads(res)
                    user_total_ids = []
                    coins = []
                    for i in res_data:
                        assert_that(i, has_key("user_id"),
                                    "no user_id response...")
                        user_total_ids.append(i["user_id"])
                        res_info = self.ar_con.get_user_info(i["user_id"])
                        res_info_data = json.loads(res_info)
                        coins.append(res_info_data["coin"])
                    rich_user_index_3 = coins.index(max(coins))
                    rich_user_id_3 = user_total_ids[rich_user_index_3]
                    poor_user_index_3 = coins.index(min(coins))
                    poor_user_id_3 = user_total_ids[poor_user_index_3]
                    user_ids_3 = [poor_user_id_3]
                    res = self.ar_con.get_user_info(rich_user_id_1)
                    res_data = json.loads(res)
                    assert_that(res_data, has_key("coin"),
                                "no coin response...")
                    if res_data["coin"] >= 100000:
                        assert_that(rich_user_id_3, equal_to(rich_user_id_1),
                                    "rich user changed...")
                        if poor_user_id_3 != rich_user_id_3:
                            print "第三次获取富豪id是:" + str(rich_user_id_3)
                            print "第三次捕捉非富豪:"
                            self.ar_con.catch_player_list(user_ids_3)
                            print "第四次获取富豪列表:"
                            self.sql = ModifySql()
                            self.sql.update_user(user_id, "lottery_type", 105)
                            self.ar_con.gm_reload_user_data(user_id)
                            res = self.ar_con.get_rich_player_list()
                            res_data = json.loads(res)
                            user_total_ids = []
                            coins = []
                            for i in res_data:
                                assert_that(i, has_key("user_id"),
                                            "no user_id response...")
                                user_total_ids.append(i["user_id"])
                                res_info = self.ar_con.get_user_info(
                                    i["user_id"])
                                res_info_data = json.loads(res_info)
                                coins.append(res_info_data["coin"])
                            rich_user_index_4 = coins.index(max(coins))
                            rich_user_id_4 = user_total_ids[rich_user_index_4]
                            print "第四次获取富豪id是:" + str(rich_user_id_4)
                            assert_that(rich_user_id_4, not_(rich_user_id_1),
                                        "rich user not change...")
Esempio n. 3
0
class AttackPetTest(unittest.TestCase):
    def setUp(self):
        print 'start run AttackPet test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "attackPet"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"
        self.total_part_name = ["head", "arm", "clothes", "skirt", "shoes"]

    def tearDown(self):
        print 'AttackPet test complete.....close socket'

    def test_attack_pet_no_attack(self):
        """
        攻击玩家未抽取到攻击卡\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()

        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ALLOW_ATTACK["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ALLOW_ATTACK["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_no_shield(self):
        """
        被攻击玩家无护盾,攻击玩家获得300000金币\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()

        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(300000),
                    "response coin mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(1), "response star mismatch...")
        assert_that(res_data, has_key("reward_coin"),
                    "no reward_coin response...")
        assert_that(res_data["reward_coin"], equal_to(0),
                    "response reward_coin mismatch...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(0),
                    "response shield mismatch...")

    def test_attack_pet_has_shield(self):
        """
        被攻击玩家有护盾,攻击玩家获得100000金币\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "shield", 1)
        self.ar_con.gm_reload_user_data(user_id_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)

        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(100000),
                    "response coin mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(1), "response star mismatch...")
        assert_that(res_data, has_key("reward_coin"),
                    "no reward_coin response...")
        assert_that(res_data["reward_coin"], equal_to(0),
                    "response reward_coin mismatch...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(2),
                    "response shield mismatch...")

    def test_attack_pet_first_attack(self):
        """
        部件第一次被攻击,星章数不变,部件等级不变,仍为可攻击状态\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        res = self.ar_con.upgrade_pet_part(part)
        res_data = json.loads(res)
        user1_coin_before = res_data["coin"]
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        user2_coin_before = res_data["coin"]
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        win_coin = res_data["win_coin"]
        assert_that(res_data["coin"], equal_to(user2_coin_before + win_coin),
                    "response coin mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(1), "response star mismatch...")
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        res = self.ar_con.get_user_info(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["can_attack"], equal_to(1),
                    "response can_attack mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(user1_coin_before),
                    "response coin mismatch...")

        res = self.ar_con.get_pet_info(pet_id, user_id_1)
        res_data = json.loads(res)
        attack_part_status = self.total_part_name[part - 1] + "_status"
        attack_part_level = self.total_part_name[part - 1] + "_level"
        assert_that(res_data, has_key(attack_part_status),
                    "no attack_part_name response...")
        assert_that(res_data[attack_part_status], equal_to(1),
                    "response attack_part_name mismatch...")
        assert_that(res_data, has_key(attack_part_level),
                    "no attack_part_level response...")
        assert_that(res_data[attack_part_level], equal_to(1),
                    "response attack_part_level mismatch...")

    def test_attack_pet_twice(self):
        """
        同部件两次被攻击,部件等级重置为0,星章数-1\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家1:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        res = self.ar_con.upgrade_pet_part(part)
        res_data = json.loads(res)
        user1_coin_before = res_data["coin"]
        print "创建玩家2两次攻击1:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        self.ar_con.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        assert_that(res_data["win_coin"], equal_to(300000),
                    "response coin mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(0), "response star mismatch...")
        print "玩家1查看宠物信息:"
        self.ar_con.get_rev()
        res = self.ar_con.get_user_info(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["can_attack"], equal_to(0),
                    "response can_attack mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(user1_coin_before),
                    "response coin mismatch...")

        res = self.ar_con.get_pet_info(pet_id, user_id_1)
        res_data = json.loads(res)
        attack_part_status = self.total_part_name[part - 1] + "_status"
        attack_part_level = self.total_part_name[part - 1] + "_level"
        assert_that(res_data, has_key(attack_part_status),
                    "no attack_part_name response...")
        assert_that(res_data[attack_part_status], equal_to(0),
                    "response attack_part_name mismatch...")
        assert_that(res_data, has_key(attack_part_level),
                    "no attack_part_level response...")
        assert_that(res_data[attack_part_level], equal_to(0),
                    "response attack_part_level mismatch...")

    def test_attack_pet_third(self):
        """
        同部件已两次被攻击,无法再次攻击\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_PLAYER_BE_PROTECTED["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_PLAYER_BE_PROTECTED["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_part_level_0(self):
        """
        攻击0级部位\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_PLAYER_BE_PROTECTED["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_PLAYER_BE_PROTECTED["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_user_not_have_pet(self):
        """
        攻击--被攻击玩家没有宠物\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        part = CoRand.get_rand_int(1, 5)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_PLAYER_BE_PROTECTED["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_PLAYER_BE_PROTECTED["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_self(self):
        """
        玩家攻击自己\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.attack_pet(part, user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_PLAYER_BE_PROTECTED["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_PLAYER_BE_PROTECTED["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_without_param(self):
        """
        攻击失败,未传参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id)
        json_body = {}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_USER_NOT_EXIST["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_USER_NOT_EXIST["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_without_user_id(self):
        """
        攻击失败,未传user_id参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id)
        json_body = {"part": 1}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_USER_NOT_EXIST["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_USER_NOT_EXIST["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_without_part(self):
        """
        攻击失败,未传part参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        json_body = {"user_id": user_id_1}
        res = self.ar_con2.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_error_part(self):
        """
        攻击失败,part参数错误\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)

        json_body = {"user_id": user_id_1, "part": 123}
        res = self.ar_con2.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_NOT_ALLOW_ATTACK_PART["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ALLOW_ATTACK_PART["err_msg"]),
                    "response msg mismatching...")

    def test_attack_pet_error_user_id(self):
        """
        攻击失败,user_id参数错误\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        user_id_2 = CoRand.get_rand_int(100001)

        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id_1)
        json_body = {"user_id": user_id_2, "part": 1}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_USER_NOT_EXIST["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_USER_NOT_EXIST["err_msg"]),
                    "response msg mismatching...")
class GetAttackCountTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetAttackCount test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getAttackCount"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"
        self.total_part_name = ["head", "arm", "clothes", "skirt", "shoes"]

    def tearDown(self):
        print 'GetAttackCount test complete.....close socket'

    def test_get_attack_count_not_attacked(self):
        """
        获取玩家被攻击次数:未被攻击过\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        res = self.ar_con.login(self.account_id, "im")
        res_data = json.loads(res)
        self.user_id = res_data["user_id"]
        self.ar_con.connect_server()
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_attack_count(self.user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("attack"), "no attack response...")
        assert_that(res_data["attack"], equal_to(0),
                    "response attack mismatch...")

    def test_get_attack_count(self):
        """
        获取玩家被攻击次数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id_1 = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建攻击玩家B,攻击A(无护盾):"
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A获取攻击次数:"
        self.ar_con.get_rev()
        res = self.ar_con.get_attack_count(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("attack"), "no attack response...")
        assert_that(res_data["attack"], equal_to(1),
                    "response attack mismatch...")
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "shield", 1)
        self.ar_con.gm_reload_user_data(user_id_1)
        print "玩家B再次攻击,A(有护盾):"
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A获取攻击次数:"
        self.ar_con.get_rev()
        res = self.ar_con.get_attack_count(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("attack"), "no attack response...")
        assert_that(res_data["attack"], equal_to(2),
                    "response attack mismatch...")

    def test_get_attack_count_without_params(self):
        """
        获取玩家被攻击次数:未传参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        json_body = {}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")
class EvilRankListTest(unittest.TestCase):
    def setUp(self):
        print 'start run EvilRankList test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "evilRankList"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'EvilRankList test complete.....close socket'

    def test_evil_rank_list_none(self):
        """
        获取排行榜--无人攻击\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.evil_rank_list(0)
        res_data = json.loads(res)
        assert res_data == [], "response rank_list mismatch..."

    def test_evil_rank_list_success(self):
        """
        获取排行榜--验证恶人榜数据正确性(攻击次数、昵称、通缉、星级等信息)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建攻击玩家B:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        #   获取玩家昵称、星章数等信息
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        self.ar_con2.upgrade_pet_part(part_2)
        #   攻击
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)

        print "A获取恶人榜:"
        self.ar_con.get_rev()
        res = self.ar_con.evil_rank_list(0)
        res_data = json.loads(res)
        assert res_data != [], "response rank_list mismatch..."
        users = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            users.append(i["user_id"])
        assert user_id_2 in users
        attack_user_index = users.index(user_id_2)
        assert_that(res_data[attack_user_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data[attack_user_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data[attack_user_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data[attack_user_index]["icon"],
                    equal_to("https://www.baidu.com/"),
                    "response icon mismatch...")
        assert_that(res_data[attack_user_index], has_key("star"),
                    "no star response...")
        assert_that(res_data[attack_user_index]["star"], equal_to(2),
                    "response star mismatch...")
        assert_that(res_data[attack_user_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data[attack_user_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[attack_user_index]["reward_id"], equal_to(0),
                    "response reward_id mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[attack_user_index]["reward_type"], equal_to(0),
                    "response attack mismatch...")

        print "A悬赏B后获取恶人榜周榜、历史榜:"
        self.ar_con.reward_player(0, user_id_2)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"),
                    "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        res = self.ar_con.evil_rank_list(0)
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        users = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            users.append(i["user_id"])
        assert user_id_2 in users
        attack_user_index = users.index(user_id_2)
        assert_that(res_data[attack_user_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data[attack_user_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data[attack_user_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data[attack_user_index]["icon"],
                    equal_to("https://www.baidu.com/"),
                    "response icon mismatch...")
        assert_that(res_data[attack_user_index], has_key("star"),
                    "no star response...")
        assert_that(res_data[attack_user_index]["star"], equal_to(2),
                    "response star mismatch...")
        assert_that(res_data[attack_user_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data[attack_user_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[attack_user_index]["reward_id"],
                    equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[attack_user_index]["reward_type"], equal_to(0),
                    "response attack mismatch...")

        res = self.ar_con.evil_rank_list(1)
        res_data = json.loads(res)
        assert res_data != [], "response rank_list mismatch..."
        users = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            users.append(i["user_id"])
        assert user_id_2 in users
        attack_user_index = users.index(user_id_2)
        assert_that(res_data[attack_user_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data[attack_user_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data[attack_user_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data[attack_user_index]["icon"],
                    equal_to("https://www.baidu.com/"),
                    "response icon mismatch...")
        assert_that(res_data[attack_user_index], has_key("star"),
                    "no star response...")
        assert_that(res_data[attack_user_index]["star"], equal_to(2),
                    "response star mismatch...")
        assert_that(res_data[attack_user_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data[attack_user_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[attack_user_index]["reward_id"],
                    equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data[attack_user_index], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[attack_user_index]["reward_type"], equal_to(0),
                    "response attack mismatch...")

    def test_evil_rank_list_order(self):
        """
        获取排行榜--验证排行顺序\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id_1 = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = 1
        while part != 6:
            self.ar_con.upgrade_pet_part(part)
            part += 1
        self.ar_con.close()
        print "创建攻击玩家B,攻击一次:"
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        account_id_2 = CoRand.get_rand_int(100001)
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(1, user_id_1)
        print "创建攻击玩家C,攻击三次:"
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        account_id_3 = CoRand.get_rand_int(100001)
        res = self.ar_con3.login(account_id_3, "im")
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(2, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(2, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(3, user_id_1)
        print "创建攻击玩家D,攻击两次:"
        self.ar_con4 = ARControl()
        self.ar_con4.connect_server()
        account_id_4 = CoRand.get_rand_int(100001)
        res = self.ar_con4.login(account_id_4, "im")
        res_data = json.loads(res)
        user_id_4 = res_data["user_id"]
        nick_name_4 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con4.modify_info(nick_name_4)
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "guidance", 131071)
        self.ar_con4.gm_reload_user_data(user_id_4)
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "lottery_type", 104)
        self.ar_con4.gm_reload_user_data(user_id_4)
        self.ar_con4.attack_pet(4, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_4, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_4)
        self.ar_con4.attack_pet(4, user_id_1)

        print "玩家A获取恶人榜:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        self.ar_con.evil_rank_list(1)
        res = self.ar_con.evil_rank_list(0)
        res_data = json.loads(res)
        assert res_data != [], "response rank_list mismatch..."
        assert_that(res_data[0], has_key("user_id"), "no user_id response...")
        assert_that(res_data[0]["user_id"], equal_to(user_id_3), "排序玩家错误")
        assert_that(res_data[0], has_key("attack"), "no attack response...")
        assert_that(res_data[0]["attack"], equal_to(3), "攻击次数错误")
        assert_that(res_data[1], has_key("user_id"), "no user_id response...")
        assert_that(res_data[1]["user_id"], equal_to(user_id_4), "排序玩家错误")
        assert_that(res_data[1], has_key("attack"), "no attack response...")
        assert_that(res_data[1]["attack"], equal_to(2), "攻击次数错误")
        assert_that(res_data[2], has_key("user_id"), "no user_id response...")
        assert_that(res_data[2]["user_id"], equal_to(user_id_2), "排序玩家错误")
        assert_that(res_data[2], has_key("attack"), "no attack response...")
        assert_that(res_data[2]["attack"], equal_to(1), "攻击次数错误")

        print "玩家A悬赏BCD后,追加悬赏D,获取恶人榜:"
        self.ar_con.reward_player(0, user_id_2)
        self.ar_con.reward_player(1, user_id_3)
        self.ar_con.pm_set_role_data("rewardNormal", 2)
        self.ar_con.reward_player(0, user_id_4)
        self.ar_con.reward_player(0, user_id_4)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        for i in res_data["reward_list"]:
            if i["be_reward_user_id"] == user_id_2:
                reward_id_2 = i["reward_id"]
            elif i["be_reward_user_id"] == user_id_3:
                reward_id_3 = i["reward_id"]
            elif i["be_reward_user_id"] == user_id_4:
                reward_id_4 = i["reward_id"]

        res = self.ar_con.evil_rank_list(1)
        res_data = json.loads(res)
        assert res_data != [], "response rank_list mismatch..."
        assert_that(res_data[0], has_key("user_id"), "no user_id response...")
        assert_that(res_data[0]["user_id"], equal_to(user_id_3), "排序玩家错误")
        assert_that(res_data[0], has_key("attack"), "no attack response...")
        assert_that(res_data[0]["attack"], equal_to(3), "攻击次数错误")
        assert_that(res_data[0], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[0]["reward_id"], equal_to(reward_id_3), "悬赏令错误")
        assert_that(res_data[0], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[0]["reward_type"], equal_to(1), "reward_type错误")

        assert_that(res_data[1], has_key("user_id"), "no user_id response...")
        assert_that(res_data[1]["user_id"], equal_to(user_id_4), "排序玩家错误")
        assert_that(res_data[1], has_key("attack"), "no attack response...")
        assert_that(res_data[1]["attack"], equal_to(2), "攻击次数错误")
        assert_that(res_data[1], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[1]["reward_id"], equal_to(reward_id_4), "悬赏令错误")
        assert_that(res_data[1], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[1]["reward_type"], equal_to(0), "reward_type错误")
        assert_that(res_data[2], has_key("user_id"), "no user_id response...")
        assert_that(res_data[2]["user_id"], equal_to(user_id_2), "排序玩家错误")
        assert_that(res_data[2], has_key("attack"), "no attack response...")
        assert_that(res_data[2]["attack"], equal_to(1), "攻击次数错误")
        assert_that(res_data[2], has_key("reward_id"),
                    "no reward_id response...")
        assert_that(res_data[2]["reward_id"], equal_to(reward_id_2), "悬赏令错误")
        assert_that(res_data[2], has_key("reward_type"),
                    "no reward_type response...")
        assert_that(res_data[2]["reward_type"], equal_to(0), "reward_type错误")
Esempio n. 6
0
class CatchPlayerListTest(unittest.TestCase):
    def setUp(self):
        print 'start run CatchPlayerList test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "catchPlayerList"
        self.account_id = 100861

    def tearDown(self):
        print 'CatchPlayerList test complete.....close socket'

    def test_catch_player_list_catch_rich(self):
        """
        捕捉富豪--偷取单个富豪70%金币\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        #   获取玩家捕捉富豪前的金币数
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        user_total_ids = []
        coins = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_total_ids.append(i["user_id"])
            res_info = self.ar_con.get_user_info(i["user_id"])
            res_info_data = json.loads(res_info)
            coins.append(res_info_data["coin"])
        #   获取富豪user_id和coin
        rich_user_index = coins.index(max(coins))
        rich_user_id = user_total_ids[rich_user_index]
        rich_coin_before = max(coins)
        user_ids = [rich_user_id]
        #   捕捉富豪
        res = self.ar_con.catch_player_list(user_ids)
        res_data = json.loads(res)
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            if i["user_id"] == rich_user_id:
                assert_that(i, has_key("steal_coin"), "no steal_coin response...")
                assert_that(i["steal_coin"], equal_to(int(rich_coin_before * 0.7)), "response steal_coin mismatch...")
                assert_that(i, has_key("coin"), "no coin response...")
                assert_that(i["coin"], equal_to(rich_coin_before), "response coin mismatch...")
            else:
                assert_that(i, has_key("steal_coin"), "no steal_coin response...")
                assert_that(i["steal_coin"], equal_to(-1), "response steal_coin mismatch...")
                assert_that(i, has_key("coin"), "no coin response...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        coin_after = res_data["coin"]
        assert_that(coin_after, equal_to(coin_before + int(rich_coin_before*0.7)), "user coin add num mismatch...")

    def test_catch_player_list_more_than_one(self):
        """
        捕捉富豪--玩家获取被捕捉所有玩家金币70%\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        user_ids = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])

        res = self.ar_con.catch_player_list(user_ids)
        res_data = json.loads(res)
        coin_add = 0
        for i in res_data:
            assert_that(i, has_key("coin"), "no coin response...")
            assert_that(i, has_key("steal_coin"), "no steal_coin response...")
            assert_that(i["steal_coin"], equal_to(int(i["coin"] * 0.7)), "response steal_coin mismatch...")
            coin_add += i["steal_coin"]
            assert_that(i, has_key("user_id"), "no user_id response...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        coin_after = res_data["coin"]
        assert_that(coin_after, equal_to(coin_before + coin_add), "user coin add num mismatch...")

    def test_catch_player_list_wrong_user(self):
        """
        捕捉富豪--偷取不是富豪列表里的玩家\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        self.ar_con.get_rich_player_list()
        steal_user_id = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        self.ar_con2.login(steal_user_id, "im")
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        user_ids = [steal_user_id]
        res = self.ar_con.catch_player_list(user_ids)
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_DATA_NOT_IDENTICAL["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_DATA_NOT_IDENTICAL["err_msg"]), "response msg mismatching...")

    def test_catch_player_list_none(self):
        """
        捕捉富豪---未捕捉到任何宠物\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        self.ar_con.get_rich_player_list()
        user_ids = []
        res = self.ar_con.catch_player_list(user_ids)
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_CATCH_ANY_ONE["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_NOT_CATCH_ANY_ONE["err_msg"]), "response msg mismatching...")
class GetUnreadMsgTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetUnreadMsg test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getUnReadMsg"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'GetUnreadMsg test complete.....close socket'

    def test_get_unread_msg_add_friend_online(self):
        """
        获取未读消息--添加好友(在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()

        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "玩家2执行操作:"
        res = self.ar_con2.get_rev()
        res_data = json.loads(res)
        # assert_that(res_data, has_key("type"), "no type response...")
        # assert_that(res_data["type"], equal_to(1), "response type mismatch...")
        # assert_that(res_data, has_key("user_id"), "no user_id response...")
        # assert_that(res_data["user_id"], equal_to(user_id_1), "response type mismatch...")

    def test_get_unread_msg_add_friend_offline(self):
        """
        获取未读消息--添加好友(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家2后离线:"
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.close()
        time.sleep(1)

        print "玩家1向2请求添加好友:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)

        print "玩家2登陆后获取未读消息:"
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        res = self.ar_con2.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("type"), "no type response...")
            assert_that(i["msg"]["type"], equal_to(1), "response type mismatch...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_1), "response user_id mismatch...")

    def test_get_unread_msg_deal_add_friend_agree_online(self):
        """
        获取未读消息--同意添加好友(在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "玩家2执行操作:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "玩家1执行操作:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("op"), "no op response...")
        assert_that(res_data["op"], equal_to(1), "response op mismatch...")
        assert_that(res_data, has_key("convid"), "no convid response...")

    def test_get_unread_msg_deal_add_friend_agree_offline(self):
        """
        获取未读消息--同意添加好友(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家2:"
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)

        print "玩家1向2请求添加好友后离线:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        self.ar_con.close()
        time.sleep(1)

        print "玩家2同意好友请求:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)

        print "玩家1登陆后获取消息:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
            assert_that(i["msg"], has_key("op"), "no op response...")
            assert_that(i["msg"]["op"], equal_to(1), "response op mismatch...")
            assert_that(i["msg"], has_key("convid"), "no convid response...")

    def test_get_unread_msg_deal_add_friend_refuse_online(self):
        """
        获取未读消息--拒绝添加好友(在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "玩家2执行操作:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, -1)
        print "玩家1执行操作:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("op"), "no op response...")
        assert_that(res_data["op"], equal_to(-1), "response op mismatch...")
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(2), "response type mismatch...")

    def test_get_unread_msg_deal_add_friend_refuse_offline(self):
        """
        获取未读消息--拒绝添加好友(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家2执行操作:"
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)

        print "玩家1执行操作后离线:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        self.ar_con.close()
        time.sleep(1)

        print "玩家2处理好友请求:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, -1)

        print "玩家1登陆后获取消息:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
            assert_that(i["msg"], has_key("op"), "no op response...")
            assert_that(i["msg"]["op"], equal_to(-1), "response op mismatch...")

    def test_get_unread_msg_no_msg(self):
        """
        无未读消息\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)

        assert_that(res_data, equal_to([]), "response mismatch...")

    # def test_get_unread_msg_coin_steal_online(self):
    #     """
    #     获取未读消息--金币被偷取(在线)\
    #     开发:黄良江(900000)\
    #     测试:林冰晶(791099)
    #     """
    #     account_id_1 = CoRand.get_rand_int(100001)
    #     res = self.ar_con.login(account_id_1, "im")
    #     res_data = json.loads(res)
    #     user_id_1 = res_data["user_id"]
    #     nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
    #     self.ar_con.modify_info(nick_name_1)
    #     self.sql = ModifySql()
    #     self.sql.update_user(user_id_1, "guidance", 131071)
    #     self.ar_con.gm_reload_user_data(user_id_1)
    #     self.sql = ModifySql()
    #     self.sql.update_user(user_id_1, "lottery_type", 105)
    #     self.ar_con.gm_reload_user_data(user_id_1)
    #     print "玩家获取富豪列表:"
    #     res = self.ar_con.get_rich_player_list()
    #     res_data = json.loads(res)
    #     user_total_ids = []
    #     coins = []
    #     for i in res_data:
    #         assert_that(i, has_key("user_id"), "no user_id response...")
    #         user_total_ids.append(i["user_id"])
    #         res_info = self.ar_con.get_user_info(i["user_id"])
    #         res_info_data = json.loads(res_info)
    #         coins.append(res_info_data["coin"])
    #     # 获取富豪user_id和coin
    #     rich_user_index = coins.index(max(coins))
    #     rich_user_id = user_total_ids[rich_user_index]
    #     user_ids = [rich_user_id]
    #     print rich_user_id
    #     print "被偷取玩家登录:"
    #     self.sql = ModifySql()
    #     rich_account_id = self.sql.query_account_id(rich_user_id)
    #     self.ar_con2 = ARControl()
    #     self.ar_con2.connect_server()
    #     self.ar_con2.login(rich_account_id, "im")
    #     print "玩家捕捉富豪:"
    #     self.ar_con.catch_player_list(user_ids)
    #     print "被偷取玩家收到服务端消息:"
    #     res = self.ar_con2.get_rev()
    #     res_data = json.loads(res)
    #     assert_that(res_data, has_key("user_id"), "no user_id response...")
    #     assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
    #     assert_that(res_data, has_key("type"), "no type response...")
    #     assert_that(res_data["type"], equal_to(4), "response type mismatch...")
    #     assert_that(res_data, has_key("steal_time"), "no steal_time response...")
    #     assert_that(res_data, has_key("steal_coin"), "no steal_coin response...")
    #     assert_that(res_data["steal_coin"], equal_to(int(max(coins)*0.7)), "response steal_coin mismatch...")

    def test_get_unread_msg_coin_steal_offline(self):
        """
        获取未读消息--金币被偷取(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id_1)
        print "玩家获取富豪列表:"
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        user_total_ids = []
        coins = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_total_ids.append(i["user_id"])
            res_info = self.ar_con.get_user_info(i["user_id"])
            res_info_data = json.loads(res_info)
            coins.append(res_info_data["coin"])
        # 获取富豪user_id和coin
        rich_user_index = coins.index(max(coins))
        rich_user_id = user_total_ids[rich_user_index]
        user_ids = [rich_user_id]
        print "玩家捕捉富豪:"
        self.ar_con.catch_player_list(user_ids)
        print "被偷取玩家登录:"
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        self.ar_con2.login(rich_user_id, "im")
        print "被偷取玩家获取未读消息:"
        res = self.ar_con2.get_unread_msg()
        res_data = json.loads(res)
        msg_user_list = []
        if res_data!=[]:
            for i in res_data:
                assert_that(i, has_key("msg"), "no msg response...")
                assert_that(i["msg"], has_key("user_id"), "no user_id response...")
                msg_user_list.append(i["msg"]["user_id"])
            assert user_id_1 in msg_user_list
            msg_index = msg_user_list.index(user_id_1)

            assert_that(res_data[msg_index]["msg"], has_key("type"), "no type response...")
            assert_that(res_data[msg_index]["msg"]["type"], equal_to(4), "response type mismatch...")
            assert_that(res_data[msg_index]["msg"], has_key("steal_time"), "no steal_time response...")
            assert_that(res_data[msg_index]["msg"], has_key("steal_coin"), "no steal_coin response...")
            assert_that(res_data[msg_index]["msg"]["steal_coin"], equal_to(int(max(coins)*0.7)),
                        "response steal_coin mismatch...")
        else:
            pass

    def test_attack_pet_attacked_user_notify_online(self):
        """
        获取未读消息--验证无护盾玩家被攻击通知(在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)

        #   第一次攻击
        print "创建玩家B,攻击A:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A获取服务端消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(3), "response type mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("attack_time"), "no attack_time response...")
        assert_that(res_data, has_key("part"), "no part response...")
        assert_that(res_data["part"], equal_to(part), "response part mismatch...")
        assert_that(res_data, has_key("level"), "no level response...")
        assert_that(res_data["level"], equal_to(1), "response level mismatch...")
        assert_that(res_data, has_key("status"), "no status response...")
        assert_that(res_data["status"], equal_to(1), "response status mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(1), "response star mismatch...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(0), "response shield mismatch...")

        #   第二次攻击
        print "玩家B第二次攻击A:"
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A获取服务端消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(3), "response type mismatch...")
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("attack_time"), "no attack_time response...")
        assert_that(res_data, has_key("part"), "no part response...")
        assert_that(res_data["part"], equal_to(part), "response part mismatch...")
        assert_that(res_data, has_key("level"), "no level response...")
        assert_that(res_data["level"], equal_to(0), "response level mismatch...")
        assert_that(res_data, has_key("status"), "no status response...")
        assert_that(res_data["status"], equal_to(0), "response status mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(0), "response star mismatch...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(0), "response shield mismatch...")

    def test_attack_pet_attacked_user_notify_offline(self):
        """
        获取未读消息-验证有护盾玩家被攻击通知(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A后离线:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "shield", 2)
        self.ar_con.gm_reload_user_data(user_id_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        self.ar_con.close()
        time.sleep(1)

        print "创建玩家B,攻击A:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A获取未读消息后离线:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
            assert_that(i["msg"], has_key("type"), "no type response...")
            assert_that(i["msg"]["type"], equal_to(3), "response type mismatch...")
            assert_that(i["msg"], has_key("attack_time"), "no attack_time response...")
            assert_that(i["msg"], has_key("part"), "no part response...")
            assert_that(i["msg"]["part"], equal_to(part), "response part mismatch...")
            assert_that(i["msg"], has_key("level"), "no level response...")
            assert_that(i["msg"]["level"], equal_to(1), "response level mismatch...")
            assert_that(i["msg"], has_key("status"), "no status response...")
            assert_that(i["msg"]["status"], equal_to(0), "response status mismatch...")
            assert_that(i["msg"], has_key("star"), "no star response...")
            assert_that(i["msg"]["star"], equal_to(1), "response star mismatch...")
            assert_that(i["msg"], has_key("shield"), "no shield response...")
            assert_that(i["msg"]["shield"], equal_to(2), "response shield mismatch...")
        self.ar_con.close()
        time.sleep(1)

        print "玩家B第二次攻击A:"
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家A登陆,获取未读消息:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
            assert_that(i["msg"], has_key("type"), "no type response...")
            assert_that(i["msg"]["type"], equal_to(3), "response type mismatch...")
            assert_that(i["msg"], has_key("attack_time"), "no attack_time response...")
            assert_that(i["msg"], has_key("part"), "no part response...")
            assert_that(i["msg"]["part"], equal_to(part), "response part mismatch...")
            assert_that(i["msg"], has_key("level"), "no level response...")
            assert_that(i["msg"]["level"], equal_to(1), "response level mismatch...")
            assert_that(i["msg"], has_key("status"), "no status response...")
            assert_that(i["msg"]["status"], equal_to(0), "response status mismatch...")
            assert_that(i["msg"], has_key("star"), "no star response...")
            assert_that(i["msg"]["star"], equal_to(1), "response star mismatch...")
            assert_that(i["msg"], has_key("shield"), "no shield response...")
            assert_that(i["msg"]["shield"], equal_to(2), "response shield mismatch...")

    def test_get_unread_msg_reward_player_online(self):
        """
        获取未读消息--验证悬赏消息(在线),包含部件被打坏、打爆\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "悬赏令使用者登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)
        print "创建好友玩家:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "悬赏令使用者同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "好友玩家收到消息:"
        self.ar_con2.get_rev()

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.get_user_info(user_id_3)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        res = self.ar_con3.upgrade_pet_part(part_3)
        res_data = json.loads(res)
        coin_level_1 = coin_before - res_data["coin"]
        res = self.ar_con3.upgrade_pet_part(part_3)
        res_data = json.loads(res)
        coin_level_2 = coin_before - res_data["coin"] - coin_level_1
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用普通通缉令通缉攻击者:"
        self.ar_con.get_rev()
        self.ar_con.get_enemy_list()
        self.ar_con.reward_player(0, user_id_3)

        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.evil_rank_list(0)

        print "好友玩家收到消息并攻击被悬赏者:"
        res = self.ar_con2.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data, has_key("be_reward_user_id"), "no be_reward_user_id response...")
        assert_that(res_data["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(6), "response type mismatch...")
        assert_that(res_data, has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_type"], equal_to(0), "response reward_type mismatch...")
        assert_that(res_data, has_key("reward_time"), "no reward_time response...")
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part_3, user_id_3, reward_id)

        print "悬赏者收到消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(5), "response type mismatch...")
        assert_that(res_data, has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_type"], equal_to(0), "response reward_type mismatch...")
        assert_that(res_data, has_key("attack_time"), "no attack_time response...")
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_level_2*0.5)), "response toll mismatch...")

        print "好友玩家再次攻击被悬赏者:"
        self.ar_con2.pm_set_role_data("lotteryType", 104)
        self.ar_con2.attack_pet(part_3, user_id_3, reward_id)

        print "悬赏者收到消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data, has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
        assert_that(res_data, has_key("type"), "no type response...")
        assert_that(res_data["type"], equal_to(5), "response type mismatch...")
        assert_that(res_data, has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_type"], equal_to(0), "response reward_type mismatch...")
        assert_that(res_data, has_key("attack_time"), "no attack_time response...")
        assert_that(res_data, has_key("toll"), "no toll response...")
        assert_that(res_data["toll"], equal_to(int(coin_level_2 * 0.5)+coin_level_1), "response toll mismatch...")

    def test_get_unread_msg_reward_player_offline(self):
        """
        获取未读消息--验证悬赏消息(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "悬赏令使用者登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)
        print "创建好友玩家:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "悬赏令使用者同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "好友玩家收到消息后离线:"
        self.ar_con2.get_rev()
        self.ar_con2.close()
        time.sleep(1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.get_user_info(user_id_3)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        res = self.ar_con3.upgrade_pet_part(part_3)
        res_data = json.loads(res)
        coin_after = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用高级通缉令通缉攻击者后离线:"
        self.ar_con.get_rev()
        self.ar_con.get_enemy_list()
        self.ar_con.reward_player(1, user_id_3)

        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("reward_list"), "no reward_list response...")
        assert_that(res_data["reward_list"][0], has_key("reward_id"), "no reward_id response...")
        reward_id = res_data["reward_list"][0]["reward_id"]
        self.ar_con.evil_rank_list(0)
        self.ar_con.close()
        time.sleep(1)

        print "好友玩家登陆,获取未读消息并攻击被悬赏者:"
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        res = self.ar_con2.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_1), "response user_id mismatch...")
            assert_that(i["msg"], has_key("be_reward_user_id"), "no be_reward_user_id response...")
            assert_that(i["msg"]["be_reward_user_id"], equal_to(user_id_3), "response be_reward_user_id mismatch...")
            assert_that(i["msg"], has_key("type"), "no type response...")
            assert_that(i["msg"]["type"], equal_to(6), "response type mismatch...")
            assert_that(i["msg"], has_key("reward_type"), "no reward_type response...")
            assert_that(i["msg"]["reward_type"], equal_to(1), "response reward_type mismatch...")
            assert_that(i["msg"], has_key("reward_time"), "no reward_time response...")

        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part_3, user_id_3, reward_id)

        print "悬赏者登陆获取未读消息:"
        self.ar_con.connect_server()
        self.ar_con.login(account_id_1, "im", uc_id_1)
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
            assert_that(i["msg"], has_key("type"), "no type response...")
            assert_that(i["msg"]["type"], equal_to(5), "response type mismatch...")
            assert_that(i["msg"], has_key("attack_time"), "no attack_time response...")
            assert_that(i["msg"], has_key("reward_type"), "no reward_type response...")
            assert_that(i["msg"]["reward_type"], equal_to(1), "response reward_type mismatch...")
            assert_that(i["msg"], has_key("reward_id"), "no reward_id response...")
            assert_that(i["msg"]["reward_id"], equal_to(reward_id), "response reward_id mismatch...")
            assert_that(i["msg"], has_key("toll"), "no toll response...")
            assert_that(i["msg"]["toll"], equal_to(int((coin_before-coin_after)*0.5)), "response toll mismatch...")

    def test_get_unread_msg_del_friend_online(self):
        """
        获取未读消息:被好友删除(在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        print "玩家B向A请求添加好友:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "A同意好友请求:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "B收到好友同意消息:"
        self.ar_con.get_rev()
        self.ar_con2.get_friend_list()

        print "A删除好友B:"
        res = self.ar_con2.del_friend(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        print "B收到消息:"
        res = self.ar_con.get_rev()
        res_data = json.loads(res)
        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data["user_id"], equal_to(user_id_2), "response user_id mismatch...")

    def test_get_unread_msg_del_friend_offline(self):
        """
        获取未读消息:被好友删除(不在线)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        print "玩家B向A请求添加好友:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "A同意好友请求:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "B收到好友同意消息后离线:"
        self.ar_con.get_rev()
        self.ar_con.get_friend_list()
        self.ar_con.close()
        time.sleep(1)

        print "A删除好友B:"
        res = self.ar_con2.del_friend(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        print "B登陆获取未读消息:"
        self.ar_con.connect_server()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        res = self.ar_con.get_unread_msg()
        res_data = json.loads(res)
        assert res_data != [], "response mismatch..."
        for i in res_data:
            assert_that(i, has_key("msg"), "no msg response...")
            assert_that(i["msg"], has_key("user_id"), "no user_id response...")
            assert_that(i["msg"]["user_id"], equal_to(user_id_2), "response user_id mismatch...")
Esempio n. 8
0
class DrawLotteryTest(unittest.TestCase):
    def setUp(self):
        print 'start run DrawLottery test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "drawLottery"
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'DrawLottery test complete.....close socket'

    def test_draw_lottery_success(self):
        """
        抽奖成功\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        pp = res_data["pp"]

        res = self.ar_con.draw_lottery()
        res_data = json.loads(res)

        assert_that(res_data, has_key("item"), "no item response...")
        assert_that(res_data, has_key("count"), "no count response...")
        assert_that(res_data, has_key("place"), "no place response...")
        assert_that(res_data, has_key("last_pp_regain"), "no last_pp_regain response...")
        if res_data["item"] == 102:
            assert_that(res_data, has_key("pp"), "no pp response...")
            assert_that(res_data["pp"], equal_to(pp+9), "pp mismatching...")
        else:
            assert_that(res_data, has_key("pp"), "no pp response...")
            assert_that(res_data["pp"], equal_to(pp-1), "pp mismatching...")

    def test_draw_lottery_large(self):
        """
        50次抽奖,验证抽奖后物品数值\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        pp_before = res_data["pp"]
        coin = res_data["coin"]
        shield = res_data["shield"]
        scan_advance_count = res_data["scan_advance"]
        scan_normal_count = res_data["scan_normal"]
        pp_add = 0

        for i in range(0, 50):
            res = self.ar_con.draw_lottery()
            res_data = json.loads(res)
            assert_that(res_data, has_key("item"), "no item response...")
            assert_that(res_data, has_key("count"), "no count response...")
            if res_data["item"] == 101:
                count = res_data["count"]
                coin += count
            elif res_data["item"] == 102:
                count = res_data["count"]
                pp_add += count
            elif res_data["item"] == 103:
                count = res_data["count"]
                shield += count
                if shield > 3:
                    pp_add += 1
                    shield = 3
            elif res_data["item"] == 106:
                if 'scan_advance' in res_data.keys():
                    count = res_data["count"]
                    scan_advance_count += count
                    assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
                else:
                    count = res_data["count"]
                    scan_normal_count += count
                    assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(pp_before-50+pp_add), "response pp error...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(coin), "response coin error...")
        assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
        assert_that(res_data["scan_advance"], equal_to(scan_advance_count), "response scan_advance error...")
        assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")
        assert_that(res_data["scan_normal"], equal_to(scan_normal_count), "response scan_normal error...")
        assert_that(res_data, has_key("last_pp_regain"), "no last_pp_regain response...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(shield), "response shield error...")

    def test_draw_lottery_shield_more_than_3(self):
        """
        验证抽到护盾满3个时,再次抽取到护盾,护盾数量不增加,不扣体力\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.connect_server()
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 100)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        pp_before = res_data["pp"]
        coin = res_data["coin"]
        scan_advance_count = res_data["scan_advance"]
        scan_normal_count = res_data["scan_normal"]
        pp_add = 0
        shield_num = 0

        for i in range(0, 100):
            res = self.ar_con.draw_lottery()
            res_data = json.loads(res)
            assert_that(res_data, has_key("item"), "no item response...")
            assert_that(res_data, has_key("count"), "no count response...")
            if res_data["item"] == 101:
                count = res_data["count"]
                coin += count
            elif res_data["item"] == 102:
                count = res_data["count"]
                pp_add += count
            elif res_data["item"] == 106:
                if 'scan_advance' in res_data.keys():
                    count = res_data["count"]
                    scan_advance_count += count
                    assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
                else:
                    count = res_data["count"]
                    scan_normal_count += count
                    assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")
            elif res_data["item"] == 103:
                count = res_data["count"]
                shield_num += count
                if shield_num > 3:
                    pp_add += 1
                    shield_num = 3
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(pp_before-100+pp_add), "response pp error...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(coin), "response coin error...")
        assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
        assert_that(res_data["scan_advance"], equal_to(scan_advance_count), "response scan_advance error...")
        assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")
        assert_that(res_data["scan_normal"], equal_to(scan_normal_count), "response scan_normal error...")
        assert_that(res_data, has_key("last_pp_regain"), "no last_pp_regain response...")
        assert_that(res_data, has_key("shield"), "no shield response...")
        assert_that(res_data["shield"], equal_to(shield_num), "response shield error...")

    def test_draw_lottery_not_enough_energy(self):
        """
        抽奖失败,体力不足\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)

        res = self.ar_con.draw_lottery()
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ENOUGH_ENERGY["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_NOT_ENOUGH_ENERGY["err_msg"]), "response msg mismatching...")

    # def test_draw_lottery_reset_timer(self):
    #     """
    #     抽奖,1小时后重置计时器、体力恢复6点\
    #     开发:黄良江(900000)\
    #     测试:林冰晶(791099)
    #     """
    #     user_id = CoRand.get_rand_int(100001)
    #     self.ar_con.login(user_id, "im")
    #     nick_name = CoRand.get_random_word_filter_sensitive(6)
    #     self.ar_con.modify_info(nick_name)
    #     time_before = time.time()
    #     for i in range(0, 30):
    #         self.ar_con.draw_lottery()
    #     res = self.ar_con.get_user_info(user_id)
    #     res_data = json.loads(res)
    #     pp_before = res_data["pp"]
    #     time.sleep(3601)
    #
    #     res = self.ar_con.draw_lottery()
    #     time_after = time.time()
    #     time_interval = int(time_after - time_before)
    #     res_data = json.loads(res)
    #
    #     assert_that(res_data, has_key("item"), "no icon response...")
    #     assert_that(res_data, has_key("last_pp_regain"), "no last_pp_regain response...")
    #     assert_that(res_data["last_pp_regain"], equal_to(time_interval - 3600), "response last_pp_regain error...")
    #     if res_data["item"] == 102:
    #         assert_that(res_data, has_key("pp"), "no nick_name response...")
    #         assert_that(res_data["pp"], equal_to(pp_before+10+5), "pp mismatching...")
    #     else:
    #         assert_that(res_data, has_key("pp"), "no nick_name response...")
    #         assert_that(res_data["pp"], equal_to(pp_before+5), "pp mismatching...")
    #         assert_that(res_data, has_key("last_pp_regain"), "no nick_name response...")

    # def test_draw_lottery_probability(self):
    #     """
    #     抽奖概率统计\
    #     开发:黄良江(900000)\
    #     测试:林冰晶(791099)
    #     """
    #     star_coin_num = 0.0
    #     coin_num = 0.0
    #     energy_num = 0.0
    #     shield_num = 0.0
    #     attack_num = 0.0
    #     steal_num = 0.0
    #     scan_celebrity_num = 0.0
    #     scan_unlock_num = 0.0
    #     user_num = 100
    #     draw_lottery_num = user_num*50
    #     for a in range(0, user_num):
    #         self.ar_con.connect_server()
    #         account_id = CoRand.get_rand_int(100001)
    #         res = self.ar_con.login(account_id, "im")
    #     res_data = json.loads(res)
    #     user_id = res_data["user_id"]
    #         nick_name = CoRand.get_random_word_filter_sensitive(6)
    #         self.ar_con.modify_info(nick_name)
    #         for i in range(0, 50):
    #             res = self.ar_con.draw_lottery()
    #             res_data = json.loads(res)
    #             assert_that(res_data, has_key("item"), "no item response...")
    #             if res_data["item"] == 100:
    #                 star_coin_num += 1
    #             elif res_data["item"] == 101:
    #                 coin_num += 1
    #             elif res_data["item"] == 102:
    #                 energy_num += 1
    #             elif res_data["item"] == 103:
    #                 shield_num += 1
    #             elif res_data["item"] == 104:
    #                 attack_num += 1
    #             elif res_data["item"] == 105:
    #                 steal_num += 1
    #             elif res_data["item"] == 106:
    #                 scan_celebrity_num += 1
    #             elif res_data["item"] == 107:
    #                 scan_unlock_num += 1
    #             else:
    #                 pass
    #     print "总计抽奖次数:" + str(draw_lottery_num)
    #     print "抽取星数金币概率:" + "%.2f%%" % (star_coin_num/draw_lottery_num*100)
    #     print "抽取金币概率:" + "%.2f%%" % (coin_num / draw_lottery_num * 100)
    #     print "抽取能量概率:" + "%.2f%%" % (energy_num / draw_lottery_num * 100)
    #     print "抽取护盾概率:" + "%.2f%%" % (shield_num / draw_lottery_num * 100)
    #     print "抽取攻击概率:" + "%.2f%%" % (attack_num / draw_lottery_num * 100)
    #     print "抽取偷取概率:" + "%.2f%%" % (steal_num / draw_lottery_num * 100)
    #     print "抽取扫描名人概率:" + "%.2f%%" % (scan_celebrity_num / draw_lottery_num * 100)
    #     print "抽取扫描解锁概率:" + "%.2f%%" % (scan_unlock_num / draw_lottery_num * 100)

    def test_draw_lottery_item_100(self):
        """
        验证抽取星数金币\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.ar_con.pm_set_role_data("coin", 100000000)
        for i in range(0, 3):
            res = self.ar_con.scan_face(self.pet_url, "la", 1)
            res_data = json.loads(res)
            pet_id = res_data["item_id"]
            self.ar_con.capture_pet(pet_id)
            self.ar_con.set_cultivate_pet(pet_id)
            part = 1
            while part != 6:
                for j in range(0, 5):
                    self.ar_con.upgrade_pet_part(part)
                part += 1

        pet_idx = 4
        star_coin_count = 200

        while pet_idx != 31:
            if pet_idx <= 8:
                star_coin_count = 200
            elif pet_idx >= 9 and pet_idx <= 13:
                star_coin_count = 300
            elif pet_idx >= 14 and pet_idx <= 18:
                star_coin_count = 400
            elif pet_idx >= 19 and pet_idx <= 23:
                star_coin_count = 500
            elif pet_idx >= 24 and pet_idx <= 28:
                star_coin_count = 600
            elif pet_idx >= 29 and pet_idx <= 30:
                star_coin_count = 700

            print "升级到第" + str(pet_idx) + "个养成宠,转盘抽中星数金币为当前星级*" + str(star_coin_count) + ":"
            res = self.ar_con.scan_face(self.pet_url, "la", 1)
            res_data = json.loads(res)
            pet_id = res_data["item_id"]
            self.ar_con.capture_pet(pet_id)
            self.ar_con.set_cultivate_pet(pet_id)
            self.sql = ModifySql()
            self.sql.update_user(user_id, "pp", 50)
            self.ar_con.gm_reload_user_data(user_id)

            res = self.ar_con.get_user_info(user_id)
            res_data = json.loads(res)
            coin = res_data["coin"]
            scan_advance_count = res_data["scan_advance"]
            scan_normal_count = res_data["scan_normal"]
            star = res_data["star"]
            shield = res_data["shield"]
            pp_add = 0

            for m in range(0, 50):
                res = self.ar_con.draw_lottery()
                res_data = json.loads(res)
                assert_that(res_data, has_key("item"), "no item response...")
                assert_that(res_data, has_key("count"), "no count response...")
                if res_data["item"] == 101:
                    count = res_data["count"]
                    coin += count
                    assert_that(res_data, has_key("coin"), "no coin response...")
                elif res_data["item"] == 102:
                    count = res_data["count"]
                    pp_add += count
                    print pp_add
                elif res_data["item"] == 103:
                    count = res_data["count"]
                    shield += count
                    if shield > 3:
                        pp_add += 1
                        shield = 3
                    print pp_add
                elif res_data["item"] == 106:
                    if 'scan_advance' in res_data.keys():
                        count = res_data["count"]
                        scan_advance_count += count
                        assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
                    else:
                        count = res_data["count"]
                        scan_normal_count += count
                        assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")
                elif res_data["item"] == 100:
                    assert_that(res_data["count"], equal_to(star_coin_count))
                    coin += star*star_coin_count
                    assert_that(res_data, has_key("coin"), "no coin response...")

            res = self.ar_con.get_user_info(user_id)
            res_data = json.loads(res)
            assert_that(res_data, has_key("pp"), "no pp response...")
            assert_that(res_data["pp"], equal_to(pp_add), "response pp error...")
            assert_that(res_data, has_key("coin"), "no coin response...")
            assert_that(res_data["coin"], equal_to(coin), "response coin error...")
            assert_that(res_data, has_key("scan_advance"), "no scan_advance response...")
            assert_that(res_data["scan_advance"], equal_to(scan_advance_count), "response scan_advance error...")
            assert_that(res_data, has_key("scan_normal"), "no scan_normal response...")
            assert_that(res_data["scan_normal"], equal_to(scan_normal_count), "response scan_normal error...")
            assert_that(res_data, has_key("last_pp_regain"), "no last_pp_regain response...")
            self.sql = ModifySql()
            self.sql.update_user(user_id, "coin", 1000000000)
            self.ar_con.gm_reload_user_data(user_id)
            part = 1
            while part != 6:
                for j in range(0, 5):
                    self.ar_con.upgrade_pet_part(part)
                part += 1
            pet_idx += 1
class GetFriendEnergyTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetFriendEnergy test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getFriendEnergy"
        self.account_id = 100861

    def tearDown(self):
        print 'GetFriendEnergy test complete.....close socket'

    def test_get_friend_energy_pp_less_than_50(self):
        """
        领取体力--体力值小于50,可领取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "玩家B赠送体力:"
        self.ar_con2.get_rev()
        self.ar_con2.give_friend_energy(user_id_1)
        print "A领取体力:"
        self.ar_con.pm_set_role_data("pp", 40)
        res = self.ar_con.get_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(41), "response pp mismatch...")

        res = self.ar_con.get_user_info(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_energy"), "no get_energy response...")
        assert_that(res_data["get_energy"], equal_to(1), "response get_energy mismatch...")

    def test_get_friend_energy_pp_50(self):
        """
        领取体力--体力值=50,不可领取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "玩家B赠送体力:"
        self.ar_con2.get_rev()
        self.ar_con2.give_friend_energy(user_id_1)
        print "A领取体力:"
        res = self.ar_con.get_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_MAX_ENERGY["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_MAX_ENERGY["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(50), "response pp mismatch...")

    def test_get_friend_energy_pp_more_than_50(self):
        """
        领取体力--体力值>50,不可领取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆,修改体力值100:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "pp", 100)
        self.ar_con.gm_reload_user_data(user_id_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "玩家B赠送体力:"
        self.ar_con2.get_rev()
        self.ar_con2.give_friend_energy(user_id_1)
        print "A领取体力:"
        res = self.ar_con.get_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_MAX_ENERGY["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_MAX_ENERGY["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(100), "response pp mismatch...")

    def test_get_friend_energy_repeat(self):
        """
        领取体力--重复领取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        print "玩家B赠送体力:"
        self.ar_con2.get_rev()
        self.ar_con2.give_friend_energy(user_id_1)
        print "A重复领取体力:"
        self.ar_con.pm_set_role_data("pp", 40)
        self.ar_con.get_friend_energy(user_id_2)
        res = self.ar_con.get_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_ENERGY_HAD_GET["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_ENERGY_HAD_GET["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(41), "response pp mismatch...")

    def test_get_friend_energy_friend_not_give(self):
        """
        领取体力--好友未赠送\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)

        print "A领取体力:"
        self.ar_con.pm_set_role_data("pp", 40)
        res = self.ar_con.get_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_FOUND_ENERGY["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_ENERGY["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(40), "response pp mismatch...")

    def test_get_friend_energy_not_friend(self):
        """
        领取体力--非好友\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        res = self.ar_con.login(100861, "im")
        res_data = json.loads(res)
        self.user_id = res_data["user_id"]
        self.ar_con.connect_server()

        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 10)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_friend_energy(self.user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_FOUND_FRIEND["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_FRIEND["err_msg"]), "response msg mismatching...")

    def test_get_friend_energy_max_50(self):
        """
        领取体力--每天上限领取50个\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        number = 1
        while number < 51:
            print "创建好友玩家"+str(number)+":"
            locals()['account_id_' + str(number)] = CoRand.get_rand_int(100001)
            locals()['uc_id_' + str(number)] = CoRand.get_rand_int()
            locals()['self.ar_con' + str(number)] = ARControl()
            locals()['self.ar_con' + str(number)].connect_server()
            res = locals()['self.ar_con' + str(number)].login(locals()['account_id_' + str(number)], "im",
                                                              locals()['uc_id_' + str(number)], )
            res_data = json.loads(res)
            locals()['user_id_' + str(number)] = res_data["user_id"]
            locals()['nick_name_' + str(number)] = CoRand.get_random_word_filter_sensitive(6)
            locals()['self.ar_con' + str(number)].modify_info(locals()['nick_name_' + str(number)])
            locals()['self.ar_con' + str(number)].add_friend(user_id)
            print "玩家A同意添加好友"+str(number)+":"
            self.ar_con.get_rev()
            self.ar_con.deal_add_friend(locals()['user_id_'+str(number)], 1)
            print "好友玩家"+str(number)+"赠送体力给A:"
            locals()['self.ar_con' + str(number)].get_rev()
            locals()['self.ar_con' + str(number)].give_friend_energy(user_id)
            number += 1

        print "修改玩家A体力值0,一键获取50体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)
        self.ar_con.get_and_give_friends_energy()
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(50), "response pp mismatch...")
        print "创建好友玩家51:"
        account_id_51 = CoRand.get_rand_int(100001)
        uc_id_51 = CoRand.get_rand_int()
        self.ar_con51 = ARControl()
        self.ar_con51.connect_server()
        res = self.ar_con51.login(account_id_51, "im", uc_id_51)
        res_data = json.loads(res)
        user_id_51 = res_data["user_id"]
        self.ar_con51.add_friend(user_id)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_51, 1)
        print "好友玩家51赠送体力给A:"
        self.ar_con51.get_rev()
        self.ar_con51.give_friend_energy(user_id)
        print "修改玩家A体力值0,获取第51个玩家赠送体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_friend_energy(user_id_51)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_MAX_GET_ENERGY["code"]), "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_MAX_GET_ENERGY["err_msg"]), "response msg mismatching...")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(0), "response pp mismatch...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_energy"), "no get_energy response...")
        assert_that(res_data["get_energy"], equal_to(50), "response get_energy mismatch...")
Esempio n. 10
0
class GetRichestPlayerTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetRichestPlayer test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getRichestPlayer"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"

    def tearDown(self):
        print 'GetRichestPlayer test complete.....close socket'

    def test_get_richest_player_no_steal(self):
        """
        获取最富富豪--未抽中偷袭\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.ar_con.get_rich_player_list()
        res = self.ar_con.get_richest_player()
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("nick_name"), "no nick_name response...")
        assert_that(res_data, has_key("icon"), "no icon response...")

    def test_get_richest_player(self):
        """
        获取最富富豪\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 105)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_rich_player_list()
        res_data = json.loads(res)
        assert res_data != []
        user_total_ids = []
        coins = []
        for i in res_data:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_total_ids.append(i["user_id"])
            res_info = self.ar_con.get_user_info(i["user_id"])
            res_info_data = json.loads(res_info)
            coins.append(res_info_data["coin"])
        rich_user_index = coins.index(max(coins))
        rich_user_nick_name = res_data[rich_user_index]["nick_name"]
        rich_user_icon = res_data[rich_user_index]["icon"]

        res = self.ar_con.get_richest_player()
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(max(coins)),
                    "response coin mismatch...")
        assert_that(res_data, has_key("nick_name"), "no nick_name response...")
        assert_that(res_data["nick_name"], equal_to(rich_user_nick_name),
                    "response nick_name mismatch...")
        assert_that(res_data, has_key("icon"), "no icon response...")
        assert_that(res_data["icon"], equal_to(rich_user_icon),
                    "response icon mismatch...")
class UpgradePetPartTest(unittest.TestCase):
    def setUp(self):
        print 'start run UpgradePetPart test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "upgradePetPart"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"
        self.total_part_name = ["head", "arm", "clothes", "skirt", "shoes"]

    def tearDown(self):
        print 'UpgradePetPart test complete.....close socket'

    def test_upgrade_pet_part_success(self):
        """
        升级部件成功\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        star_before = res_data["star"]
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        res = self.ar_con.upgrade_pet_part(part)
        res_data = json.loads(res)

        assert_that(res_data, has_key("part"), "no part response...")
        assert_that(res_data["part"], equal_to(part),
                    "response part mismatch...")
        assert_that(res_data, has_key("level"), "no level response...")
        assert_that(res_data["level"], equal_to(1),
                    "response level mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], less_than(coin_before),
                    "response coin error...")
        assert_that(res_data, has_key("is_complete"),
                    "no is_complete response...")
        assert_that(res_data["is_complete"], equal_to(0),
                    "response is_complete mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(star_before + 1),
                    "response star mismatch...")
        assert_that(res_data, has_key("reward_normal"),
                    "no reward_normal response...")
        assert_that(res_data["reward_normal"], equal_to(1),
                    "reward_normal mismatching...")

        res = self.ar_con.get_pet_info(pet_id, user_id)
        res_data = json.loads(res)
        attack_part_status = self.total_part_name[part - 1] + "_status"
        attack_part_level = self.total_part_name[part - 1] + "_level"
        assert_that(res_data, has_key(attack_part_status),
                    "no attack_part_status response...")
        assert_that(res_data[attack_part_status], equal_to(0),
                    "response attack_part_status mismatch...")
        assert_that(res_data, has_key(attack_part_level),
                    "no attack_part_level response...")
        assert_that(res_data[attack_part_level], equal_to(1),
                    "response attack_part_level mismatch...")

    def test_upgrade_pet_part_error_part(self):
        """
        升级部件失败,part错误\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int()
        res = self.ar_con.upgrade_pet_part(part)
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")

    def test_upgrade_pet_part_not_enough_coin(self):
        """
        升级部件失败,金币不足\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "coin", 0)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        res = self.ar_con.upgrade_pet_part(part)
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ENOUGH_COIN["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ENOUGH_COIN["err_msg"]),
                    "response msg mismatching...")

    def test_upgrade_pet_part_max_pet(self):
        """
        所有部件升级至最高级,解锁下一个养成宠\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "coin", 100000000)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = 1
        while part != 6:
            for i in range(0, 5):
                self.ar_con.upgrade_pet_part(part)
            part += 1

        res = self.ar_con.get_pet_info(pet_id, user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("is_complete"),
                    "no is_complete response...")
        assert_that(res_data["is_complete"], equal_to(1),
                    "response is_complete mismatch...")

        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id_2 = res_data["item_id"]
        self.ar_con.capture_pet(pet_id_2)
        self.ar_con.set_cultivate_pet(pet_id_2)
        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("pet_idx"), "no pet_idx response...")
        assert_that(res_data["pet_idx"], equal_to(2),
                    "response pet_idx mismatch...")

    def test_upgrade_pet_part_without_part(self):
        """
        升级部件失败,未传part参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        json_body = {}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")

    def test_upgrade_pet_part_get_reward_normal(self):
        """
        升级部件:完成一只养成宠,获得一个普通悬赏令\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "coin", 100000000)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = 1
        while part != 6:
            for i in range(0, 5):
                if part == 5 and i == 4:
                    pass
                else:
                    self.ar_con.upgrade_pet_part(part)
            part += 1
        res = self.ar_con.upgrade_pet_part(5)
        res_data = json.loads(res)
        assert_that(res_data, has_key("part"), "no part response...")
        assert_that(res_data["part"], equal_to(5), "response part mismatch...")
        assert_that(res_data, has_key("level"), "no level response...")
        assert_that(res_data["level"], equal_to(5),
                    "response level mismatch...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("is_complete"),
                    "no is_complete response...")
        assert_that(res_data["is_complete"], equal_to(1),
                    "response is_complete mismatch...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data["star"], equal_to(25),
                    "response star mismatch...")
        assert_that(res_data, has_key("reward_normal"),
                    "no reward_normal response...")
        assert_that(res_data["reward_normal"], equal_to(2),
                    "reward_normal mismatching...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)

        assert_that(res_data, has_key("reward_normal"),
                    "no reward_normal response...")
        assert_that(res_data["reward_normal"], equal_to(2),
                    "reward_normal mismatching...")
        assert_that(res_data, has_key("reward_advance"),
                    "no reward_advance response...")
        assert_that(res_data["reward_advance"], equal_to(1),
                    "reward_advance mismatching...")
Esempio n. 12
0
class RepairPetPartTest(unittest.TestCase):
    def setUp(self):
        print 'start run RepairPetPart test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "repairPetPart"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"
        self.total_part_name = ["head", "arm", "clothes", "skirt", "shoes"]

    def tearDown(self):
        print 'RepairPetPart test complete.....close socket'

    def test_repair_pet_part_success(self):
        """
        修复部件成功,部件状态正常\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "coin", 100000000)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.get_user_info(user_id_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)

        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        res = self.ar_con.repair_pet_part(part)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")

        res = self.ar_con.get_pet_info(pet_id, user_id_1)
        res_data = json.loads(res)
        attack_part_status = self.total_part_name[part - 1] + "_status"
        attack_part_level = self.total_part_name[part - 1] + "_level"
        assert_that(res_data, has_key(attack_part_status),
                    "no attack_part_name response...")
        assert_that(res_data[attack_part_status], equal_to(0),
                    "response attack_part_name mismatch...")
        assert_that(res_data, has_key(attack_part_level),
                    "no attack_part_level response...")
        assert_that(res_data[attack_part_level], equal_to(1),
                    "response attack_part_level mismatch...")

    def test_repair_pet_part_cut_coin(self):
        """
        验证修复部件扣除对应等级价格50%的金币\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "coin", 100000000)
        self.ar_con.gm_reload_user_data(user_id_1)
        res = self.ar_con.get_user_info(user_id_1)
        res_data = json.loads(res)
        coin_before = res_data["coin"]
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        upgrade_time = CoRand.get_rand_int(1, 5)
        coin_cut = 0
        for i in range(0, upgrade_time):
            res = self.ar_con.upgrade_pet_part(part)
            res_data = json.loads(res)
            coin_cut = coin_before - res_data["coin"]
            coin_before = res_data["coin"]
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)

        self.ar_con.get_rev()
        res = self.ar_con.repair_pet_part(part)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data["coin"], equal_to(coin_before - coin_cut // 2),
                    "response coin mismatch...")

    def test_repair_pet_part_attacked_twice(self):
        """
        二次被攻击的部件,无法修复\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        print "玩家2执行操作:"
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        res = self.ar_con.repair_pet_part(part)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_PART_BROKEN["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_PART_BROKEN["err_msg"]),
                    "response msg mismatching...")

    def test_repair_pet_part_not_broken(self):
        """
        修复未被攻击的部件\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)

        res = self.ar_con.repair_pet_part(part)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_PART_BROKEN["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_PART_BROKEN["err_msg"]),
                    "response msg mismatching...")

    def test_repair_pet_part_not_enough_coin(self):
        """
        修复部件失败,金币不足\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "玩家1执行操作:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "coin", 100)
        self.ar_con.gm_reload_user_data(user_id_1)
        print "玩家2执行操作:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        res = self.ar_con.repair_pet_part(part)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ENOUGH_COIN["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ENOUGH_COIN["err_msg"]),
                    "response msg mismatching...")

    def test_repair_pet_part_without_param(self):
        """
        修复失败,未传参数\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        json_body = {}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")

    def test_repair_pet_part_no_cultivate_pet(self):
        """
        修复失败,无随身宠\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.repair_pet_part(1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_FOUND_PET["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]),
                    "response msg mismatching...")

    def test_repair_pet_part_error_part(self):
        """
        修复失败,part参数错误\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        pet_id = res_data["item_id"]
        self.ar_con.capture_pet(pet_id)
        self.ar_con.set_cultivate_pet(pet_id)
        json_body = {"part": 123}
        res = self.ar_con.get_res(self.api_name, json_body)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"],
                    equal_to(EC_INVALID_REQUEST_PARAM["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_INVALID_REQUEST_PARAM["err_msg"]),
                    "response msg mismatching...")
Esempio n. 13
0
class GetRandFriendInfoTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetRandFriendInfo test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.account_id = 100861

    def tearDown(self):
        print 'GetRandFriendInfo test complete.....close socket'

    def test_get_rand_friend_info_success(self):
        """
        获取随机玩家--抽中攻击卡\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        res = self.ar_con.login(account_id, "im")
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        self.sql = ModifySql()
        self.sql.update_user(user_id, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id)

        res = self.ar_con.get_rand_friend_info()
        res_data = json.loads(res)

        assert_that(res_data, has_key("user_id"), "no user_id response...")
        assert_that(res_data, has_key("nick_name"), "no nick_name response...")
        assert_that(res_data, has_key("sex"), "no sex response...")
        assert_that(res_data, has_key("icon"), "no icon response...")
        assert_that(res_data, has_key("scan_normal"),
                    "no scan_normal response...")
        assert_that(res_data, has_key("scan_advance"),
                    "no scan_advance response...")
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("star"), "no star response...")
        assert_that(res_data, has_key("pet_idx"), "no pet_idx response...")
        assert_that(res_data, has_key("pet_id"), "no pet_id response...")
        assert_that(res_data, has_key("can_attack"),
                    "no can_attack response...")

    def test_get_rand_friend_info_without_attack(self):
        """
        获取随机玩家--无攻击卡\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(791099, "im")

        res = self.ar_con.get_rand_friend_info()
        res_data = json.loads(res)

        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_ALLOW_ATTACK["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_ALLOW_ATTACK["err_msg"]),
                    "response msg mismatching...")
Esempio n. 14
0
class GetAndGiveFriendEnergyTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetAndGiveFriendEnergy test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "getAndGiveFriendsEnergy"
        self.account_id = 100861

    def tearDown(self):
        print 'GetAndGiveFriendEnergy test complete.....close socket'

    def test_get_and_give_friend_energy_success(self):
        """
        一键领取和赠送体力-- 一键赠送和领取所有好友体力\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        number = 1
        while number < 11:
            print "创建好友玩家" + str(number) + ":"
            locals()['account_id_' + str(number)] = CoRand.get_rand_int(100001)
            locals()['uc_id_' + str(number)] = CoRand.get_rand_int()
            locals()['self.ar_con' + str(number)] = ARControl()
            locals()['self.ar_con' + str(number)].connect_server()
            res = locals()['self.ar_con' + str(number)].login(
                locals()['account_id_' + str(number)],
                "im",
                locals()['uc_id_' + str(number)],
            )
            res_data = json.loads(res)
            locals()['user_id_' + str(number)] = res_data["user_id"]
            locals()['nick_name_' +
                     str(number)] = CoRand.get_random_word_filter_sensitive(6)
            locals()['self.ar_con' + str(number)].modify_info(
                locals()['nick_name_' + str(number)])
            locals()['self.ar_con' + str(number)].add_friend(user_id)
            print "玩家A同意添加好友" + str(number) + ":"
            self.ar_con.get_rev()
            self.ar_con.deal_add_friend(locals()['user_id_' + str(number)], 1)
            print "好友玩家" + str(number) + "赠送体力给A:"
            locals()['self.ar_con' + str(number)].get_rev()
            locals()['self.ar_con' + str(number)].give_friend_energy(user_id)
            number += 1

        print "修改玩家A体力值0,一键赠送和获取体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(10), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(10), "返回参数pp数值错误")
        number = 1
        while number < 11:
            print "好友玩家" + str(number) + "领取体力:"
            self.sql = ModifySql()
            self.sql.update_user(locals()['user_id_' + str(number)], "pp", 10)
            self.ar_con.gm_reload_user_data(locals()['user_id_' + str(number)])
            res = locals()['self.ar_con' +
                           str(number)].get_friend_energy(user_id)
            res_data = json.loads(res)
            assert_that(res_data, has_key("code"), "no code response...")
            assert_that(res_data, has_key("err_msg"), "no err_msg response...")
            assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                        "response code mismatching...")
            assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                        "response msg mismatching...")
            number += 1

    def test_get_and_give_friend_energy_part_can_give_part_can_not_give(self):
        """
        一键领取和赠送体力--部分好友可赠送体力,部分不可赠送\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友B,并赠送体力:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        self.ar_con.give_friend_energy(user_id_2)
        print "好友B领取体力:"
        self.ar_con2.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "pp", 0)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.get_friend_energy(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                    "response msg mismatching...")
        print "创建好友玩家C:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        self.ar_con3.add_friend(user_id_1)
        print "玩家A同意添加好友C:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_3, 1)
        print "A一键赠送和获取体力:"
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(0), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(50), "返回参数pp数值错误")
        print "好友B领取体力:"
        res = self.ar_con2.get_friend_energy(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_ENERGY_HAD_GET["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_ENERGY_HAD_GET["err_msg"]),
                    "response msg mismatching...")
        print "好友C领取体力:"
        self.ar_con3.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "pp", 0)
        self.ar_con3.gm_reload_user_data(user_id_3)
        res = self.ar_con3.get_friend_energy(user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                    "response msg mismatching...")

    def test_get_and_give_friend_energy_no_friends(self):
        """
        一键领取和赠送体力-- 无好友\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(0), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(50), "返回参数pp数值错误")

    def test_get_and_give_friend_energy_get_part_energy_pp_to_50(self):
        """
        一键领取和赠送体力-- 可领取体力>(50-玩家当前体力),先领取部分体力,剩余体力可下次领取\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        number = 1
        while number < 4:
            print "创建好友玩家" + str(number) + ":"
            locals()['account_id_' + str(number)] = CoRand.get_rand_int(100001)
            locals()['uc_id_' + str(number)] = CoRand.get_rand_int()
            locals()['self.ar_con' + str(number)] = ARControl()
            locals()['self.ar_con' + str(number)].connect_server()
            res = locals()['self.ar_con' + str(number)].login(
                locals()['account_id_' + str(number)],
                "im",
                locals()['uc_id_' + str(number)],
            )
            res_data = json.loads(res)
            locals()['user_id_' + str(number)] = res_data["user_id"]
            locals()['nick_name_' +
                     str(number)] = CoRand.get_random_word_filter_sensitive(6)
            locals()['self.ar_con' + str(number)].modify_info(
                locals()['nick_name_' + str(number)])
            locals()['self.ar_con' + str(number)].add_friend(user_id)
            print "玩家A同意添加好友" + str(number) + ":"
            self.ar_con.get_rev()
            self.ar_con.deal_add_friend(locals()['user_id_' + str(number)], 1)
            print "好友玩家" + str(number) + "赠送体力给A:"
            locals()['self.ar_con' + str(number)].get_rev()
            locals()['self.ar_con' + str(number)].give_friend_energy(user_id)
            number += 1
        print "修改玩家A体力值48,一键赠送和获取体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 48)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(2), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(50), "返回参数pp数值错误")
        print "修改玩家A体力值40,一键获取体力剩余待领取体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 40)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(1), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(41), "返回参数pp数值错误")

    def test_get_and_give_friend_energy_get_max_50(self):
        """
        一键领取和赠送体力--每天上限领取50个\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        number = 1
        while number < 51:
            print "创建好友玩家" + str(number) + ":"
            locals()['account_id_' + str(number)] = CoRand.get_rand_int(100001)
            locals()['uc_id_' + str(number)] = CoRand.get_rand_int()
            locals()['self.ar_con' + str(number)] = ARControl()
            locals()['self.ar_con' + str(number)].connect_server()
            res = locals()['self.ar_con' + str(number)].login(
                locals()['account_id_' + str(number)],
                "im",
                locals()['uc_id_' + str(number)],
            )
            res_data = json.loads(res)
            locals()['user_id_' + str(number)] = res_data["user_id"]
            locals()['nick_name_' +
                     str(number)] = CoRand.get_random_word_filter_sensitive(6)
            locals()['self.ar_con' + str(number)].modify_info(
                locals()['nick_name_' + str(number)])
            locals()['self.ar_con' + str(number)].add_friend(user_id)
            print "玩家A同意添加好友" + str(number) + ":"
            self.ar_con.get_rev()
            self.ar_con.deal_add_friend(locals()['user_id_' + str(number)], 1)
            print "好友玩家" + str(number) + "赠送体力给A:"
            locals()['self.ar_con' + str(number)].get_rev()
            locals()['self.ar_con' + str(number)].give_friend_energy(user_id)
            number += 1

        print "修改玩家A体力值0,一键获取50体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)
        self.ar_con.get_and_give_friends_energy()
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(50), "response pp mismatch...")
        print "创建好友玩家51:"
        account_id_51 = CoRand.get_rand_int(100001)
        uc_id_51 = CoRand.get_rand_int()
        self.ar_con51 = ARControl()
        self.ar_con51.connect_server()
        res = self.ar_con51.login(account_id_51, "im", uc_id_51)
        res_data = json.loads(res)
        user_id_51 = res_data["user_id"]
        nick_name_51 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con51.modify_info(nick_name_51)
        self.ar_con51.add_friend(user_id)
        print "玩家A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_51, 1)
        print "好友玩家51赠送体力给A:"
        self.ar_con51.get_rev()
        self.ar_con51.give_friend_energy(user_id)
        print "修改玩家A体力值0,一键获取第51个玩家赠送体力:"
        self.sql = ModifySql()
        self.sql.update_user(user_id, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id)
        res = self.ar_con.get_and_give_friends_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_pp"), "返回参数缺少get_pp")
        assert_that(res_data["get_pp"], equal_to(0), "返回参数get_pp数值错误")
        assert_that(res_data, has_key("pp"), "返回参数缺少pp")
        assert_that(res_data["pp"], equal_to(0), "返回参数pp数值错误")
        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(0), "response pp mismatch...")

        res = self.ar_con.get_user_info(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("get_energy"),
                    "no get_energy response...")
        assert_that(res_data["get_energy"], equal_to(50),
                    "response get_energy mismatch...")
class GiveFriendEnergyTest(unittest.TestCase):
    def setUp(self):
        print 'start run GiveFriendEnergy test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.api_name = "giveFriendEnergy"
        self.account_id = 100861

    def tearDown(self):
        print 'GiveFriendEnergy test complete.....close socket'

    def test_give_friend_energy_success(self):
        """
        赠送体力--当天第一次赠送,赠送成功\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友,赠送体力:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        res = self.ar_con.give_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                    "response msg mismatching...")

        res = self.ar_con.get_energy()
        res_data = json.loads(res)
        assert_that(res_data, has_key("pp"), "no pp response...")
        assert_that(res_data["pp"], equal_to(50), "response pp mismatching...")

    def test_give_friend_energy_again_one_day(self):
        """
        赠送体力--当天已赠送,好友已领取,无法再次赠送\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "玩家A登陆:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "玩家A同意添加好友,赠送体力:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)
        res = self.ar_con.give_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                    "response msg mismatching...")
        print "玩家B领取体力:"
        self.ar_con2.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "pp", 0)
        self.ar_con.gm_reload_user_data(user_id_2)
        self.ar_con2.get_friend_energy(user_id_1)
        print "玩家A再次赠送体力:"
        res = self.ar_con.give_friend_energy(user_id_2)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_ENERGY_HAD_GIVE["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_ENERGY_HAD_GIVE["err_msg"]),
                    "response msg mismatching...")

    def test_give_friend_energy_give_more_than_50(self):
        """
        赠送体力--每天赠送体力无上限(测试60次)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建玩家A:"
        account_id = CoRand.get_rand_int(100001)
        uc_id = CoRand.get_rand_int()
        res = self.ar_con.login(account_id, "im", uc_id)
        res_data = json.loads(res)
        user_id = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        number = 1
        while number < 61:
            print "创建好友玩家" + str(number) + ":"
            locals()['account_id_' + str(number)] = CoRand.get_rand_int(100001)
            locals()['uc_id_' + str(number)] = CoRand.get_rand_int()
            locals()['self.ar_con' + str(number)] = ARControl()
            locals()['self.ar_con' + str(number)].connect_server()
            res = locals()['self.ar_con' + str(number)].login(
                locals()['account_id_' + str(number)],
                "im",
                locals()['uc_id_' + str(number)],
            )
            res_data = json.loads(res)
            locals()['user_id_' + str(number)] = res_data["user_id"]
            locals()['nick_name_' +
                     str(number)] = CoRand.get_random_word_filter_sensitive(6)
            locals()['self.ar_con' + str(number)].modify_info(
                locals()['nick_name_' + str(number)])
            locals()['self.ar_con' + str(number)].add_friend(user_id)
            print "玩家A同意添加好友" + str(number) + ",并赠送体力:"
            self.ar_con.get_rev()
            self.ar_con.deal_add_friend(locals()['user_id_' + str(number)], 1)
            res = self.ar_con.give_friend_energy(locals()['user_id_' +
                                                          str(number)])
            res_data = json.loads(res)
            assert_that(res_data, has_key("code"), "no code response...")
            assert_that(res_data, has_key("err_msg"), "no err_msg response...")
            assert_that(res_data["code"], equal_to(EC_SUCCESS["code"]),
                        "response code mismatching...")
            assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]),
                        "response msg mismatching...")
            number += 1

    def test_give_friend_energy_not_friend(self):
        """
        赠送体力--赠送非好友\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.give_friend_energy(self.account_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_FOUND_FRIEND["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_FOUND_FRIEND["err_msg"]),
                    "response msg mismatching...")

    def test_give_friend_energy_not_exist(self):
        """
        赠送体力--赠送给不存在的玩家\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        user_id = CoRand.get_rand_int(100001)
        self.ar_con.login(self.account_id, "im")
        res = self.ar_con.give_friend_energy(user_id)
        res_data = json.loads(res)
        assert_that(res_data, has_key("code"), "no code response...")
        assert_that(res_data, has_key("err_msg"), "no err_msg response...")
        assert_that(res_data["code"], equal_to(EC_NOT_FOUND_FRIEND["code"]),
                    "response code mismatching...")
        assert_that(res_data["err_msg"],
                    equal_to(EC_NOT_FOUND_FRIEND["err_msg"]),
                    "response msg mismatching...")
Esempio n. 16
0
class GetEnemyListTest(unittest.TestCase):
    def setUp(self):
        print 'start run GetEnemyList test ......connect server'
        self.ar_con = ARControl()
        self.ar_con.connect_server()
        self.sql = ModifySql()
        self.api_name = "getEnemyList"
        self.account_id = 100861
        self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg"
        self.total_part_name = ["head", "arm", "clothes", "skirt", "shoes"]

    def tearDown(self):
        print 'GetEnemyList test complete.....close socket'

    def test_attack_pet_join_enemy_list(self):
        """
        非好友玩家攻击成功,加入仇人列表(未复仇)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建玩家B攻击A:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        user2_coin_before = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        win_coin = res_data["win_coin"]
        assert_that(res_data["coin"], equal_to(user2_coin_before + win_coin),
                    "response coin mismatch...")
        print "玩家A查看仇人列表:"
        self.ar_con.get_rev()
        time.sleep(1)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_2 in user_ids
        enemy_index = user_ids.index(user_id_2)
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index]["sex"], equal_to(0),
                    "response sex mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")

    def test_attack_pet_join_enemy_list_revenge(self):
        """
        非好友玩家攻击,玩家已复仇,从仇人列表中去除\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建玩家B攻击A:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        user2_coin_before = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        win_coin = res_data["win_coin"]
        assert_that(res_data["coin"], equal_to(user2_coin_before + win_coin),
                    "response coin mismatch...")
        print "玩家A复仇,攻击B后查看仇人列表:"
        self.ar_con.get_rev()
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_2 in user_ids
        enemy_index = user_ids.index(user_id_2)
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index]["sex"], equal_to(0),
                    "response sex mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.attack_pet(part_2, user_id_2)
        time.sleep(1)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert res_data["enemy_list"] == [], "response enemy_list mismatch..."
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data[
            "reward_list"] == [], "response reward_list mismatch..."

    def test_attack_pet_join_enemy_list_has_revenged_and_friend_reward(self):
        """
        非好友玩家攻击,玩家已复仇,且该攻击玩家被好友悬赏,查看仇人列表\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建好友玩家B:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        self.ar_con2.add_friend(user_id_1)
        print "A同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)

        print "B收到消息:"
        self.ar_con2.get_rev()
        print "创建玩家C攻击A、B:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part, user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_2, user_id_2)
        print "B通缉攻击者C:"
        self.ar_con2.get_rev()
        self.ar_con2.reward_player(0, user_id_3)
        print "玩家A复仇,攻击C后查看仇人列表:"
        self.ar_con.get_rev()
        self.ar_con.get_enemy_list()
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.attack_pet(part_3, user_id_3)
        time.sleep(1)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_3 in user_ids
        enemy_index = user_ids.index(user_id_3)
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index]["sex"], equal_to(0),
                    "response sex mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")

        assert res_data["reward_list"] != [], "response reward_list mismatch..."
        reward_player_ids = []
        for j in res_data["reward_list"]:
            assert_that(j, has_key("be_reward_user_id"),
                        "no be_reward_user_id response...")
            reward_player_ids.append(j["be_reward_user_id"])
        assert user_id_3 in reward_player_ids, "attack_user not in reward_list..."
        user_id_3_index = reward_player_ids.index(user_id_3)
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("user_id"), "no user_id response...")
        assert_that(res_data["reward_list"][user_id_3_index]["user_id"],
                    equal_to(user_id_2), "response user_id mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_list"][user_id_3_index]["reward_type"],
                    equal_to(0), "response reward_type mismatch...")

    def test_attack_pet_friend(self):
        """
        好友玩家攻击成功,加入仇人列表\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家2:"
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        print "创建好友玩家1:"
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        self.ar_con.add_friend(user_id_2)
        print "玩家2同意添加好友:"
        self.ar_con2.get_rev()
        self.ar_con2.deal_add_friend(user_id_1, 1)
        print "玩家1执行操作:"
        self.ar_con.get_rev()
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "玩家2攻击1:"
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.ar_con2.attack_pet(part, user_id_1)
        print "玩家1获取仇人列表:"
        self.ar_con.get_rev()
        time.sleep(1)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)

        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_2 in user_ids
        enemy_index = user_ids.index(user_id_2)
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index]["nick_name"],
                    equal_to(nick_name_2), "response nick_name mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index]["sex"], equal_to(0),
                    "response sex mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")

    def test_get_enemy_list_reward_player_normal(self):
        """
        获取仇人列表--悬赏仇人后,加入悬赏令列表(普通通缉令)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)
        print "悬赏令使用者获取仇人列表:"
        self.ar_con.get_rev()
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_3 in user_ids
        enemy_index = user_ids.index(user_id_3)
        assert_that(res_data["enemy_list"][enemy_index], has_key("user_id"),
                    "no user_id response...")
        assert_that(res_data["enemy_list"][enemy_index]["user_id"],
                    equal_to(user_id_3), "response user_id mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("pet_id"),
                    "no pet_id response...")

        print "悬赏令使用者通缉攻击者后,查询仇人列表:"
        self.ar_con.reward_player(0, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_3 in user_ids
        enemy_index = user_ids.index(user_id_3)
        assert_that(res_data["enemy_list"][enemy_index], has_key("user_id"),
                    "no user_id response...")
        assert_that(res_data["enemy_list"][enemy_index]["user_id"],
                    equal_to(user_id_3), "response user_id mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("pet_id"),
                    "no pet_id response...")

        reward_player_ids = []
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["reward_list"] != [], "response reward_list mismatch..."
        for j in res_data["reward_list"]:
            assert_that(j, has_key("be_reward_user_id"),
                        "no be_reward_user_id response...")
            reward_player_ids.append(j["be_reward_user_id"])
        assert user_id_3 in reward_player_ids, "attack_user not in reward_list..."
        user_id_3_index = reward_player_ids.index(user_id_3)
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("user_id"), "no user_id response...")
        assert_that(res_data["reward_list"][user_id_3_index]["user_id"],
                    equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_list"][user_id_3_index]["reward_type"],
                    equal_to(0), "response reward_type mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("end_time"), "no end_time response...")

    def test_get_enemy_list_reward_player_advance(self):
        """
        获取仇人列表---悬赏仇人后,加入悬赏令列表(高级通缉令)\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)
        print "悬赏令使用者获取仇人列表:"
        self.ar_con.get_rev()
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_3 in user_ids
        enemy_index = user_ids.index(user_id_3)
        assert_that(res_data["enemy_list"][enemy_index], has_key("user_id"),
                    "no user_id response...")
        assert_that(res_data["enemy_list"][enemy_index]["user_id"],
                    equal_to(user_id_3), "response user_id mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("pet_id"),
                    "no pet_id response...")

        print "悬赏令使用者通缉攻击者后,查询仇人列表:"
        self.ar_con.reward_player(1, user_id_3)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_3 in user_ids
        enemy_index = user_ids.index(user_id_3)
        assert_that(res_data["enemy_list"][enemy_index], has_key("user_id"),
                    "no user_id response...")
        assert_that(res_data["enemy_list"][enemy_index]["user_id"],
                    equal_to(user_id_3), "response user_id mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("pet_id"),
                    "no pet_id response...")

        reward_player_ids = []
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["reward_list"] != [], "response reward_list mismatch..."
        for j in res_data["reward_list"]:
            assert_that(j, has_key("be_reward_user_id"),
                        "no be_reward_user_id response...")
            reward_player_ids.append(j["be_reward_user_id"])
        assert user_id_3 in reward_player_ids, "attack_user not in reward_list..."
        user_id_3_index = reward_player_ids.index(user_id_3)
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("user_id"), "no user_id response...")
        assert_that(res_data["reward_list"][user_id_3_index]["user_id"],
                    equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_list"][user_id_3_index]["reward_type"],
                    equal_to(1), "response reward_type mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("end_time"), "no end_time response...")

    def test_get_enemy_list_reward_player_friend(self):
        """
        获取仇人列表--被悬赏玩家加入悬赏者好友的悬赏列表\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        print "创建悬赏令使用者:"
        account_id_1 = CoRand.get_rand_int(100001)
        uc_id_1 = CoRand.get_rand_int()
        res = self.ar_con.login(account_id_1, "im", uc_id_1)
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name_1 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name_1)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_1 = res_data["item_id"]
        self.ar_con.capture_pet(item_id_1)
        self.ar_con.set_cultivate_pet(item_id_1)
        part_1 = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part_1)
        print "创建好友玩家:"
        account_id_2 = CoRand.get_rand_int(100001)
        uc_id_2 = CoRand.get_rand_int()
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        res = self.ar_con2.login(account_id_2, "im", uc_id_2)
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name_2 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name_2)
        self.ar_con2.add_friend(user_id_1)
        print "悬赏令使用者同意添加好友:"
        self.ar_con.get_rev()
        self.ar_con.deal_add_friend(user_id_2, 1)

        print "好友玩家收到消息:"
        self.ar_con2.get_rev()

        print "创建攻击者玩家:"
        account_id_3 = CoRand.get_rand_int(100001)
        uc_id_3 = CoRand.get_rand_int()
        self.ar_con3 = ARControl()
        self.ar_con3.connect_server()
        res = self.ar_con3.login(account_id_3, "im", uc_id_3)
        res_data = json.loads(res)
        user_id_3 = res_data["user_id"]
        nick_name_3 = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con3.modify_info(nick_name_3)
        res = self.ar_con3.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_3 = res_data["item_id"]
        self.ar_con3.capture_pet(item_id_3)
        self.ar_con3.set_cultivate_pet(item_id_3)
        part_3 = CoRand.get_rand_int(1, 5)
        self.ar_con3.upgrade_pet_part(part_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "guidance", 131071)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.sql = ModifySql()
        self.sql.update_user(user_id_3, "lottery_type", 104)
        self.ar_con3.gm_reload_user_data(user_id_3)
        self.ar_con3.attack_pet(part_1, user_id_1)

        print "悬赏令使用者通缉攻击者:"
        self.ar_con.get_rev()
        self.ar_con.reward_player(0, user_id_3)

        print "好友玩家收到消息:"
        self.ar_con2.get_rev()
        res = self.ar_con2.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["reward_list"] != [], "response reward_list mismatch..."
        reward_player_ids = []
        for j in res_data["reward_list"]:
            assert_that(j, has_key("be_reward_user_id"),
                        "no be_reward_user_id response...")
            reward_player_ids.append(j["be_reward_user_id"])
        assert user_id_3 in reward_player_ids, "attack_user not in reward_list..."
        user_id_3_index = reward_player_ids.index(user_id_3)
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_id"), "no reward_id response...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("user_id"), "no user_id response...")
        assert_that(res_data["reward_list"][user_id_3_index]["user_id"],
                    equal_to(user_id_1), "response user_id mismatch...")
        assert_that(res_data["reward_list"][user_id_3_index],
                    has_key("reward_type"), "no reward_type response...")
        assert_that(res_data["reward_list"][user_id_3_index]["reward_type"],
                    equal_to(0), "response reward_type mismatch...")

    def test_get_enemy_list_attacker_can_not_attack(self):
        """
        攻击自己的非好友玩家养成宠不可被攻击,加入仇人列表\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家A:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建玩家B攻击A,B当前养成宠未升级,不可攻击:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        user2_coin_before = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        win_coin = res_data["win_coin"]
        assert_that(res_data["coin"], equal_to(user2_coin_before + win_coin),
                    "response coin mismatch...")
        print "玩家A查看仇人列表:"
        self.ar_con.get_rev()
        time.sleep(1)
        res = self.ar_con.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data["enemy_list"] != [], "response enemy_list mismatch..."
        user_ids = []
        for i in res_data["enemy_list"]:
            assert_that(i, has_key("user_id"), "no user_id response...")
            user_ids.append(i["user_id"])
        assert user_id_2 in user_ids
        enemy_index = user_ids.index(user_id_2)
        assert_that(res_data["enemy_list"][enemy_index], has_key("nick_name"),
                    "no nick_name response...")
        assert_that(res_data["enemy_list"][enemy_index]["nick_name"],
                    equal_to(nick_name), "response nick_name mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("sex"),
                    "no sex response...")
        assert_that(res_data["enemy_list"][enemy_index]["sex"], equal_to(0),
                    "response sex mismatch...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("icon"),
                    "no icon response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("star"),
                    "no star response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("can_attack"),
                    "no can_attack response...")
        assert_that(res_data["enemy_list"][enemy_index], has_key("attack"),
                    "no attack response...")
        assert_that(res_data["enemy_list"][enemy_index]["attack"], equal_to(1),
                    "response attack mismatch...")

    def test_enemy_list_attack_first(self):
        """
        A攻击B,B复仇,B不加入A的仇人列表\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        account_id_1 = CoRand.get_rand_int(100001)
        account_id_2 = CoRand.get_rand_int(100001)
        self.ar_con2 = ARControl()
        self.ar_con2.connect_server()
        print "创建玩家B:"
        res = self.ar_con.login(account_id_1, "im")
        res_data = json.loads(res)
        user_id_1 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con.modify_info(nick_name)
        res = self.ar_con.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id = res_data["item_id"]
        self.ar_con.capture_pet(item_id)
        self.ar_con.set_cultivate_pet(item_id)
        part = CoRand.get_rand_int(1, 5)
        self.ar_con.upgrade_pet_part(part)
        print "创建玩家A攻击B:"
        res = self.ar_con2.login(account_id_2, "im")
        res_data = json.loads(res)
        user_id_2 = res_data["user_id"]
        nick_name = CoRand.get_random_word_filter_sensitive(6)
        self.ar_con2.modify_info(nick_name)
        res = self.ar_con2.scan_face(self.pet_url, "la", 1)
        res_data = json.loads(res)
        item_id_2 = res_data["item_id"]
        self.ar_con2.capture_pet(item_id_2)
        self.ar_con2.set_cultivate_pet(item_id_2)
        part_2 = CoRand.get_rand_int(1, 5)
        self.ar_con2.upgrade_pet_part(part_2)
        res = self.ar_con2.get_user_info(user_id_2)
        res_data = json.loads(res)
        user2_coin_before = res_data["coin"]
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "guidance", 131071)
        self.ar_con2.gm_reload_user_data(user_id_2)
        self.sql = ModifySql()
        self.sql.update_user(user_id_2, "lottery_type", 104)
        self.ar_con2.gm_reload_user_data(user_id_2)
        res = self.ar_con2.attack_pet(part, user_id_1)
        res_data = json.loads(res)
        assert_that(res_data, has_key("coin"), "no coin response...")
        assert_that(res_data, has_key("win_coin"), "no win_coin response...")
        win_coin = res_data["win_coin"]
        assert_that(res_data["coin"], equal_to(user2_coin_before + win_coin),
                    "response coin mismatch...")
        print "玩家B复仇,攻击A:"
        self.ar_con.get_rev()
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "guidance", 131071)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.sql = ModifySql()
        self.sql.update_user(user_id_1, "lottery_type", 104)
        self.ar_con.gm_reload_user_data(user_id_1)
        self.ar_con.attack_pet(part_2, user_id_2)

        print "获取A的仇人列表:"
        self.ar_con2.get_rev()
        res = self.ar_con2.get_enemy_list()
        res_data = json.loads(res)
        assert_that(res_data, has_key("enemy_list"),
                    "no enemy_list response...")
        assert res_data["enemy_list"] == [], "response enemy_list mismatch..."
        assert_that(res_data, has_key("reward_list"),
                    "no reward_list response...")
        assert res_data[
            "reward_list"] == [], "response reward_list mismatch..."