Exemplo n.º 1
0
 def test1_query_equip_auth(self):
     '''
     请求设备认证
     :return:
     '''
     host = self.host
     lujing = 'query_equip_auth'
     text = {
         "EquipAuthSeq": "{}".format(self.EquipAuthSeq),
         "ConnectorID": self.connID
     }
     encrypt_data = encrypt(self.DataSecret, str(text))
     data = {
         "OperatorID":
         self.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(self.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                      self.times + "0001"))
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     undata = eval(decrypt(self.DataSecret, res['Data']))
     miaoshu(url=host + lujing,
             method="post",
             data=text,
             check="{Ret and Msg}",
             respons=undata)
Exemplo n.º 2
0
 def test5_query_equip_charge_status(self):
     '''
     查询充电状态
     :return:
     '''
     host = self.host
     lujing = 'query_equip_charge_status'
     text = {"StartChargeSeq": "{}".format(self.order)}
     encrypt_data = encrypt(self.DataSecret, str(text))
     data = {
         "OperatorID":
         self.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(self.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                      self.times + "0001"))
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     miaoshu(url=host + lujing,
             method="post",
             data=text,
             check="{Ret and Msg}",
             respons=res)
     self.assertTrue(res['Ret'] == 0, msg="状态码不正确")
     self.assertTrue(res['Msg'] == "请求成功", msg="返回msg不正确")
Exemplo n.º 3
0
 def setUpClass(cls):
     host = cls.host
     lujing = 'query_token'
     text = '{"OperatorID":"MA005DBW1","OperatorSecret":"2019092301abcdef"}'
     encrypt_data = encrypt(cls.DataSecret, text)
     data = {
         "OperatorID":
         cls.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(cls.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(cls.SigSecret,
                      cls.operator_id + encrypt_data + cls.times + "0001"))
     }
     headers = cls.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     # res = requests.post(url=host + lujing, data=data, headers=header
     print(res)
     token = eval(decrypt(cls.DataSecret, res['Data']))['AccessToken']
     cls.headers['Authorization'] = 'Bearer ' + token
     return cls.headers
Exemplo n.º 4
0
    def setUpClass(cls):
        host = cls.host
        lujing = 'query_token'
        text = '{"OperatorID":"MA59CU773","OperatorSecret":"7iPn98cO06iK6oP7"}'
        encrypt_data = encrypt(cls.DataSecret, text)
        print(encrypt_data)
        data = {
            "OperatorID":
            cls.operator_id,
            "Data":
            "{}".format(encrypt_data),
            "TimeStamp":
            "{}".format(cls.times),
            "Seq":
            "0001",
            "Sig":
            "{}".format(
                hmac_md5(cls.SigSecret,
                         cls.operator_id + encrypt_data + cls.times + "0001"))
        }

        headers = cls.headers
        res = RunMethod().run_main('post', host, lujing, data, headers)

        token = eval(decrypt(cls.DataSecret, res['Data']))['AccessToken']
        cls.headers['Authorization'] = 'Bearer ' + token
        return cls.headers
Exemplo n.º 5
0
 def test4_query_notification_start_charge_result(self, text):
     '''
     推送充电结果
     :return:
     '''
     host = self.host
     lujing = 'query_notification_start_charge_result'
     # text = {"StartChargeSeq": "{}".format(self.order), "ConnectorID": "{}".format(self.connID)}
     encrypt_data = encrypt(self.DataSecret, str(text))
     data = {
         "OperatorID":
         self.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(self.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                      self.times + "0001"))
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     print(res)
     # undata = eval(decrypt(self.DataSecret, res['Data']))
     miaoshu(url=host + lujing,
             method="post",
             data=text,
             check="{Ret and Msg}",
             respons=res)
Exemplo n.º 6
0
 def test1_query_stations_info(self, text):
     '''
     查询充电站信息
     :return:
     '''
     print(self.headers)
     host = self.host
     lujing = 'query_stations_info'
     encrypt_data = encrypt(self.DataSecret, text)
     data = {
         "OperatorID":
         self.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(self.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                      self.times + "0001"))
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     miaoshu(url=host + lujing,
             method="post",
             data=text,
             check="{Ret and Msg}",
             respons=res)
Exemplo n.º 7
0
 def test3_query_station_status(self):
     '''
     设备接口状态查询
     :return:
     '''
     host = self.host
     lujing = 'query_station_status'
     text = {"StationIDs": ["{}".format(self.stationID)]}
     encrypt_data = encrypt(self.DataSecret, str(text))
     data = {
         "OperatorID":
         self.operator_id,
         "Data":
         "{}".format(encrypt_data),
         "TimeStamp":
         "{}".format(self.times),
         "Seq":
         "0001",
         "Sig":
         "{}".format(
             hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                      self.times + "0001"))
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     undata = eval(decrypt(self.DataSecret, res['Data']))
     miaoshu(url=host + lujing,
             method="post",
             data=text,
             check="{'StationIDs', 'ConnectorStatusInfos'}",
             respons=undata)
     self.assertTrue(res['Ret'] == 0, msg="状态码不正确")
     self.assertIn('StationStatusInfos', undata, msg='返回内容不正确')
