示例#1
0
class UCFactory(object):

    def __init__(self, host):
        self.uc = UC()
        self.nd_uc_o = NdUc()
        self.rest_o = CoRestful.Restful()
        self.rand_o = CoRand()
        self.host = host

    def get_tokens(self):
        """
        获取token
        """
        username = '******'
        passwords = '123456'
        pwd_md5 = self.nd_uc_o.get_password_md5(passwords)
        response = self.uc.get_tokens(username, pwd_md5)
        return response

    def parse_tokens(self, response, http_method, request_url):
        """
        解析token
        """
        data_dec = self.rest_o.parse_response(response, 201, '解析token错误')
        mid = data_dec['access_token']
        mac_key = data_dec['mac_key']
        now = int(time.time())

        if len(str(now)) == 10:
            timestamp = str(now) + '000'
        else:
            timestamp = str(now)[0:9] + str(int(float(str(now)[9:])*1000))

        nonce = timestamp + ':' + self.rand_o.randomword(4) + str(random.randrange(1000, 9999))

        request_content = nonce + '\n' + http_method + '\n' + request_url + '\n' + self.host + '\n'
        mac = base64.b64encode(new(str(mac_key), str(request_content), digestmod=hashlib.sha256).digest())
        authorization = 'MAC id="' + str(mid) + '",nonce="' + str(nonce) + '",mac="' + str(mac) + '"'
        
        print authorization
        return str(authorization)
    
    def insert_authorization_to_header(self, http_obj, url, http_method):
        """
        在header中设置安全认证
        """
        response = self.get_tokens()
        authorization = self.parse_tokens(response, http_method, url)
        header = {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization":authorization
        }
        http_obj.set_header(header)
        return http_obj
示例#2
0
 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...")
示例#3
0
    def test_get_room_info_error_room_id(self):
        """
        获取房间信息失败,错误的room_id\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(self.account_id, "im")
        room_id = CoRand.randomword(6)
        res = self.ar_con.get_room_info(room_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...")
示例#4
0
 def test_get_soul_list_user_id_error(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)
     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, equal_to([]), "response mismatch...")
示例#5
0
 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...")
    def test_modify_info_nick_name_long(self):
        """
        修改角色信息失败,昵称超出字符限制\
        开发:黄良江(900000)\
        测试:林冰晶(791099)
        """
        self.ar_con.login(100861, "im")
        nick_name = CoRand.randomword(16)
        res = self.ar_con.modify_info(nick_name)
        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...")