MobilePost.py 1.56 KB
#!/usr/bin/python
# coding=utf-8

'''
Author: jipeigong 2017年7月19日17:53:38
'''

import json
from atdd.ATDDCase import ATDDCase

class MobilePost(ATDDCase):

    def do_login(self):

        login_url = '/Public/Api/Debug/Login/SetCookie?uid=' + self.uid + '&_identifier=studycenter'
        print("开始登录", self.host + '/' + self.domain + login_url)
        response = self.get(login_url)

        assert response.status_code == 200, "登陆请求失败" + response.text
        data = response.json()
        assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False)
        return data


    # 手机端接口模板
    def mobile_post(self, interfaceUrl, data=None, **options):
        self.interfaceUrl = interfaceUrl
        self.data = data

        url = self.host + '/' + self.domain + self.interfaceUrl
        r = self.post(url, self.data, **options)
        self.assertEquals(200, r.status_code)
        result = json.loads(r.text)
        errcode = result['errcode']
        self.assertEquals(0, errcode)
        return result

    # 手机端接口模板-异常判断
    def MobilePostAbnormal(self, interfaceUrl, data=None, code=None, **options):
        self.interfaceUrl = interfaceUrl
        self.data = data
        self.code = code

        url = self.host + '/' + self.domain + self.interfaceUrl
        r = self.post(url, self.data, **options)
        self.assertEquals(200, r.status_code)
        result = json.loads(r.text)
        errcode = result['errcode']
        self.assertEquals(code, errcode)
        return result