Exemplo n.º 8
0
    def test8_datafield_error(self):
        '''
        检验请求的业务参数不合法(字段命名不正确)
        :return:
        '''

        host = self.host
        lujing = 'query_token'
        text = '{"OperatorID":"359705330","OperatorSecret11":"11"}'
        encrypt_data = encrypt(self.DataSecret, text)
        print(encrypt_data)
        data = {
            "OperatorID":
            "MA35PU38X",
            "Data":
            "{}".format(encrypt_data),
            "TimeStamp":
            "{}".format(self.times),
            "Seq":
            "0001",
            "Sig":
            "{}".format(
                hmac_md5(self.SigSecret,
                         "359705330" + encrypt_data + self.times + "0001"))
        }
        headers = self.headers
        res = RunMethod().run_main('post', host, lujing, data, headers)
        print("请求的业务参数:{}".format(text))
        miaoshu(url=host + lujing,
                method="post",
                data=data,
                check="{'Ret': 4004 'Msg': '请求的业务参数不合法,各接口定义自己的必须参数'}",
                respons=res)
        self.assertTrue(res['Ret'] == 4004, msg="状态码不正确")
        self.assertTrue(res['Msg'] == "请求的业务参数不合法,各接口定义自己的必须参数")
Exemplo n.º 9
0
 def test5_dataMiSS_TimeStamp(self):
     '''
     检验post参数不合法,缺少必须参数TimeStamp
     :return:
     '''
     encrypt_data = encrypt(self.DataSecret, self.text)
     sig = hmac_md5(self.SigSecret,
                    "359705330" + encrypt_data + self.times + "0001")
     host = self.host
     lujing = 'query_token'
     data = {
         "OperatorID": "359705330",
         "Data": "{}".format(encrypt_data),
         "Seq": "0001",
         "Sig": "{}".format(sig)
     }
     headers = self.headers
     res = RunMethod().run_main('post', host, lujing, data, headers)
     miaoshu(url=host + lujing,
             method="post",
             data=data,
             check="{'Ret': 4003 'Msg': 'POST参数不合法,缺少必须的示例'}",
             respons=res)
     self.assertTrue(res['Ret'] == 4003, msg="状态码不正确")
     self.assertTrue(
         res['Msg'] ==
         "POST参数不合法,缺少必须的示例:OperatorID,sig,TimeStamp,Data,Seq五个参数",
         msg="返回msg不正确")
Exemplo n.º 10
0
    def setUpClass(cls):

        cls.host = 'http://106.14.157.148:8090/evcs/v1/'
        cls.headers = {"Content-Type": "application/json; charset=utf-8"}
        cls.times = time.strftime("%Y%m%d%H%M%S", time.localtime())
        cls.DataSecret = '78BxIeGT7zQYuN12'
        cls.SigSecret = 'b8aEBQGiyFyPmjSc'
        cls.text = '{"OperatorID":"359705330","OperatorSecret":"gZjHb3GK5ye5en1v"}'
        cls.encrypt_data = encrypt(cls.DataSecret, cls.text)
        cls.sig = hmac_md5(cls.SigSecret,
                           '359705330' + cls.encrypt_data + cls.times + '0001')
        print(cls.sig)
Exemplo n.º 11
0
    def test4_query_stations_stats(self):
        '''
        查询统计信息
        :return:
        '''
        host = self.host
        lujing = 'query_station_stats'
        text = {
            "StationID": "{}".format(self.stationID),
            "StartTime": "2019-10-20",
            "EndTime": "2019-11-20"
        }

        encrypt_data = encrypt(self.DataSecret, str(text))
        data = {
            "OperatorID":
            self.operator_id,
            "Data":
            "{}".format(encrypt_data),
            "TimeStamp":
            "{}".format(self.times),
            "Seq":
            "0001",
            "Sig":
            "{}".format(
                hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                         self.times + "0001"))
        }
        headers = self.headers
        res = RunMethod().run_main('post', host, lujing, data, headers)
        # res = requests.post(url=host + lujing, json=data, headers=headers)
        undata = eval(decrypt(self.DataSecret, res['Data']))
        miaoshu(url=host + lujing,
                method="post",
                data=text,
                check="{'Ret': 0, 'Msg': '请求成功',}",
                respons=undata)
        self.assertTrue(res['Ret'] == 0, msg="状态码不正确")
        self.assertIn('StationStatsInfo', undata, msg='返回内容不正确')
Exemplo n.º 12
0
    def test2_notification_stationStatus(self):
        '''
        设备状态变化推送
        :return:
        '''
        host = self.host
        lujing = 'notification_stationStatus'
        text = {
            "ConnectorStatusInfo": [{
                "ConnectorID": "{}".format(self.connID),
                "Status": 1
            }]
        }
        encrypt_data = encrypt(self.DataSecret, str(text))
        data = {
            "OperatorID":
            self.operator_id,
            "Data":
            "{}".format(encrypt_data),
            "TimeStamp":
            "{}".format(self.times),
            "Seq":
            "0001",
            "Sig":
            "{}".format(
                hmac_md5(self.SigSecret, self.operator_id + encrypt_data +
                         self.times + "0001"))
        }
        headers = self.headers

        res = RunMethod().run_main('post', host, lujing, data, headers)
        miaoshu(url=host + lujing,
                method="post",
                data=text,
                check="{'Ret': 0, 'Msg': '请求成功',}",
                respons=res)
        self.assertTrue(res.status_code == 200, msg="状态码不正确")