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 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 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...")