ATDDCase.py 3.22 KB
# -*- coding: utf-8 -*-


import unittest
import requests

# 多企业选择处理


class ATDDCase(unittest.TestCase):

    # 全局变量  -yq环境

    global list
    # host = "https://yq.vchangyi.com"
    #
    # uc_host = "http://restapi.99hr.com"
    # domain = 'ECF532420A6916AB184EB6409E7FE413'
    # mobile = '17321009308'
    # psw = '222222'
    # jipeihong_uid = '755DE0550A69039F0BA12102F4A4F8E1' # 季培红的UID
    # cert = ('1_vchangyi.com_bundle.crt', '2_vchangyi.com.key')
    #
    # header_json = {"Content-Type": "application/json; charset=utf-8"}
    # header_form = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}


    # 测试环境
    global list
    host = "https://yuanquan.vchangyi.com"
    uc_host = "http://t-rst.vchangyi.com"
    domain = '6F91FA1D7F00000106413BB6F47A9F54'  # 企业号“颤抖的小包包”

    mobile = '17321009308'
    psw = 'test123456'
    jipeihong_uid = '6F920BAB7F00000169D1924CB1318A56'  # 季培红的UID
    cert = ('1_vchangyi.com_bundle.crt', '2_vchangyi.com.key')

    header_json = {"Content-Type": "application/json; charset=utf-8"}
    header_form = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}


    # 全局cookie
    session = requests.Session()

    def parse_array(self, prop, value_array):
        req_params = {}
        count = 0
        tpl = "{prop}[{count}][{key}]"
        for value in value_array:
            for key, val in value.items():
                req_params[tpl.format_map({
                    "prop":prop,
                    "count":count,
                    "key":key
                })] =  val

            count += 1

        return req_params

    def tearDown(self):
        if self.session is not None:
            self.session.close()

    # 请求方法定义
    def post(self, url, data=None, **kwargs):

        assert self.session
        assert url

        return self.session.post(
            url,
            data=data,
            **kwargs
        )

    def get(self, url, **kwargs):
        assert self.session
        assert url
        return self.session.get(
            self.host + '/' + self.domain + url,
            **kwargs
        )

    def put(self, url, data=None, **kwargs):

        assert self.session
        assert url

        return self.session.put(
                self.host + '/' + self.domain + url,
                data=data, **kwargs
        )

    def delete(self, url, **kwargs):

        assert self.session
        assert url

        return self.session.delete(
                self.host + '/' + self.domain + url,
                **kwargs
        )

    def patch(self, url, data=None, **kwargs):

        assert self.session
        assert url

        return self.session.patch(
                self.host + '/' + self.domain + url,
                data=data, **kwargs
        )

    def head(self, url, **kwargs):

        assert self.session
        assert url

        return self.session.head(
                self.host + '/' + self.domain + url,
                **kwargs
        )

    def options(self, url, **kwargs):

        assert self.session
        assert url

        return self.session.options(
                self.host + '/' + self.domain + url,
                **kwargs
        )