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


import unittest
import requests

# 多企业选择处理


class ATDDCase(unittest.TestCase):

    #全局变量

    global list
    host = "https://yq.vchangyi.com"
    uc_host = "http://l-rst.vchangyi.com"
    domain = '755DD9770A69039F18591A2906A3C371' # 企业号“小仙女”


    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"}


    # 全局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
        )