Exemple #1
0
    def assert_actualTime_in_timeErrorRange(self,
                                            actual_time,
                                            offset_sec=None):
        '''
        功能:实际时间是否在当前时间允许的误差范围内
        :param actual_time: 待校验的时间,其时间格式为:%Y-%m-%d %H:%M:%S
        :param offset_sec: 时间误差偏移量
        :return:
        '''

        # 默认参数定义
        if not offset_sec:
            offset_sec = 5
        # time_format = "%Y-%m-%d %H:%M:%S"

        # 获取到实际的时间戳
        actual_timestamp = TimeHelper.get_timestamp_from_time(actual_time)

        # 获取期望的时间戳范围
        floor_expect_timestamp = actual_timestamp - offset_sec
        ceil_expect_timestamp = actual_timestamp + offset_sec

        with allure.step('[断言校验]实际时间在期望时间区间范围内,误差偏移量是 {}秒'.format(offset_sec)):
            AllureHelper.attachText("", "实际时间:{}".format(actual_time))
            AllureHelper.attachText(
                "", "期望时间区间:{}--{}".format(
                    TimeHelper.get_time_from_timestamp(floor_expect_timestamp),
                    TimeHelper.get_time_from_timestamp(ceil_expect_timestamp)))

            assert actual_timestamp >= floor_expect_timestamp and actual_timestamp <= ceil_expect_timestamp
Exemple #2
0
def get_alarmId(timestamp=None):

    if timestamp is None:
        timestamp = timestamp

    tmp_time = TimeHelper.get_time_from_timestamp(timestamp)
    timestamp = TimeHelper.get_timestamp_from_time(assigned_time=tmp_time)
    part_1 = TimeHelper.get_time_from_timestamp(timestamp=timestamp, time_format="%Y-%m-%d_%H-%M-%S")
    part_2 = StringHelper.random_digit(100,999)
    part_3 = StringHelper.random_digit(1000,9999)
    part_4 = StringHelper.random_digit(0,9)
    return "{}_{}_{}_{}".format(part_1, part_2, part_3, part_4)
Exemple #3
0
    def simulate_device_uploadPic(self, img_time=None, score=None, img_path=None, body_img_path=None, userStatus=None, capAngle=None):

        if img_time is None:
            img_time = TimeHelper.get_time(t=TimeHelper.get_time_from_timestamp(), offset=10)
        if score is None:
            score = str(random.randint(80, 190) / 100)
        if img_path is None:
            img_path = gen_bnsData.get_face_picture(index=1)
        face_frame = ImageHelper.pic_to_bytes(img_path)
        if body_img_path is None:
            body_frame = face_frame
        else:
            body_frame = ImageHelper.pic_to_bytes(body_img_path)
        if userStatus is None:
            userStatus = 2  # 默认进店
        if capAngle is None:
            capAngle = 0  # 默认正脸
        alarmId = gen_bnsData.get_alarmId(timestamp=TimeHelper.get_timestamp_from_time(assigned_time=img_time))

        pb_login_msg = pb_business.upload_v4_data(self.aes_key, img_time, face_frame, body_frame, float(score), userStatus, capAngle, alarmId)
        msg_aes_len = len(pb_login_msg)
        format = '>BIHI%ds' % (msg_aes_len)
        send_msg = struct.pack(format, int('0x1A', 16), msg_aes_len, func_num_map.DankiV4ReportData, 0, pb_login_msg)

        # 定义函数需要返回的信息
        info_dict = dict()
        info_dict.setdefault('img_time', img_time)
        info_dict.setdefault('score', score)
        info_dict.setdefault('alarmId', alarmId)
        info_dict.setdefault('userStatus', userStatus)
        info_dict.setdefault('capAngle', capAngle)
        # info_dict.setdefault('face_frame', face_frame)

        self.checkLoginInfo()

        self.send_message(send_msg)
        self.log.log_info("设备上报图片信息:{}".format(info_dict))

        self.checkReplyInfo()

        AllureHelper.attachJson(info_dict, "设备上报的信息")
        AllureHelper.attachPic(face_frame, "设备上报的图片")

        return info_dict