test_ZCBasic.py 7.33 KB
# -*- coding: utf-8 -*-

# @Time    : 2021/8/6 16:29
# @Author  : Ljq
# @File    : test_ZCBasic.py
# @Software: PyCharm

"""
整车进门基础数据获取测试
"""

import json
import unittest
from commons.scripts.readConf import rC
from commons.api import zcApi as zcA
from commons.MySession import my
from commons.api.entranceFeeBillList import entranceFeeBillList as eFBL
import time,random

class test_ZCBasic(unittest.TestCase):
    """整车-创建整车进门单基础信息接口测试"""
    def setUp(self) -> None:
        pass

    def tearDown(self) -> None:
        pass


    @classmethod
    def setUpClass(cls) -> None:
        cls.gatewayHost = rC.returnOptionsItems("host", "gatewayHost")
        cls.jmsfHost = rC.returnOptionsItems("host", "jmsfHost")

    @classmethod
    def tearDownClass(cls) -> None:
        pass

    def test_getCar(self):
        """整车-整车创建:获取车型接口调用测试"""
        # 获取车型
        carType = zcA.get_carType(host=self.gatewayHost)
        print(carType.text)
        assert carType.json()["code"] == "200"
        assert carType.json()["data"] != []

    def test_getAllCategory(self):
        """整车-整车创建:获取测试商品信息测试"""
        # 获取
        # print(my.userInfo["data"]["user"]["firmCode"])
        marketId = my.userInfo["data"]["user"]["firmId"]
        resCategory = zcA.get_listCategoryByCondition(host=self.gatewayHost,marketId=marketId,keyword="")
        print(resCategory.text)
        assert resCategory.json()["code"] == "200","全商品查询失败"
        assert resCategory.json()["data"] != [],"全商品查询失败,查询结果不应该为空"

    def test_getOneCategory(self):
        """整车-整车创建:获取测试商品信息测试"""
        # 获取
        marketId = my.userInfo["data"]["user"]["firmId"]
        resCategory = zcA.get_listCategoryByCondition(host=self.gatewayHost,marketId=marketId,keyword="火龙果")
        print(resCategory.text)
        nameList = [i["name"] for i in resCategory.json()["data"]]
        assert resCategory.json()["code"] == "200"
        for i in nameList:
            assert "火龙果" in i,"指定条件查询失败,按照名称查询出商品错误"

    def test_getAllExample(self):
        """整车-整车创建:接车员信息获取测试"""
        # print(my.userInfo["data"]["user"]["departmentId"])
        firmCode = my.userInfo["data"]["user"]["firmCode"]
        departmentId = my.userInfo["data"]["user"]["departmentId"]
        listByExample = zcA.get_listByExample(host=self.gatewayHost,firmCode=firmCode,departmentId=departmentId)
        print(listByExample.json())
        assert listByExample.json()["code"]=="200","接车员信息获取测试失败"
        assert listByExample.json()["data"]!=[],"接车员信息获取测试失败"

    def test_getOneExample(self):
        """整车-整车创建:按接车员名称信息查询接车员"""
        # print(my.userInfo["data"]["user"]["departmentId"])
        # firmCode = my.userInfo["data"]["user"]["firmCode"]
        # departmentId = my.userInfo["data"]["user"]["departmentId"]

        firmCode = my.userInfo["data"]["user"]["firmCode"]
        firmId = my.userInfo["data"]["user"]["firmId"]
        try:
            res_config = gLL.get_config(host=host, marketId=firmId)
            departmentId = [i["value"] for i in res_config.json()["rows"] if i["name"] == "DepartmentId"][0]
        except:
            departmentId = None
        keyword="哈达测试"
        listByExample = zcA.get_listByExample(host=self.gatewayHost,firmCode=firmCode,departmentId=departmentId,
                                              keyword=keyword)
        print(listByExample.json())
        assert listByExample.json()["code"]=="200","按接车员名称信息查询接车员测试失败"
        assert listByExample.json()["data"]!=[],"按接车员名称信息查询接车员测试失败"

    def test_transactionType(self):
        """整车-整车创建:交易类型获取测试"""
        transactionType = zcA.query_transactionType(host=self.gatewayHost)
        print(transactionType.json())
        assert transactionType.status_code==200,"交易类型信息获取测试失败"
        assert transactionType.json()["rows"]!=[],"交易类型信息获取测试失败"

    @unittest.skip
    def test_getGoodsTag(self):
        """整车-整车创建:货物标签获取测试"""
        goodsTag = zcA.get_goodsTag(host=self.gatewayHost)
        print(goodsTag.json())
        assert goodsTag.status_code==200,"货物标签信息获取测试失败"
        assert goodsTag.json()["data"]!=[],"货物标签信息获取测试失败"

    def test_getAllAddress(self):
        """整车-整车创建:按照省份查询产地"""
        province = "四川省"
        address = zcA.get_address(host=self.gatewayHost,province=province)
        print(address.json())
        assert address.json()["code"] == "200","按照省份查询产地信息获取测试失败"
        mergerNameList = [i["mergerName"] for i in address.json()["data"] if province not in i["mergerName"]]
        assert mergerNameList == [],"按照省份查询产地信息获取测试失败"

    def test_getOneAddress(self):
        """整车-整车创建:按照省份查询产地"""
        province = "四川省"
        city = "成都市"
        area = "锦江区"
        address = zcA.get_address(host=self.gatewayHost,province=province,city=city,area=area)
        print(address.json())
        assert address.json()["code"]=="200","详细产地信息查询失败"
        assert len(address.json()["data"])==1,"详细产地信息查询只能查询出一个结果,查询结果超过一个测试失败"
        assert address.json()["data"][0]["mergerName"] == "四川省,成都市,锦江区","根据省市区查询插地信息查询失败"

    def test_getAllDep(self):
        """整车-整车创建:接车部门信息获取"""
        depRes = zcA.get_dep(host=self.gatewayHost)
        print(depRes.json())
        assert depRes.json()["code"]=="200","接车部门信息获取测试失败"
        assert depRes.json()["data"] != [], "接车部门信息获取测试失败"


    def test_getOneDep(self):
        """整车-整车创建:查询指定接车部门信息"""
        keyword="哈达测试部"
        depRes = zcA.get_dep(host=self.gatewayHost,keyword=keyword)
        print(depRes.json())
        assert depRes.json()["code"]=="200","查询指定接车部门信息获取测试失败"
        assert len(depRes.json()["data"]) == 1, "查询指定接车部门信息获取测试失败"
        assert depRes.json()["data"][0]["name"] == keyword,"查询指定接车部门信息获取测试失败"

    def test_getProveType(self):
        """整车-整车创建:证明类型信息获取"""
        proveType = zcA.get_proveType(host=self.gatewayHost)
        print(proveType.json())
        assert proveType.json()["code"]=="200","证明类型信息获取测试失败"
        assert proveType.json()["data"] != [], "证明类型信息获取测试失败"

    def test_getDuplicateToken(self):
        """整车-整车创建:获取防重复token"""
        duplicateTokenRes = zcA.get_duplicateToken(host=self.gatewayHost)
        print(duplicateTokenRes.json())
        assert duplicateTokenRes.json()["code"]=="200","获取防重复token测试失败"
        assert duplicateTokenRes.json()["data"].isalnum(), "获取防重复token测试失败"