test_homebasic.py 6.45 KB
Newer Older
huangchengcheng committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#-*-coding:utf-8  -*-
__testauthor__ = "huangchengcheng"
__time__ = "2021/5/20 9:47"

import os
import allure
import config
import pytest
import xlrd
from common.tools import request_main
from common.utils import getExcelData


14

huangchengcheng committed
15 16 17 18
@allure.feature("首页基础功能")
class TestHomebasic:
    workbook=xlrd.open_workbook(f'{config.BaseConfig.root_path}/test_case_data/bmc/bmc_home_basic_functions_2021513.xlsx')

19 20 21 22 23 24
    def setup_class(self):
        config.BMCConfig.headers["Pvt-Token"] = getattr(config.BMCConfig, "bmc_pvt_token")
        config.BMCConfig.headers["Token"] = getattr(config.BMCConfig, "bmc_token")
        self.headers = config.BMCConfig.headers


huangchengcheng committed
25 26 27 28 29 30 31 32 33 34
    @allure.story("获取开通城市列表")
    @allure.link("")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","SwitchList"))
    def test_switchList(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        data=indata["reqData"]
        expectdata=indata["expectData"]
huangchengcheng committed
35
        self.res=request_main(url,self.headers,method,data)
huangchengcheng committed
36
        try:
huangchengcheng committed
37 38
            assert self.res["code"]==expectdata["code"]
            assert self.res["success"]==expectdata["success"]
huangchengcheng committed
39 40 41 42 43 44 45 46 47 48 49 50 51
        except Exception as e:
            raise e


    @allure.story("城市切换保存")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Switchchange"))
    def test_switchchang(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        data=indata["reqData"]
        expectdata=indata["expectData"]
huangchengcheng committed
52
        self.res=request_main(url=url,data=data,method=method,headers=self.headers)
huangchengcheng committed
53
        try:
huangchengcheng committed
54
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
55 56 57 58 59 60 61 62 63 64 65 66 67
        except Exception as e:
            raise e


    @allure.story("获取资讯分类")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Newsclassify"))
    def test_Newsclassify(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        data=indata["reqData"]
        expectdata=indata["expectData"]
huangchengcheng committed
68
        self.res=request_main(url=url,data=data,method=method,headers=self.headers)
huangchengcheng committed
69
        try:
huangchengcheng committed
70
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
71 72 73 74 75 76 77 78 79 80 81 82
        except Exception as e:
            raise e

    @allure.story("文章banner列表")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Newsgetbanner"))
    def test_newsgetbanner(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        expectdata=indata["expectData"]
        data=indata["reqData"]
huangchengcheng committed
83
        self.res=request_main(url=url,method=method,data=data,headers=self.headers)
huangchengcheng committed
84
        try:
huangchengcheng committed
85
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
86 87 88 89 90 91 92 93 94 95 96 97 98
        except Exception as e:
            raise e


    @allure.story("获取资讯列表")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Newsgetlist"))
    def test_newsgetlist(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        expectdata=indata["expectData"]
        data=indata["reqData"]
huangchengcheng committed
99
        self.res=request_main(url=url,method=method,data=data,headers=self.headers)
huangchengcheng committed
100
        try:
huangchengcheng committed
101
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
102 103 104
        except Exception as e:
            raise e

105 106 107 108 109 110 111 112 113
    @pytest.fixture(scope='function')
    def newsgetlist(self):
        url = f'{config.BMCConfig.host}/news/categoryItems'
        method = "get"
        data = {"categoryId":"1","page":"1","size":"20"}
        res=request_main(url,self.headers,method,data,)
        return res


huangchengcheng committed
114 115 116 117 118

    @allure.story("获得文章详情")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Newsdetail"))
119
    def test_newsdetail(self,indata,newsgetlist):
huangchengcheng committed
120 121 122
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        expectdata=indata["expectData"]
123 124 125 126 127 128 129 130 131 132 133 134
        try:
            newlist=newsgetlist["data"]["list"]
            if newlist==[]:
                pytest.skip("没有文章,无法获取文章详情")
            else:
                if len(indata["reqData"]["id"])==0:
                    data = indata["reqData"]
                else:
                    indata["reqData"]["id"]=newlist[0]["id"]
                    data=indata["reqData"]
        except Exception as e:
            raise e
huangchengcheng committed
135
        self.res=request_main(url=url,method=method,data=data,headers=self.headers)
huangchengcheng committed
136
        try:
huangchengcheng committed
137
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
138 139 140
        except Exception as e:
            raise e

141 142


huangchengcheng committed
143 144 145 146 147 148 149 150 151
    @allure.story("资讯列表搜索")
    @allure.description("creator:liaohui,autoCreator:huangchengcheng")
    @allure.title("{indata[testPoint]}")
    @pytest.mark.parametrize("indata",getExcelData.get_excelData(workbook,"首页基础功能","Newssearch"))
    def test_newssearch(self,indata):
        url=f'{config.BMCConfig.host}/{indata["url"]}'
        method=indata["method"]
        expectdata=indata["expectData"]
        data=indata["reqData"]
huangchengcheng committed
152
        self.res=request_main(url=url,method=method,data=data,headers=self.headers)
huangchengcheng committed
153
        try:
huangchengcheng committed
154
            assert self.res["code"]==expectdata["code"]
huangchengcheng committed
155 156 157
        except Exception as e:
            raise e

huangchengcheng committed
158 159 160
    def teardown(self):
        allure.attach(f'{self.res}','相应结果',allure.attachment_type.TEXT)

huangchengcheng committed
161 162 163 164 165

# if __name__ == '__main__':
#
#     # 生成报告数据
#     pytest.main(['-v', '-s', "test_homebasic.py", '--alluredir', './bmc/report',"--clean-alluredir"])
166
#     # pytest.main(['-v', '-s', "test_homebasic.py::TestHomebasic::test_newsdetail", '--alluredir', './bmc/report', "--clean-alluredir"])
huangchengcheng committed
167 168
#     # 打开报告
#     os.system('allure serve ./bmc/report')