class GetDefPetTeamTest(unittest.TestCase): """ 查看默认的宠物队伍 """ def setUp(self): print 'start run GetDefPetTeam test ......connect server' self.ar_con = ARControl() self.ar_con.connect_server() def tearDown(self): print 'GetDefPetTeam test complete.....close socket' def test_get_def_pet_team_ok(self): """ 查看默认的宠物队伍成功\ 开发:黄良江(900000)\ 测试:林冰晶(791099) """ account_id = 100861 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.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, has_key("pet_id1"), "no pet_id1 response...") assert_that(res_data, has_key("pet_id2"), "no pet_id2 response...") assert_that(res_data, has_key("pet_id3"), "no pet_id3 response...") assert_that(res_data, has_key("pet_id4"), "no pet_id4 response...") assert_that(res_data, has_key("pet_id5"), "no pet_id5 response...") assert_that(res_data, has_key("pet_id6"), "no pet_id6 response...") assert_that(res_data, has_key("pet_id7"), "no pet_id7 response...") assert_that(res_data, has_key("pet_id8"), "no pet_id8 response...") assert_that(res_data, has_key("pet_id9"), "no pet_id9 response...") assert_that(res_data, has_key("skill_id"), "no skill_id response...")
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 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 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...")