Esempio n. 1
0
class Test_jiekou:
    def setup(self):
        self.run = Menstent()
        self.get_data = Get_data()
        self.excle = OperationExcle()

    @pytest.mark.run(order=2)
    def test_01(self, demo):
        url = "http://127.0.0.1:8000/api/departments/"
        method = 'GET'
        print("--test_01")
        print(" test---%d" % demo)
        self.run.run_man(method, url)

    @pytest.mark.skipif(condition=2 > 1, reason="跳过")
    @pytest.mark.parametrize("item", get_data())
    def test_05(self, item):
        self.run_test(url=item["url"],
                      methods=item["methods"],
                      params=item["data"],
                      expect=item["expect"],
                      i=item["i"])

    def run_test(self, url, methods, i, params=None, expect=None):
        ret = self.run.run_man(url=url, rev_method=methods, params=params)
        ret2 = str(json.loads(ret))

        if is_contents(expect, ret2):
            self.get_data.write_data(i, 'pass')
        else:
            self.get_data.write_data(i, 'fail')
        assert expect in ret2
Esempio n. 2
0
class Run_Test(object):
    def __init__(self):
        self.men = Menstent()
        self.getdata = Get_data()
        self.excle = OperationExcle()

    def go_on_run(self):
        for i in range(1, self.getdata.get_case_count()):
            methods = self.getdata.get_methods(i)
            url = self.getdata.get_case_Url(i)
            data = self.getdata.get_data(i)
            expect = self.getdata.get_expect(i)
            case_id = self.getdata.get_case_id(i)
            depend = DependdentData(case_id)

            if self.getdata.is_dependent(i):
                depend_data = depend.get_data_depend_data(i)
                depend_key = self.getdata.is_dependent(i)
                data[depend_key] = depend_data

            ret = self.men.run_man(rev_method=methods, url=url, data=data)
            if is_contents(expect, ret):
                self.getdata.write_data(i, 'pass')
            else:
                self.getdata.write_data(i, 'fail')
Esempio n. 3
0
class DependdentData(object):
    def __init__(self, case_id):
        self.case_id = case_id
        self.excle = OperationExcle()
        self.run = Menstent()
        self.data = Get_data()

    def get_case_line_data(self):
        row_date = self.excle.get_case_id_to_value(self.case_id)
        return row_date

    def run_depent(self):
        row = self.excle.get_case_id_row(self.case_id)
        url = self.data.get_case_Url(row)
        method = self.data.get_methods(row)
        req_data = self.data.get_data(row)
        headers = self.data.get_case_headers(row)
        return self.run.run_man(url, method, req_data, headers)

    def get_data_depend_data(self, row):
        depend_data = self.data.get_depend_data(row)
        res_data = self.run_depent()
        json_re = parse(depend_data)
        masle = json_re.find(res_data)
        return [math.value for math in masle][0]
Esempio n. 4
0
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
        "Accept":
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9"
    }
    r = requests.get('https://mifengcha.com/ico/honeybox', headers=headers)
    html = etree.HTML(r.content.decode("utf-8"))
    result = html.xpath('//section[@class="mgt50"]/ul/li')
    item = {}
    for i, li in enumerate(result):
        if i <= 1:
            value = li.xpath("./text()")
            name = li.xpath("./span[1]/text()")
            item[name[0].split(" :")[0].strip()] = value[0].split(
                " :")[0].strip()
        else:
            span = li.xpath("./span[1]/text()")
            span2 = li.xpath("./span[2]//text()")
            mytest = [i for i in span2 if i != ' ']
            item[span[0].split(" :")[0].strip(":")] = mytest[0].strip()
    return item


if __name__ == '__main__':
    # print(get_xapth())
    url = "http://127.0.0.1:8000/api/departments/"
    methods = "GET"
    m = Menstent()
    print(m.run_man(url=url, rev_method=methods))
    # My_test().run_test(url=url, methods=methods, expect="T05", i=4)