def case_runner(test_case, url):
    print(url)
    for key, value in test_case['parameter'].items():
        url = url + key + '=' + value + '&'
    url = url[:-1]
    print(url)
    response = requests.get(url)
    print(response.text)
    if response.text == '':
        print('失败')
    diff = []
    try:
        response = json.loads(response.text)
        config_diff = Inspection_method().response_diff_list(
            config, response, diff)
        if config_diff == False:
            print('数据结构有误')
            print('失败')
        print(response)
        if response['extra']['scenario'] != test_case['result']['scenario']:
            print(test_case)
            print('失败')
            print('scenario错误 ' + '预期为 ' + test_case['result']['scenario'])
        if response['extra']['bucketName'] != test_case['result']['bucketName']:
            print(test_case)
            print(response)
            print('bucketName错误 ' + '预期为 ' + test_case['result']['bucketName'])
            print('失败')
        # 与content-sending之间的关联主要有两个值一个是MD5(图片id)和score,如果有MD5会判断score的值如果大于等于limitScore(默认值为0.0,或者跟着传来的值)则会返回MD5值。否则会走随机逻辑
        if response['score'] < 0:
            print('score值小于0了')
            print('失败')
        if response['limitScore'] != 0.0:
            print('limitscore不为0.0')
            print('失败')
        if 'taghit' in list(response['extra'].keys()):
            if response['extra']['taghit'] == 'hit':
                if 'rmd_hit' in list(response['extra'].keys()):
                    if response['extra']['rmd_hit'] == '0':
                        if response['md5'] != '':
                            print('命中但md5为空')
                            print('失败')

                    else:
                        if response['md5'] == '':
                            print('md5不应该有返回')
                            print('失败')
                else:
                    if response['md5'] == '':
                        print('命中但md5为空')
                        print('失败')

    except Exception as e:
        print(e)
        print('失败')
        print(url)
        print(test_case)
 def new_cdn_check(self, data, check_value, response, fail_data):
     tags_config_url = json.loads(response.text)['data']['tags_config_url']
     tags_config_url_response = requests.get(tags_config_url)
     tags_config_url_response.encoding = 'utf-8'
     json_tags_config_url_response = json.loads(
         tags_config_url_response.text)
     Im = Inspection_method().response_diff_list(
         check_value, json_tags_config_url_response, diff=[])
     if Im == False:
         fail_data.update({
             'data': data,
             'reason': 'tags_config_url文件中内容格式有误'
         })
예제 #3
0
 def asser_api(self, data, response, fail):
     Assert = self.Assert
     try:
         Assert_code = Assert['code']
     except:
         Assert_code = None
     try:
         Assert_data_format = Assert['data_format']
     except:
         Assert_data_format = None
     try:
         Assert_data_content = Assert['data_content']
     except:
         Assert_data_content = None
     try:
         Assert_data_response_header = Assert['response_header']
     except:
         Assert_data_response_header = None
     fail_data = {}
     reason = []
     if response.status_code != 200:
         reason.append('接口返回值不等于200')
     try:
         response_data = json.loads(response.text)
         if Assert_code != None:
             code = response_data[Assert['code']['key']]
             if code != int(Assert['code']['value']):
                 reason.append('接口对应code' + Assert['code']['key'] +
                               '值错误,返回内容为' + str(code))
         if Assert_data_format != None:
             case = Assert['data_format']
             if '&' in str(case.keys()):
                 for i in case.keys():
                     condition = json.loads(i)
                     if Inspection_method.response_value(list(condition.keys())[0], response_data) == \
                             list(condition.values())[0]:
                         case = case[i]
                         break
예제 #4
0
# -*- coding: utf-8 -*-
# __author__ = 'Gz'

import json

import requests
import yaml
import random
import copy

from base_function.Inspection_method import Inspection_method
# from base_function.data_sqlite import *
from base_function.kika_base_request import Kika_base_request
from base_function.golable_function import config_reader

Inspection_method = Inspection_method()


class Http_Test:
    def __init__(self, config, source='online'):
        self.config = config
        self.url = self.config['source'][source]['url']
        try:
            self.keys = self.config['source'][source]['keys']
        except:
            self.keys = None
        try:
            self.data = self.config['source'][source]['data']
            # 如果data中有为空的默认data为空
            if 'None' in str(self.data):
                self.data = None