class EvolutionPetTest(unittest.TestCase): def setUp(self): print 'start run EvolutionPet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() def tearDown(self): print 'EvolutionPet test complete.....close socket' def test_evolution_pet_success(self): """ 进化宠物成功\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_pet_list(user_id) res_data = json.loads(res) pet_id = res_data[0]["pet_id"] res = self.ar_con.get_pet_info(pet_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no id response...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "user_id not match...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("quality"), "no quality response...") assert_that(res_data, has_key("evolution_type"), "no evolution_type response...") assert_that(res_data, has_key("lookface"), "no lookface response...") assert_that(res_data, has_key("power"), "no power response...") assert_that(res_data, has_key("level"), "no level response...") assert_that(res_data, has_key("exp"), "no exp response...") assert_that(res_data, has_key("hp"), "no hp response...") assert_that(res_data, has_key("is_capture"), "no isCapture response...") assert_that(res_data, has_key("atk"), "no atk response...") assert_that(res_data, has_key("hit_rate"), "no hit_rate response...") assert_that(res_data, has_key("dodge_rate"), "no dodge_rate response...") assert_that(res_data, has_key("crit_rate"), "no crit_rate response...") assert_that(res_data, has_key("anti_crit_rate"), "no anti_crit_rate response...") assert_that(res_data, has_key("skill1"), "no skill1 response...") assert_that(res_data, has_key("skill1_level"), "no skill1_level response...") assert_that(res_data, has_key("skill2"), "no skill2 response...") assert_that(res_data, has_key("skill2_level"), "no skill2_level response...") assert_that(res_data, has_key("skill3"), "no skill3 response...") assert_that(res_data, has_key("skill3_level"), "no skill3_level response...") assert_that(res_data, has_key("skill4"), "no skill4 response...") assert_that(res_data, has_key("skill4_level"), "no skill4_level response...")
class GetApartmentSweepInfoTest(unittest.TestCase): """ 查看公寓打扫信息 """ def setUp(self): print 'start run GetApartmentSweepInfo test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.account_id = 100861 def tearDown(self): print 'GetApartmentSweepInfo test complete.....close socket' def test_get_apartment_sweep_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"] apartment_code = 1 res = self.ar_con.get_all_apartment() res_data = json.loads(res) for apartment in res_data: if apartment["is_full"] == 1: apartment_code = apartment["apartment_code"] break res = self.ar_con.apply_apartment(apartment_code) res_data = json.loads(res) floor = res_data["floor"] pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.match_pet(pet_url) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) self.ar_con.sweep_apartment(apartment_code, user_id, floor) res = self.ar_con.get_apartment_sweep_info(apartment_code, user_id, floor) res_data = json.loads(res) assert_that(res_data, has_key("pet_info"), "no pet_info response...") assert_that(res_data, has_key("left_num"), "no left_num response...") assert_that(res_data, has_key("countdown"), "no countdown response...") assert_that(res_data["pet_info"], has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_info"], has_key("pet_code"), "no pet_code response...") assert_that(res_data["pet_info"], has_key("user_id"), "no user_id response...") assert_that(res_data["pet_info"], has_key("name"), "no name response...") assert_that(res_data["pet_info"], has_key("quality"), "no quality response...")
class GetSweepOtherRewardsTest(unittest.TestCase): """ 获取玩家打扫别人房间的奖励 """ def setUp(self): print 'start run GetSweepOtherRewards test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.account_id = 100861 def tearDown(self): print 'GetSweepOtherRewards test complete.....close socket' def test_get_sweep_other_rewards_success(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"] apartment_code_1 = 1 res = self.ar_con.get_all_apartment() res_data = json.loads(res) for apartment in res_data: if apartment["is_full"] == 1: apartment_code_1 = apartment["apartment_code"] break res = self.ar_con.apply_apartment(apartment_code_1) res_data = json.loads(res) floor_1 = res_data["floor"] self.ar_con.connect_server() account_id_2 = CoRand.get_rand_int(100001) self.ar_con.login(account_id_2, "im") pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.match_pet(pet_url) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) self.ar_con.sweep_apartment(apartment_code_1, user_id_1, floor_1) time.sleep(901) res = self.ar_con.get_sweep_other_rewards() res_data = json.loads(res) for rewards in res_data: assert_that(rewards, has_key("pet_id"), "no pet_id response...") assert_that(rewards, has_key("time"), "no time response...") assert_that(rewards, has_key("coin"), "no coin response...") assert_that(rewards, has_key("contribute_value"), "no contribute_value response...") assert_that(rewards, has_key("construct_value"), "no construct_value response...") assert_that(rewards, has_key("user_id"), "no user_id response...")
class GetMatchCountTest(unittest.TestCase): def setUp(self): print 'start run GetMatchCount test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() def tearDown(self): print 'GetMatchCount test complete.....close socket' def test_get_match_count_success(self): """ 获取剩余的捕获次数成功\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ self.ar_con.login(100861, "im") res = self.ar_con.get_match_count() res_data = json.loads(res) assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") assert_that(res_data, has_key("scan_advance"), "no scan_advance response...") def test_get_match_count_after_capture(self): """ 捕获宠物后次数减一\ 【暂时去除次数限制,后期待更新】 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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_match_count() res_data = json.loads(res) before_count = res_data["scan_advance"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) self.ar_con.capture_pet(res_data["item_id"]) res = self.ar_con.get_match_count() res_data = json.loads(res) after_count = res_data["scan_advance"] assert_that(before_count - after_count, equal_to(1), "get_match_count result error...")
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错误")
class SetFollowPetTest(unittest.TestCase): def setUp(self): print 'start run SetFollowPet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "setFollowPet" self.account_id = 100861 def tearDown(self): print 'SetFollowPet test complete.....close socket' def test_set_follow_pet_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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] res = self.ar_con.set_follow_pet(theme_park_id, pet_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...") res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no pet_id1 response...") assert_that(res_data["star"], equal_to(star), "response pet_id1 error...") def test_set_follow_pet_from_stage_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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] self.ar_con.equip_pet(theme_park_id, pet_id, 1) res = self.ar_con.set_follow_pet(theme_park_id, pet_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_PET_NOT_FREE["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_PET_NOT_FREE["err_msg"]), "response msg mismatching...") res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no pet_id1 response...") assert_that(res_data["star"], equal_to(star + 1), "response pet_id1 error...") def test_set_follow_pet_error_theme_park(self): """ 设置随身宠失败,错误的乐园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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) pet_id = res_data["follow_pet_id"] theme_park_id = CoRand.get_rand_int() res = self.ar_con.set_follow_pet(theme_park_id, pet_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_NO_FOUND_PLAYER_PARK["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NO_FOUND_PLAYER_PARK["err_msg"]), "response msg mismatching...") def test_set_follow_pet_error_pet(self): """ 设置随身宠失败,错误的宠物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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] pet_id = CoRand.get_rand_int() res = self.ar_con.set_follow_pet(theme_park_id, pet_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_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]), "response msg mismatching...") def test_set_follow_pet_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 EquipPetTest(unittest.TestCase): def setUp(self): print 'start run EquipPet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "equipPet" self.account_id = 100861 def tearDown(self): print 'EquipPet test complete.....close socket' def test_equip_pet_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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] pos = CoRand.get_rand_int(1, 5) res = self.ar_con.equip_pet(theme_park_id, pet_id, pos) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no star response...") assert_that(res_data["star"], equal_to(star + 1), "response star error...") res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) assert_that(res_data, has_key("pet_id" + str(pos)), "no pet_id1 response...") assert_that(res_data["pet_id" + str(pos)], equal_to(pet_id), "response pet_id1 error...") def test_equip_pet_already_equipped(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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id_1 = res_data["pet_id"] self.ar_con.capture_pet(pet_id_1) res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id_2 = res_data["pet_id"] self.ar_con.capture_pet(pet_id_2) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] self.ar_con.equip_pet(theme_park_id, pet_id_1, 1) res = self.ar_con.equip_pet(theme_park_id, pet_id_2, 1) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no star response...") assert_that(res_data["star"], equal_to(star + 1), "response star error...") res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) assert_that(res_data, has_key("pet_id1"), "no pet_id1 response...") assert_that(res_data["pet_id1"], equal_to(pet_id_2), "response pet_id1 error...") def test_equip_pet_without_pos(self): """ 装备宠物成功,未传pos,默认第一个位置\ 开发:黄良江(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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] json_body = {"theme_park_id": theme_park_id, "pet_id": pet_id} res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no star response...") assert_that(res_data["star"], equal_to(star + 1), "response star error...") res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) assert_that(res_data, has_key("pet_id1"), "no pet_id1 response...") assert_that(res_data["pet_id1"], equal_to(pet_id), "response pet_id1 error...") def test_equip_pet_error_pos(self): """ 装备宠物成功,pos值非法,默认为第五个位置\ 开发:黄良江(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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] pos = CoRand.get_rand_int() res = self.ar_con.equip_pet(theme_park_id, pet_id, pos) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no star response...") assert_that(res_data["star"], equal_to(star + 1), "response star error...") res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) assert_that(res_data, has_key("pet_id5"), "no pet_id1 response...") assert_that(res_data["pet_id5"], equal_to(pet_id), "response pet_id1 error...") def test_equip_pet_from_follow_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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] pet_id = res_data["follow_pet_id"] res = self.ar_con.equip_pet(theme_park_id, pet_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_PET_NOT_FREE["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_PET_NOT_FREE["err_msg"]), "response msg mismatching...") def test_equip_pet_error_theme_park(self): """ 装备宠物失败,错误的乐园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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) pet_id = res_data["follow_pet_id"] theme_park_id = CoRand.get_rand_int() res = self.ar_con.equip_pet(theme_park_id, pet_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_NO_FOUND_PLAYER_PARK["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NO_FOUND_PLAYER_PARK["err_msg"]), "response msg mismatching...") def test_equip_pet_error_pet(self): """ 装备宠物失败,错误的宠物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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] pet_id = CoRand.get_rand_int() res = self.ar_con.equip_pet(theme_park_id, pet_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_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_equip_pet_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 CapturePetTest(unittest.TestCase): def setUp(self): print 'start run CapturePet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "capturePet" def tearDown(self): print 'CapturePet test complete.....close socket' def test_capture_pet_success(self): """ 捕获宠物成功\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] res = self.ar_con.capture_pet(item_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...") res = self.ar_con.get_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data["user_id"], equal_to(user_id), "pet uncapture ...") def test_capture_pet_has_been_captured(self): """ 捕获已被捕获的宠物\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) self.ar_con.connect_server() account_id_2 = CoRand.get_rand_int(100001) self.ar_con.login(account_id_2, "im") nick_name_2 = CoRand.get_random_word_filter_sensitive(6) self.ar_con.modify_info(nick_name_2) res = self.ar_con.capture_pet(item_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_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]), "response msg mismatching...") def test_capture_pet_with_not_exist_pet(self): """ 捕获宠物失败,不存在的宠物ID\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ self.ar_con.login(100861, "im") item_id = CoRand.get_rand_int() json_body = {"pet_id": item_id} 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_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_capture_pet_with_error_param(self): """ 捕获宠物失败,错误的参数\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ self.ar_con.login(100861, "im") json_body = {"pets_id": 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...") def test_capture_pet_without_param(self): """ 捕获宠物失败,未传参数\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "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 SellPetTest(unittest.TestCase): """ 出售宠物 """ def setUp(self): print 'start run SellPet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" def tearDown(self): print 'SellPet test complete.....close socket' def test_sell_pet_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"] pet_ids = [] res = self.ar_con.scan_face(self.pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) pet_ids.append(res_data["pet_id"]) res = self.ar_con.sell_pet(pet_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_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_pet_info(pet_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_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]), "response msg mismatching...") def test_sell_pet_batch_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"] pet_ids = [] for x in range(0, 5): res = self.ar_con.scan_face(self.pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) pet_ids.append(res_data["pet_id"]) res = self.ar_con.sell_pet(pet_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_SUCCESS["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_SUCCESS["err_msg"]), "response msg mismatching...") def test_sell_pet_notexist(self): """ 出售不存在的宠物\ 开发:黄良江(900000)\ 测试:林冰晶(791099) 目前提示参数错误,建议修改 """ self.ar_con.login(100861, "im") pet_ids = [] pet_id = CoRand.get_rand_int() pet_ids.append(pet_id) res = self.ar_con.sell_pet(pet_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_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 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 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...")
class GetPetListTest(unittest.TestCase): def setUp(self): print 'start run GetPetList test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.account_id = 100861 self.api_name = "getPetList" def tearDown(self): print 'GetPetList test complete.....close socket' def test_get_pet_list_success(self): """ 获取其他玩家宠物列表成功\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) self.ar_con.connect_server() self.ar_con.login(self.account_id, "im") res = self.ar_con.get_pet_list(user_id_1) res_data = json.loads(res) for petinfo in res_data: assert_that(petinfo, has_key("pet_id"), "no item_id response...") assert_that(petinfo, has_key("user_id"), "no user_id response...") assert_that(petinfo["user_id"], equal_to(user_id_1), "response user_id mismatching...") assert_that(petinfo, has_key("pet_code"), "no pet_code response...") assert_that(petinfo, has_key("name"), "no name response...") assert_that(petinfo, has_key("is_capture"), "no is_capture response...") assert_that(petinfo, has_key("head_status"), "no head_status response...") assert_that(petinfo, has_key("head_level"), "no head_level response...") assert_that(petinfo, has_key("arm_status"), "no arm_status response...") assert_that(petinfo, has_key("arm_level"), "no arm_level response...") assert_that(petinfo, has_key("clothes_status"), "no clothes_status response...") assert_that(petinfo, has_key("clothes_level"), "no clothes_level response...") assert_that(petinfo, has_key("shoes_status"), "no shoes_status response...") assert_that(petinfo, has_key("shoes_level"), "no shoes_level response...") assert_that(petinfo, has_key("skirt_status"), "no skirt_status response...") assert_that(petinfo, has_key("skirt_level"), "no skirt_level response...") assert_that(petinfo, has_key("pet_idx"), "no item_idx response...") assert_that(petinfo, has_key("is_complete"), "no is_complete response...") def test_get_pet_list_without_params(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) json_body = {} res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) for petinfo in res_data: assert_that(petinfo, has_key("pet_id"), "no item_id response...") assert_that(petinfo, has_key("user_id"), "no user_id response...") assert_that(petinfo["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(petinfo, has_key("pet_code"), "no pet_code response...") assert_that(petinfo, has_key("name"), "no name response...") def test_get_pet_list_user_id_error(self): """ 获取宠物列表失败,用户id错误\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(self.account_id, "im") user_id = CoRand.randomword(8) json_body = { "user_id": user_id } 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 GetPetInfoTest(unittest.TestCase): def setUp(self): print 'start run GetPetInfo test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "getPetInfo" self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" def tearDown(self): print 'GetPetInfo test complete.....close socket' def test_get_pet_info_success(self): """ 获取宠物信息成功,查看自己的宠物信息\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_pet_list(user_id) res_data = json.loads(res) pet_id = res_data[0]["pet_id"] json_body = { "pet_id": pet_id } res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") assert_that(res_data, has_key("head_status"), "no head_status response...") assert_that(res_data, has_key("head_level"), "no head_level response...") assert_that(res_data, has_key("arm_status"), "no arm_status response...") assert_that(res_data, has_key("arm_level"), "no arm_level response...") assert_that(res_data, has_key("clothes_status"), "no clothes_status response...") assert_that(res_data, has_key("clothes_level"), "no clothes_level response...") assert_that(res_data, has_key("shoes_status"), "no shoes_status response...") assert_that(res_data, has_key("shoes_level"), "no shoes_level response...") assert_that(res_data, has_key("skirt_status"), "no skirt_status response...") assert_that(res_data, has_key("skirt_level"), "no skirt_level response...") assert_that(res_data, has_key("pet_idx"), "no pet_idx response...") assert_that(res_data, has_key("is_complete"), "no is_complete response...") def test_get_pet_info_has_glass(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) url = "http://192.168.239.119:807/ARTest/glass_true/1.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] self.ar_con.capture_pet(pet_id) json_body = { "pet_id": pet_id } res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(1), "response has_glass mismatching...") assert_that(res_data, has_key("head_status"), "no head_status response...") assert_that(res_data, has_key("head_level"), "no head_level response...") assert_that(res_data, has_key("arm_status"), "no arm_status response...") assert_that(res_data, has_key("arm_level"), "no arm_level response...") assert_that(res_data, has_key("clothes_status"), "no clothes_status response...") assert_that(res_data, has_key("clothes_level"), "no clothes_level response...") assert_that(res_data, has_key("shoes_status"), "no shoes_status response...") assert_that(res_data, has_key("shoes_level"), "no shoes_level response...") assert_that(res_data, has_key("skirt_status"), "no skirt_status response...") assert_that(res_data, has_key("skirt_level"), "no skirt_level response...") assert_that(res_data, has_key("pet_idx"), "no pet_idx response...") assert_that(res_data, has_key("is_complete"), "no is_complete response...") def test_get_pet_info_not_has_glass(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) url = "http://192.168.239.119:807/ARTest/glass_false/1.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] self.ar_con.capture_pet(pet_id) json_body = { "pet_id": pet_id } res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(0), "response has_glass mismatching...") assert_that(res_data, has_key("head_status"), "no head_status response...") assert_that(res_data, has_key("head_level"), "no head_level response...") assert_that(res_data, has_key("arm_status"), "no arm_status response...") assert_that(res_data, has_key("arm_level"), "no arm_level response...") assert_that(res_data, has_key("clothes_status"), "no clothes_status response...") assert_that(res_data, has_key("clothes_level"), "no clothes_level response...") assert_that(res_data, has_key("shoes_status"), "no shoes_status response...") assert_that(res_data, has_key("shoes_level"), "no shoes_level response...") assert_that(res_data, has_key("skirt_status"), "no skirt_status response...") assert_that(res_data, has_key("skirt_level"), "no skirt_level response...") assert_that(res_data, has_key("pet_idx"), "no pet_idx response...") assert_that(res_data, has_key("is_complete"), "no is_complete response...") def test_get_pet_info_no_exist(self): """ 获取不存在宠物信息\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ res = self.ar_con.login(100861, "im") res_data = json.loads(res) user_id = res_data["user_id"] pet_id = 100861 res = self.ar_con.get_pet_info(pet_id, 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_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]), "response msg mismatching...") def test_get_pet_info_others_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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] self.ar_con.capture_pet(pet_id) self.ar_con.connect_server() self.ar_con.login(100861, "im") res = self.ar_con.get_pet_info(pet_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") def test_get_pet_info_no_cultivate_pet(self): """ 获取宠物信息:未传item_id和user_id,查看玩家当前养成宠信息(玩家未设置养成宠)\ 开发:黄良江(900000)\ 测试:魏春旺(100861) """ 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"] 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_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_get_pet_info_without_item_id_and_user_id(self): """ 获取宠物信息,未传item_id和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) 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 = {} res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(0), "response has_glass mismatching...") assert_that(res_data, has_key("head_status"), "no head_status response...") assert_that(res_data, has_key("head_level"), "no head_level response...") assert_that(res_data, has_key("arm_status"), "no arm_status response...") assert_that(res_data, has_key("arm_level"), "no arm_level response...") assert_that(res_data, has_key("clothes_status"), "no clothes_status response...") assert_that(res_data, has_key("clothes_level"), "no clothes_level response...") assert_that(res_data, has_key("shoes_status"), "no shoes_status response...") assert_that(res_data, has_key("shoes_level"), "no shoes_level response...") assert_that(res_data, has_key("skirt_status"), "no skirt_status response...") assert_that(res_data, has_key("skirt_level"), "no skirt_level response...") assert_that(res_data, has_key("pet_idx"), "no pet_idx response...") assert_that(res_data, has_key("is_complete"), "no is_complete response...") def test_get_pet_info_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) 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) json_body = { "pet_id": pet_id } res = self.ar_con.get_res(self.api_name, json_body) res_data = json.loads(res) assert_that(res_data, has_key("pet_id"), "no pet_id response...") assert_that(res_data["pet_id"], equal_to(pet_id), "response pet_id mismatching...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "response user_id mismatching...") assert_that(res_data, has_key("pet_code"), "no pet_code response...") assert_that(res_data, has_key("name"), "no name response...") assert_that(res_data, has_key("is_capture"), "no is_capture response...") assert_that(res_data["is_capture"], equal_to(1), "response is_capture mismatching...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(0), "response has_glass mismatching...") assert_that(res_data, has_key("head_status"), "no head_status response...") assert_that(res_data, has_key("head_level"), "no head_level response...") assert_that(res_data, has_key("arm_status"), "no arm_status response...") assert_that(res_data, has_key("arm_level"), "no arm_level response...") assert_that(res_data, has_key("clothes_status"), "no clothes_status response...") assert_that(res_data, has_key("clothes_level"), "no clothes_level response...") assert_that(res_data, has_key("shoes_status"), "no shoes_status response...") assert_that(res_data, has_key("shoes_level"), "no shoes_level response...") assert_that(res_data, has_key("skirt_status"), "no skirt_status response...") assert_that(res_data, has_key("skirt_level"), "no skirt_level response...") assert_that(res_data, has_key("pet_idx"), "no pet_idx response...") assert_that(res_data, has_key("is_complete"), "no is_complete response...")
class CancelReadyTest(unittest.TestCase): """ 取消战斗准备 """ def setUp(self): print 'start run CancelReady test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.room_id = 0 def tearDown(self): if self.room_id != 0: self.ar_con.leave_room(self.room_id) print 'leave room complete...' print 'CancelReady test complete.....close socket' def test_cancel_ready_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) pet_member = [] for A in range(0, 3): pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] self.ar_con.set_def_pet_team(pet_member, team_code) res = self.ar_con.get_room_list() res_data = json.loads(res) assert_that(res_data, has_key("list"), "no list response...") for room in res_data["list"]: assert_that(room, has_key("player_count"), "no player_count response...") if room["player_count"] == 0: self.room_id = room["room_id"] break self.ar_con.join_room(self.room_id) self.ar_con.ready_battle() res = self.ar_con.cancel_ready() 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_cancel_ready_not_join(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.cancel_ready() 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_JOIN_ANY_ROOM["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_USER_NOT_JOIN_ANY_ROOM["err_msg"]), "response msg mismatching...")
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...")
class SellItemTest(unittest.TestCase): """ 出售物品 """ def setUp(self): print 'start run SellItem test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "sellItem" self.account_id = 100861 def tearDown(self): print 'SellItem test complete.....close socket' def test_sell_item_face_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.get_user_info(user_id) res_data = json.loads(res) coin_before = res_data["coin"] photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) res = self.ar_con.sell_item(item_id, 3, 1) res_data = json.loads(res) assert_that(res_data, has_key("gain_coin"), "no gain_coin response...") gain_coin = res_data["gain_coin"] assert_that(res_data, has_key("coin"), "no coin response...") assert_that(res_data["coin"], equal_to(coin_before + gain_coin), "coin mismatch...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(0), "item_count mismatch...") def test_sell_item_protozoan_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.get_user_info(user_id) res_data = json.loads(res) coin_before = res_data["coin"] photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 0) res_data = json.loads(res) assert_that(res_data, has_key("item_type"), "no item_type response...") assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] if res_data["item_type"] == 0: print "出售灵魂宠:" res = self.ar_con.sell_item(item_id, 0, 1) res_data = json.loads(res) assert_that(res_data, has_key("gain_coin"), "no gain_coin response...") gain_coin = res_data["gain_coin"] assert_that(res_data, has_key("coin"), "no coin response...") assert_that(res_data["coin"], equal_to(coin_before + gain_coin), "coin mismatch...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(0), "item_count mismatch...") elif res_data["item_type"] == 1: print "出售原生宠" res = self.ar_con.sell_item(item_id, 1, 1) res_data = json.loads(res) assert_that(res_data, has_key("gain_coin"), "no gain_coin response...") gain_coin = res_data["gain_coin"] assert_that(res_data, has_key("coin"), "no coin response...") assert_that(res_data["coin"], equal_to(coin_before + gain_coin), "coin mismatch...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(0), "item_count mismatch...") def test_sell_item_no_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.sell_item(8013, 3, 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_sell_item_face_pet_not_catch(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"] photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] res = self.ar_con.sell_item(item_id, 3, 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_PET_NOT_CAPTURE["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_PET_NOT_CAPTURE["err_msg"]), "response msg mismatching...") def test_sell_item_face_pet_not_enough(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"] photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id_1 = res_data["item_id"] self.ar_con.capture_pet(item_id_1) self.ar_con.get_pet_list(user_id) res = self.ar_con.sell_item(item_id_1, 3, 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_ENOUGH_ITEM["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_ENOUGH_ITEM["err_msg"]), "response msg mismatching...") def test_sell_item_multiple(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"] photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" soul_pet_num = 0 for i in range(0, 10): res = self.ar_con.scan_face(url, "la", 0) res_data = json.loads(res) if res_data["item_type"] == 0: assert_that(res_data, has_key("item_id"), "no item_id response...") item_id_soul = res_data["item_id"] soul_pet_num += 1 if soul_pet_num != 0: res = self.ar_con.sell_item(item_id_soul, 0, soul_pet_num) res_data = json.loads(res) assert_that(res_data, has_key("gain_coin"), "no gain_coin response...") assert_that(res_data["gain_coin"], equal_to(3000 * soul_pet_num), "gain_coin mismatch...") assert_that(res_data, has_key("coin"), "no coin response...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(0), "item_count mismatch...") def test_sell_item_cultivate(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) self.ar_con.set_cultivate_pet(item_id) res = self.ar_con.sell_item(item_id, 3, 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_COMPLETE_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_COMPLETE_PET["err_msg"]), "response msg mismatching...") def test_sell_item_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_sell_item_without_item_id(self): """ 出售物品--缺少参数item_id\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(self.account_id, "im") json_body = {"item_type": 0, "item_count": 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_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_sell_item_without_item_type(self): """ 出售物品--缺少参数item_type\ 开发:黄良江(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) json_body = {"item_id": item_id, "item_count": 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_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_sell_item_without_item_count(self): """ 出售物品--缺少参数item_count\ 开发:黄良江(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) json_body = {"item_id": item_id, "item_type": 3} 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_sell_item_face_pet_error_item_type(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) res = self.ar_con.sell_item(item_id, 2, 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_UNKNOWN_ITEM_TYPE["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_UNKNOWN_ITEM_TYPE["err_msg"]), "response msg mismatching...") def test_sell_item_that_item_id_not_own(self): """ 出售物品--非玩家物品id\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ print "玩家A获取人脸宠:" 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) url = "http://192.168.239.119:807/ARTest/glass_true/1.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) print "玩家B出售A的人脸宠:" self.ar_con.connect_server() self.ar_con.login(self.account_id, "im") res = self.ar_con.sell_item(item_id, 3, 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...")
class ScanFaceTest(unittest.TestCase): """ 人脸扫描 """ def setUp(self): print 'start run ScanFace test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "scanFace" self.account_id = 100861 def tearDown(self): print 'ScanFace test complete.....close socket' def test_scan_face_advance_with_glass(self): """ 人脸扫描--使用高级扫描卡,戴眼镜==》高级扫描次数-1,出人脸宠,自定义命名无效\ 开发:黄良江(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) scan_advance_before = res_data["scan_advance"] scan_advance = CoRand.get_rand_int(1, 10000) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_true/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", scan_advance) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_type"), "no item_type response...") assert_that(res_data["item_type"], equal_to(3), "item_type mismatch...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(1), "item_count mismatch...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(1), "response has_glass mismatch...") assert_that(res_data, has_key("scan_advance"), "no scan_advance response...") assert_that(res_data["scan_advance"], equal_to(scan_advance_before - 1), "scan_advance mismatch...") item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) res = self.ar_con.get_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("name"), "no name response...") assert res_data["name"] != "la", "宠物名称错误" def test_scan_face_advance_no_glass(self): """ 人脸扫描--使用高级扫描卡,不戴眼镜,高级扫描次数-1,出人脸宠\ 开发:黄良江(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) scan_advance_before = res_data["scan_advance"] scan_advance = CoRand.get_rand_int(1, 10000) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_false/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", scan_advance) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_type"), "no item_type response...") assert_that(res_data["item_type"], equal_to(3), "item_type mismatch...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, has_key("has_glass"), "no has_glass response...") assert_that(res_data["has_glass"], equal_to(0), "response has_glass mismatch...") assert_that(res_data, has_key("scan_advance"), "no scan_advance response...") assert_that(res_data["scan_advance"], equal_to(scan_advance_before - 1), "scan_advance mismatch...") def test_scan_face_normal(self): """ 人脸扫描--使用普通扫描卡,普通扫描次数-1,可以生成灵魂宠、原生宠、金币\ 开发:黄良江(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 0) res_data = json.loads(res) assert_that(res_data, has_key("item_type"), "no item_type response...") if res_data["item_type"] == 0: print "生成灵魂宠" assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, not has_key("item_code"), "灵魂宠没有item_code字段") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data["item_count"], equal_to(1), "item_count mismatch...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, not has_key("has_glass"), "no has_glass response...") assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") item_id = res_data["item_id"] res = self.ar_con.get_soul_pet_list(user_id) res_data = json.loads(res) assert_that(res_data[0], has_key("item_id"), "no item_id response...") assert_that(res_data[0]["item_id"], equal_to(item_id), "item_id mismatch...") assert_that(res_data[0], has_key("item_name"), "no item_name response...") assert res_data[0]["item_name"] == "la", "灵魂宠名称错误" elif res_data["item_type"] == 1: print "生成原生宠" assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, not has_key("has_glass"), "no has_glass response...") assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") item_id = res_data["item_id"] res = self.ar_con.get_protozoan_list(user_id) res_data = json.loads(res) assert_that(res_data[0], has_key("item_id"), "no item_id response...") assert_that(res_data[0]["item_id"], equal_to(item_id), "item_id mismatch...") assert_that(res_data[0], has_key("item_name"), "no item_name response...") assert res_data[0]["item_name"] != "la", "原生宠名称错误" elif res_data["item_type"] == 2: print "生成金币" assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, not has_key("has_glass"), "no has_glass response...") assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") def test_scan_face_without_scan_advance(self): """ 人脸扫描--不传scan_advance,默认使用普通扫描卡\ 开发:黄良江(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_false/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la") res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_type"), "no item_type response...") assert res_data["item_type"] != 3, "item_type mismatch..." assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, not has_key("has_glass"), "no has_glass response...") assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") def test_scan_face_scan_advance_less_than_0(self): """ 人脸扫描--scan_advance传负数,使用普通扫描卡\ 开发:黄良江(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) photo_id = CoRand.get_rand_int(1, 10) url = "http://192.168.239.119:807/ARTest/glass_false/" + str( photo_id) + ".jpg" res = self.ar_con.scan_face(url, "la", -100) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("item_type"), "no item_type response...") assert res_data["item_type"] != 3, "item_type mismatch..." assert_that(res_data, has_key("item_count"), "no item_count response...") assert_that(res_data, has_key("total_count"), "no total_count response...") assert_that(res_data, not has_key("has_glass"), "no has_glass response...") assert_that(res_data, has_key("scan_normal"), "no scan_normal response...") def test_scan_face_illegal_url(self): """ 人脸扫描--异常情况返回随机的识别结果\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "im") url = CoRand.randomword(8) res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) assert_that(res_data, has_key("item_id"), "no item_id response...") assert_that(res_data, has_key("item_code"), "no item_code response...") assert_that(res_data, has_key("scan_advance"), "no scan_advance response...") def test_scan_face_without_params(self): """ 人脸扫描--请求未带参数\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "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_scan_face_with_error_param(self): """ 人脸扫描--url参数名错误\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "im") json_body = { "url12": "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" } 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 LeaveRoomTest(unittest.TestCase): """ 离开房间 """ def setUp(self): print 'start run LeaveRoom test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.account_id = 100861 self.room_id = 0 self.api_name = "leaveRoom" def tearDown(self): print 'LeaveRoom test complete.....close socket' def test_leave_room_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) pet_member = [] for A in range(0, 3): pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] self.ar_con.set_def_pet_team(pet_member, team_code) res = self.ar_con.get_room_list() res_data = json.loads(res) assert_that(res_data, has_key("list"), "no list response...") for room in res_data["list"]: assert_that(room, has_key("player_count"), "no player_count response...") if room["player_count"] == 0: self.room_id = room["room_id"] break self.ar_con.join_room(self.room_id) res = self.ar_con.leave_room(self.room_id) res_data = json.loads(res) assert_that(res_data, has_key("room_id"), "no room_id response...") assert_that(res_data["room_id"], equal_to(self.room_id), "room_id mismatching...") def test_leave_room_not_join(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_room_list() res_data = json.loads(res) room_id = res_data["list"][0]["room_id"] res = self.ar_con.leave_room(room_id) res_data = json.loads(res) assert_that(res_data, has_key("room_id"), "no room_id response...") assert_that(res_data["room_id"], equal_to(room_id), "room_id mismatching...") # def test_leave_room_without_params(self): # """ # 离开房间失败,未传房间id\【目前返回{},待优化】 # 开发:黄良江(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) # 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_leave_room_error_room_id(self): """ 离开房间,错误的房间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) room_id = CoRand.get_rand_int(100) res = self.ar_con.leave_room(room_id) res_data = json.loads(res) assert_that(res_data, has_key("room_id"), "no room_id response...") assert_that(res_data["room_id"], equal_to(room_id), "room_id mismatching...")
class SetPetTagTest(unittest.TestCase): def setUp(self): print 'start run SetPetTag test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "setPetTag" def tearDown(self): print 'SetPetTag test complete.....close socket' def test_set_pet_tag_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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) tag = CoRand.get_random_word_filter_sensitive(25) res = self.ar_con.set_pet_tag(item_id, tag) 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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("tag"), "no tag response...") assert_that(res_data["tag"], equal_to(tag), "response tag mismatching...") def test_set_pet_tag_chinese(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) tag = CoRand.get_rand_chinese(5) res = self.ar_con.set_pet_tag(item_id, tag) 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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("tag"), "no tag response...") assert_that(res_data["tag"], equal_to(tag), "response tag mismatching...") def test_set_pet_tag_without_item_id(self): """ 设置宠物备注--请求参数缺少item_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) tag = CoRand.get_random_word_filter_sensitive(8) json_body = {"tag": tag} 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_set_pet_tag_without_tag(self): """ 设置宠物备注--请求参数缺少tag,取消备注\ 开发:黄良江(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) json_body = {"pet_id": item_id} 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_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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, not has_key("tag"), "no tag response...") def test_set_pet_tag_with_tag_null(self): """ 设置宠物备注--tag传空值,取消备注\ 开发:黄良江(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) tag = "" res = self.ar_con.set_pet_tag(item_id, tag) 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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, not has_key("tag"), "no tag response...") def test_set_pet_tag_update(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) tag_1 = CoRand.get_random_word_filter_sensitive(25) tag_2 = CoRand.get_random_word_filter_sensitive(25) print "首次备注:" res = self.ar_con.set_pet_tag(item_id, tag_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 "再次备注:" res = self.ar_con.set_pet_tag(item_id, tag_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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("tag"), "no tag response...") assert_that(res_data["tag"], equal_to(tag_2), "response tag mismatching...") def test_set_pet_tag_second_time_tag_null(self): """ 设置宠物备注--第一次正常备注,第二次备注tag传空\ 开发:黄良江(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) url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) item_id = res_data["item_id"] self.ar_con.capture_pet(item_id) tag_1 = CoRand.get_random_word_filter_sensitive(25) tag_2 = "" print "首次备注:" res = self.ar_con.set_pet_tag(item_id, tag_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 "再次备注:" res = self.ar_con.set_pet_tag(item_id, tag_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_pet_info(item_id, user_id) res_data = json.loads(res) assert_that(res_data, has_key("tag"), "no tag response...") assert_that(res_data["tag"], equal_to(tag_2), "response tag 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...")
class SetPetModeVerTest(unittest.TestCase): """ 设置人脸宠属性 """ def setUp(self): print 'start run setPetModelVer test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "setPetModelVer" self.pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" def tearDown(self): print 'setPetModelVer test complete.....close socket' def test_set_pet_mode_ver_success(self): """ 设置人脸宠属性成功\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") 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) ver = 123 res = self.ar_con.set_pet_mode_ver(item_id, ver) 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_set_pet_mode_ver_other_user(self): """ 设置人脸宠属性--设置其他玩家宠物\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ print "玩家A获取人脸宠:" account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") 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) print "玩家B设置玩A的人脸宠属性:" self.ar_con.connect_server() self.ar_con.login(100861, "im") res = self.ar_con.set_pet_mode_ver(item_id, 123) 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_set_pet_mode_ver_other_pet(self): """ 设置人脸宠属性--设置原生宠/灵魂宠属性\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") 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") res_data = json.loads(res) item_id = res_data["item_id"] item_type = res_data["item_type"] if item_type != 2: res = self.ar_con.set_pet_mode_ver(item_id, 123) 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_set_pet_mode_ver_cultivate(self): """ 设置人脸宠属性--设置养成宠属性\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") 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) res = self.ar_con.set_pet_mode_ver(item_id, 123) 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_set_pet_mode_ver_error_pet_id(self): """ 设置人脸宠属性失败--错误的宠物id\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") nick_name = CoRand.get_random_word_filter_sensitive(6) self.ar_con.modify_info(nick_name) pet_id = CoRand.get_rand_int(1, 1000) ver = 123 res = self.ar_con.set_pet_mode_ver(pet_id, ver) 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_set_pet_mode_ver_error_ver(self): """ 设置人脸宠属性失败--无效的版本\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") 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) ver = CoRand.get_random_word_filter_sensitive(6) res = self.ar_con.set_pet_mode_ver(item_id, ver) 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_set_pet_mode_ver_no_param(self): """ 设置人脸宠属性失败--请求未带参数\ 开发:黄良江(900000)\ 测试:王 玲(222067) """ account_id = CoRand.get_rand_int(100001) self.ar_con.login(account_id, "im") nick_name = CoRand.get_random_word_filter_sensitive(6) self.ar_con.modify_info(nick_name) 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_NOT_FOUND_PET["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NOT_FOUND_PET["err_msg"]), "response msg mismatching...")
class SetDefPetTeamTest(unittest.TestCase): def setUp(self): print 'start run SetDefPetTeam test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "setDefPetTeam" def tearDown(self): print 'SetDefPetTeam test complete.....close socket' def test_set_def_pet_team_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) pet_member = [] pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] res = self.ar_con.set_def_pet_team(pet_member, team_code) 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_def_pet_team() res_data = json.loads(res) assert_that(res_data, has_key("team_code"), "no team_code response...") assert_that(res_data, has_key("user_id"), "no user_id response...") assert_that(res_data["user_id"], equal_to(user_id), "user_id mismatching...") assert_that(res_data, has_key("pet_id1"), "no pet_id1 response...") assert_that(res_data["pet_id1"], equal_to(pet_id), "user_id mismatching...") def test_set_def_pet_team_batch(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) pet_member = [] for A in range(0, 3): pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] res = self.ar_con.set_def_pet_team(pet_member, team_code) 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_set_def_pet_team_too_much_pet(self): """ 批量设置默认的宠物队伍失败,宠物超过3个\ 开发:黄良江(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) pet_member = [] for A in range(0, 5): pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] res = self.ar_con.set_def_pet_team(pet_member, team_code) 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_set_def_pet_team_without_params(self): """ 设置默认的宠物队伍失败,未传参数\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "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_set_def_pet_team_error_pet_member(self): """ 设置默认的宠物队伍失败,错误的宠物id列表\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ self.ar_con.login(100861, "im") pet_member = [1, 2, 3] res = self.ar_con.get_def_pet_team() res_data = json.loads(res) team_code = res_data["team_code"] res = self.ar_con.set_def_pet_team(pet_member, team_code) 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_set_def_pet_team_error_team_code(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) pet_member = [] pet_url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(pet_url, "la", 1) res_data = json.loads(res) pet_id = res_data["item_id"] pet_member.append(pet_id) self.ar_con.capture_pet(pet_id) team_code = 9999 res = self.ar_con.set_def_pet_team(pet_member, team_code) 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 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...")
class TearDownPetTest(unittest.TestCase): def setUp(self): print 'start run TearDownPet test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() self.api_name = "teardownPet" def tearDown(self): print 'TearDownPet test complete.....close socket' def test_tear_down_pet_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"] url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" res = self.ar_con.scan_face(url, "la", 1) res_data = json.loads(res) pet_id = res_data["pet_id"] self.ar_con.capture_pet(pet_id) res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) theme_park_id = res_data["park_id"] res = self.ar_con.get_user_info(user_id) res_data = json.loads(res) star = res_data["star"] self.ar_con.equip_pet(theme_park_id, pet_id, 1) res = self.ar_con.tear_down_pet(theme_park_id, pet_id) res_data = json.loads(res) assert_that(res_data, has_key("star"), "no star response...") assert_that(res_data["star"], equal_to(star), "response star error...") res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) assert_that(res_data, has_key("pet_id1"), "no pet_id1 response...") assert_that(res_data["pet_id1"], equal_to(0), "response pet_id1 error...") # def test_tear_down_follow_pet(self): # """ # 卸随身宠\ # 开发:黄良江(900000)\ # 测试:林冰晶(791099) # """ # user_id = CoRand.get_rand_int(100001) # self.ar_con.login(user_id, "im") # res = self.ar_con.get_theme_park(user_id, -1) # res_data = json.loads(res) # theme_park_id = res_data["park_id"] # pet_id = res_data["follow_pet_id"] # # res = self.ar_con.tear_down_pet(theme_park_id, pet_id) # res_data = json.loads(res) # assert_that(res_data, has_key("star"), "no star response...") # assert_that(res_data["star"], equal_to(0), "response star error...") # def test_tear_down_pet_not_equip(self): # """ # 卸下未装备宠物\ # 开发:黄良江(900000)\ # 测试:林冰晶(791099) # """ # user_id = CoRand.get_rand_int(100001) # self.ar_con.login(user_id, "im") # url = "http://192.168.19.220/v0.1/static/cscommon/avatar/123456789/123456789.jpg" # res = self.ar_con.match_pet(url) # res_data = json.loads(res) # pet_id = res_data["pet_id"] # self.ar_con.capture_pet(pet_id) # res = self.ar_con.get_theme_park(user_id, -1) # res_data = json.loads(res) # theme_park_id = res_data["park_id"] # res = self.ar_con.get_user_info(user_id) # res_data = json.loads(res) # star = res_data["star"] # # res = self.ar_con.tear_down_pet(theme_park_id, pet_id) # res_data = json.loads(res) # self.ar_con.get_theme_park(user_id, -1) # 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_tear_down_pet_without_params(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"] 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_tear_down_pet_error_theme_park(self): """ 卸下宠物失败,错误的乐园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"] res = self.ar_con.get_theme_park(user_id, -1) res_data = json.loads(res) pet_id = res_data["follow_pet_id"] theme_park_id = CoRand.get_rand_int() res = self.ar_con.tear_down_pet(theme_park_id, pet_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_NO_FOUND_PLAYER_PARK["code"]), "response code mismatching...") assert_that(res_data["err_msg"], equal_to(EC_NO_FOUND_PLAYER_PARK["err_msg"]), "response msg mismatching...")
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 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 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..."