예제 #1
0
class shown_case:
    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual()
        self.sql = """update shown_case set args=%s,response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t = tool()
        self.login_param, self.deviceid = runconfig.RunConfig().get_login(
            islocal)

        self.login_param2 = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, self.login_param)
        self.ecode = errorCodeConst()

    # 取数据库中args
    @staticmethod
    def select_args(cursor, case_no):
        _get_arg = 'select args from shown_case where case_no = %s'
        cursor.execute(_get_arg, case_no)
        arg = cursor.fetchone()
        if arg[0] == '':
            return {}
        return eval(arg[0])

    def test_recomend_unlogin(self):
        kw = {}

        header = self.api.get_header()

        # cur = self.casedb.connect_casedb()
        response = self.api.shown_page('recommend', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        try:
            assert self.ecode.ACCESS_TOKEN_LOST == response.json()['errorCode']
        except AssertionError:
            print json.dumps(response.json(), ensure_ascii=False)

        # self.casedb.closeDB(cur)

    def test_01_recommend(self):
        case_no = 1

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "page": [
                    {
                        "type":
                        "banner",
                        "data": [{
                            "type": "xxx",
                            "image": "",
                            "url": "",
                            "bannerId": 0,
                            "name": "",
                            "createTime": "",
                            "updateTime": ""
                        }]
                    },
                    {
                        "type":
                        "opus",
                        "data": [{
                            "author": {
                                "userId": 0,
                                "userName": "",
                                "avatar": ""
                            },
                            "type": "song",
                            "creativeType": "",
                            "songId": 0,
                            "songName": "",
                            "description": "",
                            "image": "",
                            "songUrl": "",
                            "songDuration": 0,
                            "listenCount": 0,
                            "collectCount": 0,
                            "commentCount": 0,
                            "shareCount": 0,
                            "likeCount": 0,
                            "createTime": "",
                            "recommendTime": "",
                            "recommendTags": [""],
                            "tags": [""],
                            "genre": ""  # 作品流派
                        }],
                        next:
                        ""
                    }
                ]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_02_recommend_page(self):
        case_no = 2

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, args)

        self.casedb.closeDB(cur)

    def test_03_recommend_no_next(self):
        case_no = 3

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_4_search_user(self):
        case_no = 4

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('user', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_5_search_user_partial(self):
        case_no = 5

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('user', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_6_search_opus(self):
        case_no = 6

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('opus', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_7_hot_search_opus_english(self):
        case_no = 7

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('opus', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_8_hot_page(self):
        case_no = 8
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "page": [{
                    "type":
                    "opus",
                    "data": [{
                        "author": {
                            "userId": 0,
                            "userName": "",
                            "avatar": ""
                        },
                        "type":
                        "song",
                        "creativeType":
                        "",
                        "songId":
                        0,
                        "songName":
                        "",
                        "description":
                        "",
                        "image":
                        "",
                        "songUrl":
                        "",
                        "songDuration":
                        0,
                        "listenCount":
                        0,
                        "collectCount":
                        0,
                        "commentCount":
                        0,
                        "shareCount":
                        0,
                        "likeCount":
                        0,
                        "createTime":
                        "",
                        "recommendTime":
                        "",
                        "recommendTags": [""],
                        "tags": [""],
                        "genre":
                        "",
                        "comment": [{
                            "commentText": "",
                            "commentTime": "",
                            "author": {
                                "userId": 0,
                                "userName": "",
                                "avatar": ""
                            },
                            "likeCount": 0
                        }]
                    }]
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('hot', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_9_hot_page(self):
        case_no = 9

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('hot', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_10_hot_page(self):
        case_no = 10

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('hot', header, kw)
        if response.status_code == 200:
            print u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_11_hot_page(self):
        case_no = 11

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('hot', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_12_hot_page(self):
        case_no = 12

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('hot', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_13_newest(self):
        case_no = 13
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "page": [{
                    "type":
                    "opus",
                    "data": [{
                        "author": {
                            "userId": 0,
                            "userName": "",
                            "avatar": ""
                        },
                        "type":
                        "song",
                        "creativeType":
                        "",
                        "songId":
                        0,
                        "songName":
                        "",
                        "description":
                        "",
                        "image":
                        "",
                        "songUrl":
                        "",
                        "songDuration":
                        0,
                        "listenCount":
                        0,
                        "collectCount":
                        0,
                        "commentCount":
                        0,
                        "shareCount":
                        0,
                        "likeCount":
                        0,
                        "createTime":
                        "",
                        "recommendTime":
                        "",
                        "recommendTags": [""],
                        "tags": [""],
                        "genre":
                        "",
                        "comment": [{
                            "commentText": "",
                            "commentTime": "",
                            "author": {
                                "userId": 0,
                                "userName": "",
                                "avatar": ""
                            },
                            "likeCount": 0
                        }]
                    }]
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('newest', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_14_newest(self):
        case_no = 14

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('newest', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_15_newest(self):
        case_no = 15

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('newest', header, kw)
        # assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_16_newest(self):
        case_no = 16

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('newest', header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_17_newest(self):
        case_no = 17

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('newest', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_18_rank(self):
        case_no = 18
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "page": [{
                    "type":
                    "rankingDay",
                    "data": [{
                        "author": {
                            "userId": 0,
                            "userName": "",
                            "avatar": ""
                        },
                        "type": "song",
                        "creativeType": "",
                        "songId": 0,
                        "songName": "",
                        "description": "",
                        "image": "",
                        "songUrl": "",
                        "songDuration": 0,
                        "listenCount": 0,
                        "collectCount": 0,
                        "commentCount": 0,
                        "shareCount": 0,
                        "likeCount": 0,
                        "createTime": "",
                        "recommendTime": "",
                        "recommendTags": [""],
                        "tags": [""],
                        "genre": "",
                        "ranking": 0
                    }]
                }, {
                    "type":
                    "rankingWeek",
                    "data": [{
                        "author": {
                            "userId": 0,
                            "userName": "",
                            "avatar": ""
                        },
                        "type": "song",
                        "creativeType": "",
                        "songId": 0,
                        "songName": "",
                        "description": "",
                        "image": "",
                        "songUrl": "",
                        "songDuration": 0,
                        "listenCount": 0,
                        "collectCount": 0,
                        "commentCount": 0,
                        "shareCount": 0,
                        "likeCount": 0,
                        "createTime": "",
                        "recommendTime": "",
                        "recommendTags": [""],
                        "tags": [""],
                        "genre": "",
                        "ranking": 0
                    }]
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('ranking', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_19_rank(self):
        case_no = 19

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('ranking', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_20_rank(self):
        case_no = 20

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('ranking', header, kw)
        if response.status_code == 200:
            print u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_21_rank(self):
        case_no = 21

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('ranking', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_22_rank(self):
        case_no = 22

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('ranking', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_23_scout(self):
        case_no = 23
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "user": [{
                    "userId": 0,
                    "userName": "",
                    "avatar": "",
                    "ranking": 0,
                    "score": 0,
                    "gradeText": "",
                    "followerCount": 0,
                    "opusCount": "",
                    "scoutCount": 0,
                    "isFollowed": 0
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('scout', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_24_musician(self):
        case_no = 24

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_25_musician(self):
        case_no = 25

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_26_musician(self):
        case_no = 26

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_27_musician(self):
        case_no = 27

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_28_musician(self):
        case_no = 28

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_29_musician(self):
        case_no = 29

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_30_musician(self):
        case_no = 30

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_31_musician(self):
        case_no = 31

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_32_musician(self):
        case_no = 32

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.shown_page('musician', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    '''def test_12_scout(self):
        case_no = 12
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "user": [
                    {
                        "userId": 0,
                        "userName": "",
                        "avatar": "",
                        "ranking": 0,
                        "score": 0,
                        "followerCount": 0,
                        "opusCount": "",
                        "scoutCount": 0,
                        "isFollowed": 0
                    }
                ]
            }
        }

        kw = {}
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.shown_page('scout', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_NULL, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)'''

    def test_33_voilate(self):
        case_no = 33
        r_list = []
        e_list = []
        expect_data = {"data": {"sequence": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        # kw = self.select_args(cur, case_no)
        kw = {
            "text": "举报",
            "violateType": "r",
            "target": {
                "id": 6315799816953660810,
                "type": "user"
            },
            "contact": ""
        }
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_34_voilate_type_wrong(self):
        case_no = 34

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARG_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_35_voilate_text_null(self):
        case_no = 35

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARG_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_36_voilate_id_wrong(self):
        case_no = 36
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.RECORD_UNEXIST, kw)

        self.casedb.closeDB(cur)

    def test_37_voilate_violateType_null(self):
        case_no = 37

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARG_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_38_feedback(self):
        case_no = 38
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(1, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_39_feedback_contact(self):
        case_no = 39

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(1, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_40_feedback_content_null(self):
        case_no = 40
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(1, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARG_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_41_search_user(self):
        case_no = 41

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "user": [{
                    "userId": 0,
                    "userName": "",
                    "avatar": "",
                    "level": "",
                    "opusCount": 0
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('user', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_43_opus_detail_comment(self):
        case_no = 43

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        print kw
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_44_opus_detail_comment(self):
        case_no = 44

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_45_opus_detail_comment(self):
        case_no = 45

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_46_opus_detail_comment(self):
        case_no = 46

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_47_opus_detail_comment(self):
        case_no = 47

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

        remote_cur = self.casedb.connect_remotedb()
        sql = """SELECT count(*) FROM opus_comment WHERE opus_id=%s AND id = opus_comment_id"""
        remote_cur.execute(sql, kw['opusid'])
        comments_tuple = remote_cur.fetchone()

    def test_48_opus_detail_comment(self):
        case_no = 48

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_49_opus_detail_comment(self):
        case_no = 49

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.UNKNOWN_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_50_opus_detail_comment(self):
        case_no = 50

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_51_opus_detail_comment(self):
        case_no = 51

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        # assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_52_voilate_song(self):
        case_no = 52
        r_list = []
        e_list = []
        expect_data = {"data": {"sequence": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_53_voilate_comment(self):
        case_no = 53
        r_list = []
        e_list = []
        expect_data = {"data": {"sequence": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.violate_feedback(0, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_55_hot_word(self):
        case_no = 55

        r_list = []
        e_list = []
        expect_data = {"data": {"keyword": [{"text": ""}]}}
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('hot', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_42_opus_detail_comment(self):
        case_no = 42

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "comment": [{
                    "commentId":
                    0,
                    "createTime":
                    "",
                    "likeCount":
                    0,
                    "replyCount":
                    0,
                    "author": {
                        "userId": 0,
                        "userName": "",
                        "avatar": ""
                    },
                    "content":
                    "",
                    "status":
                    0,
                    "isLiked":
                    0,  # 是否已点赞,
                    "reply": [{
                        "commentId": 0,
                        "createTime": "",
                        "likeCount": 0,
                        "author": {
                            "userId": 0,
                            "userName": "",
                            "avatar": ""
                        },
                        "content": "",
                        "status": 0,
                        "isLiked": 0,
                        "replyTo": {
                            "author": {
                                "userId": 0,
                                "userName": "",
                                "avatar": ""
                            },
                            "commentId": 0,
                            "commentTime": "",
                            "content": "",
                            "likeCount": 0,
                            "status": 0
                        }
                    }]
                }]
            }
        }
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.get_song_detail(1, header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_57_hot_search_opus_english_partial(self):
        case_no = 57

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('opus', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_56_search_user_english_partial(self):
        case_no = 56

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.search('user', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_58_recommend_page(self):
        """page=2,不带"next"必填项"""
        case_no = 58

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_NULL, args)

        self.casedb.closeDB(cur)

    def test_59_recommend_page(self):
        """page=2,带上next但不传值,应该传值为空的错"""

        # print type(sys._getframe().f_code.co_name)
        case_no = 59
        header = self.t.get_header
        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_NULL, args)

        self.casedb.closeDB(cur)

    def test_60_recommend_page(self):
        """page=2,带上next,但传值不是返回的next字段值,报传值错误"""
        case_no = 60

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, args)

        self.casedb.closeDB(cur)

    def test_61_recommend_page(self):
        """page=2,next=:next"""
        case_no = 61

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.shown_page('recommend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)
예제 #2
0
class other_Case:

    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual()
        self.sql = """update other_case set args=%s,response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t = tool()
        self.login_param, self.deviceid = runconfig.RunConfig().get_login(islocal)

        self.login_param2 = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, self.login_param)
        self.ecode = errorCodeConst()

    # 取数据库中args
    @staticmethod
    def select_args(cursor, case_no):
        _get_arg = 'select args from other_case where case_no = %s'
        cursor.execute(_get_arg, case_no)
        arg = cursor.fetchone()
        if arg[0] == '':
            return {}
        return eval(arg[0])

    def test_recomend_unlogin(self):
        kw = {}

        header = self.api.get_header()

        # cur = self.casedb.connect_casedb()
        response = self.api.shown_page('recommend', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        try:
            assert self.ecode.ACCESS_TOKEN_LOST == response.json()['errorCode']
        except AssertionError:
            print json.dumps(response.json(), ensure_ascii=False)

        # self.casedb.closeDB(cur)

    def test_01_ranking_friend(self):
        case_no = 1

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "friend": [
                    {
                        "userId": 0,
                        "userName": "",
                        "level": "",
                        "ranking": 0,
                        "avatar": ""
                    }
                ]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_02_ranking_friend(self):
        case_no = 2

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_03_ranking_friend(self):
        case_no = 3

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_NULL, args)

        self.casedb.closeDB(cur)

    def test_04_ranking_friend(self):
        case_no = 4

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.UNKNOWN_ERROR, args)

        self.casedb.closeDB(cur)

    def test_05_ranking_friend(self):
        case_no = 5

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_06_ranking_friend(self):
        case_no = 6

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_07_ranking_friend(self):
        case_no = 7

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        if response.status_code == 500:
            print u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, args)

        self.casedb.closeDB(cur)

    def test_08_ranking_friend(self):
        case_no = 8

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('friend', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, args)

        self.casedb.closeDB(cur)

    def test_09_ranking_fans(self):
        case_no = 9

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "friend": [
                    {
                        "userId": 0,
                        "userName": "",
                        "level": "",
                        "ranking": 0,
                        "avatar": ""
                    }
                ]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_10_ranking_fans(self):
        case_no = 10

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_11_ranking_fans(self):
        case_no = 11

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_NULL, args)

        self.casedb.closeDB(cur)

    def test_12_ranking_fans(self):
        case_no = 12

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.UNKNOWN_ERROR, args)

        self.casedb.closeDB(cur)

    def test_13_ranking_fans(self):
        case_no = 13

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_14_ranking_fans(self):
        case_no = 14

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, args)

        self.casedb.closeDB(cur)

    def test_15_ranking_fans(self):
        case_no = 15

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, args)

        self.casedb.closeDB(cur)

    def test_16_ranking_fans(self):
        case_no = 16

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        args = self.select_args(cur, case_no)
        response = self.api.ranking_friend_fans('fans', header, args)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, args)

        self.casedb.closeDB(cur)

    def test_17_scout_list(self):
        case_no = 17

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "user": [
                    {
                        "userId": 0,
                        "userName": "",
                        "avatar": ""
                    }
                ]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_18_scout_list(self):
        case_no = 18

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_19_scout_list(self):
        case_no = 19

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_NULL, kw)

        self.casedb.closeDB(cur)

    def test_20_scout_list(self):
        case_no = 20

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        if response.status_code == 500:
            print u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_TYPE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_21_scout_list(self):
        case_no = 21

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_22_scout_list(self):
        case_no = 22

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_23_scout_list(self):
        case_no = 23

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_24_scout_list(self):
        case_no = 24

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.scout_list(header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_25_cancel_join_medley(self):
        case_no = 25

        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "deleteTime": "",
                "currParticipantCount": 0,
                "maxParticipantCount": 0
            }
        }
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_medley('delete', header, kwargs=kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_26_cancel_join_medley(self):
        case_no = 26

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_medley('delete', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.AUTH_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_27_cancel_join_medley(self):
        case_no = 27

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_medley('delete', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, self.ecode.AUTH_ERROR, kw)

        self.casedb.closeDB(cur)
예제 #3
0
class user_case:
    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual(islocal)
        self.sql = """update user_case set args=%s, response= %s,result= %s,test_time= %s WHERE case_no = %s"""
        self.t = tool()
        # self.deviceid = "c37c6b3c-10cc-411d-abfe-200135522e6d"
        self.login_param, self.deviceid = runconfig.RunConfig().get_login(
            islocal)
        self.t.get_login_header(self.api, self.deviceid, self.login_param)
        self.ecode = errorCodeConst()

    def test_01_user_info(self):  # 获取用户信息
        case_no = 1
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        uid = self.t.get_login_id
        response = self.api.get_user_info(uid, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)
        self.casedb.closeDB(cur)

    def test_28_user_info_unlogin(self):
        case_no = 28
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        response = self.api.get_user_info('6301346050607153160', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST)
        self.casedb.closeDB(cur)

    def test_02_my_info(self):  # 获取用户信息
        case_no = 2
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        response = self.api.get_my_info(header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        self.casedb.closeDB(cur)

    def test_03_my_info_unlogin(self):  # 获取用户信息
        case_no = 3
        cur = self.casedb.connect_casedb()

        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        response = self.api.get_my_info(header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100201)
        self.casedb.closeDB(cur)

    def test_04_modify_my_info(self):
        case_no = 4
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        param = {
            "userName": "******",
            "avatar": "",
            "email": "*****@*****.**",
            "sex": 1,
            "birthday": "1990-09-16",
            "emotionStatus": 2,
            "personalProfile": "",
            "backgroundImageUrl": "http://www.baidu.com"
        }
        response = self.api.modify_my_info(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_05_modify_setting(self):
        case_no = 5
        cur = self.casedb.connect_casedb()

        header = self.t.get_header

        param = {"commentBoardPrivacySettings": 1, "pushLikeNoticeSettings": 1}

        response = self.api.op_settings('patch', header, params=param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_06_modify_setting_wrong_value(self):  # 获取用户信息
        case_no = 6
        cur = self.casedb.connect_casedb()

        header = self.t.get_header

        param = {
            "commentBoardPrivacySettings": 2,
            "pushSystemNoticeSettings": 0
        }
        response = self.api.op_settings('patch', header, params=param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103, param)
        self.casedb.closeDB(cur)

    '''def test_07_modify_setting_NaN(self):    #
        case_no = 7
        cur = self.casedb.connect_casedb()

        header = self.t.get_header

        param = {"commentBoardPrivacySettings": "a"}
        response = self.api.op_settings('patch', header, params=param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        self.casedb.closeDB(cur)'''

    def test_08_get_setting(self):  # 获取用户信息
        case_no = 8
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        response = self.api.op_settings('get', header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)
        self.casedb.closeDB(cur)

    def test_09_focus(self):  # 关注用户
        case_no = 9
        cur = self.casedb.connect_casedb()
        uid = '6311841386878468166'

        header = self.t.get_header

        response = self.api.op_focus('put', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, uid)
        self.casedb.closeDB(cur)

    def test_10_focus_list(self):  # 关注用户列表
        case_no = 10
        cur = self.casedb.connect_casedb()
        uid = '6302709656942805004'

        header = self.t.get_header

        response = self.api.op_focus('get', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, uid)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_11_focus_again(self):
        """
        重复关注用户
        :return:
        """
        case_no = 11
        cur = self.casedb.connect_casedb()
        uid = '6302709656942805004'

        header = self.t.get_header

        response = self.api.op_focus('put', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        self.casedb.closeDB(cur)

    def test_12_fans_list(self):  # 粉丝列表
        case_no = 12
        cur = self.casedb.connect_casedb()
        uid = self.t.get_login_id

        header = self.t.get_header

        response = self.api.get_fans_list(uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        self.casedb.closeDB(cur)

    def test_13_unfocus(self):  # 取消关注
        case_no = 13
        cur = self.casedb.connect_casedb()
        uid = '6302709656942805004'

        header = self.t.get_header

        response = self.api.op_focus('delete', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        self.casedb.closeDB(cur)

    def test_14_unfocus_unknown(self):
        """
        取消关注未关注用户
        :return:
        """
        case_no = 14
        cur = self.casedb.connect_casedb()
        uid = '6301346047952158727'

        header = self.t.get_header

        response = self.api.op_focus('delete', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_15_blacklist(self):
        case_no = 15
        cur = self.casedb.connect_casedb()
        uid = '6298101404421974110'

        header = self.t.get_header

        response = self.api.op_blacklist('put', header, uid)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, uid)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_16_blacklist_again(self):
        case_no = 16
        cur = self.casedb.connect_casedb()
        uid = '6298101404421974110'

        header = self.t.get_header

        response = self.api.op_blacklist('put', header, uid)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ALREADY_IN_BLACKLIST, uid)
        self.casedb.closeDB(cur)

    def test_17_blacklist_list(self):
        case_no = 17
        cur = self.casedb.connect_casedb()
        # uid = '6301346050607153160'

        header = self.t.get_header

        response = self.api.op_blacklist('get', header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_18_unblacklist(self):
        """
        取消加黑
        :return:
        """
        case_no = 18
        cur = self.casedb.connect_casedb()
        uid = '6298101404421974110'

        header = self.t.get_header

        response = self.api.op_blacklist('delete', header, uid)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_19_banding_phone(self):
        case_no = 19
        cur = self.casedb.connect_casedb()
        third_param = {
            "thirdAuthToken": "weixintoken3",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        header = self.t.get_login_header(self.api, self.deviceid, third_param)

        response = self.api.bind_phone_sms({"phoneNumber": "13036582900"},
                                           header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 0,
                            {"phoneNumber": "13036582900"})
        self.casedb.closeDB(cur)

    def test_20_already_banding_phone(self):
        case_no = 20
        cur = self.casedb.connect_casedb()
        third_param = {
            "thirdAuthToken": "weixintoken3",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        header = self.t.get_login_header(self.api, self.deviceid, third_param)

        response = self.api.bind_phone_sms({"phoneNumber": "18782943850"},
                                           header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100401,
                            third_param)
        self.casedb.closeDB(cur)

    def test_27_banding_weibo_again(self):
        """
        18782943857再次绑定微博平台的另一账号
        :return:
        """
        case_no = 27
        cur = self.casedb.connect_casedb()
        phone_param = {
            'phoneNumber': "18782943857",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        header = self.t.get_login_header(self.api, self.deviceid, phone_param)

        param = {
            "thirdAuthToken": "banding27",
            "thirdAccountName": "machineid wrong",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weibo",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }

        response = self.api.bind_third('weibo', param, header)
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100407, param)
        self.casedb.closeDB(cur)

    def test_29_modify_my_info(self):
        case_no = 29
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        param = {"userName": "******"}
        response = self.api.modify_my_info(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_34_blacklist_unexist(self):
        """
        加黑不存在的用户
        :return:
        """
        case_no = 34
        cur = self.casedb.connect_casedb()
        uid = '6301346050607153161'

        header = self.t.get_header

        response = self.api.op_blacklist('put', header, uid)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100408, uid)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_21_banding_phone_wrong_format(self):
        case_no = 21
        cur = self.casedb.connect_casedb()
        third_param = {
            "thirdAuthToken": "weixintoken3",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        header = self.t.get_login_header(self.api, self.deviceid, third_param)

        response = self.api.bind_phone_sms({"phoneNumber": "1303658oe90"},
                                           header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            third_param)
        self.casedb.closeDB(cur)

    def test_22_banding_phone_longer(self):
        case_no = 22
        cur = self.casedb.connect_casedb()
        third_param = {
            "thirdAuthToken": "weixintoken3",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        header = self.t.get_login_header(self.api, self.deviceid, third_param)

        response = self.api.bind_phone_sms({"phoneNumber": "1303658291011"},
                                           header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            third_param)
        self.casedb.closeDB(cur)

    def test_23_banding_phone(self, phoneNumber):
        case_no = 23
        cur = self.casedb.connect_casedb()
        # 第三方登陆账号
        third_param = {
            "thirdAuthToken": "weixintoken",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "machineId": 100001
        }

        self.t.get_login_header(self.api, self.deviceid, third_param)
        header = self.t.get_header

        re = self.api.bind_phone_sms({"phoneNumber": phoneNumber},
                                     header=header)
        assert re.status_code == 200, u"http响应错误,错误码 %s" % re.status_code
        data = re.json()

        param = {
            "phoneNumber": phoneNumber,
            "password": base64.b64encode("888888"),
            "platform": "iOS",
            "clientVersion": "2.0",
            "bindingPhoneNumberSmsCode": "0000",
            "bindingPhoneNumberSmsId": data['data']['bindingPhoneNumberSmsId']
        }

        response = self.api.bind_phone(param, header)
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_24_banding_phone_again(self, phoneNumber):
        case_no = 24
        cur = self.casedb.connect_casedb()
        third_param = {
            "thirdAuthToken": "weixintoken",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, third_param)
        header = self.t.get_header

        re = self.api.bind_phone_sms({"phoneNumber": phoneNumber},
                                     header=header)
        assert re.status_code == 200, u"http响应错误,错误码 %s" % re.status_code
        data = re.json()

        param = {
            "phoneNumber": phoneNumber,
            "password": base64.b64encode("888888"),
            "platform": "iOS",
            "clientVersion": "2.0",
            "bindingPhoneNumberSmsCode": "0000",
            "bindingPhoneNumberSmsId": data['data']['bindingPhoneNumberSmsId']
        }

        response = self.api.bind_phone(param, header)
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100406, param)
        self.casedb.closeDB(cur)

    def test_25_banding_weibo(self):
        case_no = 25
        cur = self.casedb.connect_casedb()
        phone_param = {
            'phoneNumber': "13000000000",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, phone_param)
        header = self.t.get_header

        param = {
            "thirdAuthToken": "banding3858",
            "thirdAccountName": "weibo3858",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weibo",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.bind_third('weibo', param, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_26_banding_qq_again(self):
        """
        18782943857再次绑定qq
        :return:
        """
        case_no = 26
        cur = self.casedb.connect_casedb()
        phone_param = {
            'phoneNumber': "13000000000",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, phone_param)
        header = self.t.get_header

        param = {
            "thirdAuthToken": "weibotoken4",
            "thirdAccountName": "weibo4",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "qq",
            "clientVersion": "2.0",
            "machineId": 100001
        }

        response = self.api.bind_third('qq', param, header)
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100401, param)
        self.casedb.closeDB(cur)

    def test_30_modify_sex_2(self):
        case_no = 30
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        param = {"sex": 3}
        response = self.api.modify_my_info(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103, param)
        self.casedb.closeDB(cur)

    def test_31_modify_settings_unlogin(self):
        case_no = 31
        cur = self.casedb.connect_casedb()

        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {"commentBoardPrivacySettings": 1, "pushLikeNoticeSettings": 1}
        response = self.api.op_settings('patch', header, params=param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100201, param)
        self.casedb.closeDB(cur)

    def test_32_focus_self(self):
        """
        关注自己
        :return:
        """
        case_no = 32
        cur = self.casedb.connect_casedb()

        header = self.t.get_header

        response = self.api.op_focus('put',
                                     '6299163298503852033',
                                     header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 200604)
        self.casedb.closeDB(cur)

    def test_33_focus_list_unlogin(self):  # 关注用户列表
        case_no = 33
        cur = self.casedb.connect_casedb()
        uid = '6302709656942805004'

        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")

        response = self.api.op_focus('get', uid, header=header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100201)
        self.casedb.closeDB(cur)

    def test_35_blacklist_self(self):
        case_no = 35
        cur = self.casedb.connect_casedb()
        uid = self.t.get_login_id

        header = self.t.get_header

        response = self.api.op_blacklist('put', header, uid)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 200605, uid)
        # cur.close()
        self.casedb.closeDB(cur)

    def test_binding_list(self):
        third_param = {
            "thirdAuthToken": "weibotoken4",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, third_param)
        header = self.t.get_header
        r = self.api.bind_list(header)
        print r.json()

    def test_delete_binding(self):
        third_param = {
            "thirdAuthToken": "weibotoken4",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, third_param)
        header = self.t.get_header
        r = self.api.delete_bind('qq', header)
        print r.text.decode('utf-8')
예제 #4
0
class notice_case:
    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual()
        self.sql = """update notice_case set args=%s,response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t = tool()
        self.login_param, self.deviceid = runconfig.RunConfig().get_login(
            islocal)

        self.login_param2 = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        self.t.get_login_header(self.api, self.deviceid, self.login_param)
        self.ecode = errorCodeConst()

    # 取数据库中args
    @staticmethod
    def select_args(cursor, case_no):
        _get_arg = 'select args from notice_case where case_no = %s'
        cursor.execute(_get_arg, case_no)
        arg = cursor.fetchone()
        if arg[0] == '':
            return {}
        return eval(arg[0])

    def test_01_unread_message_count(self):
        case_no = 1
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "unreadCount": {
                    "like": 0,
                    "r": 0,
                    "comment": 0,
                    "share": 0
                }
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('unread', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_02_unread_message_count(self):
        case_no = 2

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('unread', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST)

        self.casedb.closeDB(cur)

    def test_03_flag_notice(self):
        case_no = 3
        r_list = []
        e_list = []
        expect_data = {"data": {"lastReadAt": "2017-07-27 14:49:00"}}
        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_04_flag_notice(self):
        case_no = 4

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('r', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        self.casedb.closeDB(cur)

    def test_05_flag_notice(self):
        case_no = 5

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_06_flag_notice(self):
        case_no = 6

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST, kw)

        self.casedb.closeDB(cur)

    def test_07_flag_like(self):
        case_no = 7
        r_list = []
        e_list = []
        expect_data = {"data": {"lastReadAt": "2017-07-27 14:49:00"}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('like', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_08_flag_like(self):
        case_no = 8

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('like', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        self.casedb.closeDB(cur)

    def test_09_flag_like(self):
        case_no = 9

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('like', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_10_flag_like(self):
        case_no = 10

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('like', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST, kw)

        self.casedb.closeDB(cur)

    def test_11_flag_comment(self):
        case_no = 11
        r_list = []
        e_list = []
        expect_data = {"data": {"lastReadAt": "2017-07-27 14:49:00"}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('comment', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_12_flag_comment(self):
        case_no = 12

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        # kw = self.select_args(cur, case_no)
        response = self.api.op_notice('comment', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        self.casedb.closeDB(cur)

    def test_13_flag_comment(self):
        case_no = 13

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('comment', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_14_flag_comment(self):
        case_no = 14

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('comment', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST, kw)

        self.casedb.closeDB(cur)

    def test_15_flag_share(self):
        case_no = 15
        r_list = []
        e_list = []
        expect_data = {"data": {"lastReadAt": "2017-07-27 14:49:00"}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('share', 'put', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_16_flag_share(self):
        case_no = 16

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        # kw = self.select_args(cur, case_no)
        response = self.api.op_notice('share', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        self.casedb.closeDB(cur)

    def test_17_flag_share(self):
        case_no = 17

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('share', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_18_flag_share(self):
        case_no = 18

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('share', 'put', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST, kw)

        self.casedb.closeDB(cur)

    def test_19_clear_notice(self):
        case_no = 19
        r_list = []
        e_list = []
        expect_data = {"data": {"udpateTime": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('r', 'delete', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_20_clear_comment(self):
        case_no = 20
        r_list = []
        e_list = []
        expect_data = {"data": {"updateTime": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('comment', 'delete', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_21_clear_like(self):
        case_no = 21
        r_list = []
        e_list = []
        expect_data = {"data": {"updateTime": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('like', 'delete', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_22_clear_share(self):
        case_no = 22
        r_list = []
        e_list = []
        expect_data = {"data": {"updateTime": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('share', 'delete', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_23_read_notice(self):
        case_no = 23
        r_list = []
        e_list = []
        expect_data = {"data": {"udpateTime": ""}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_24_read_notice(self):
        case_no = 24

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header, kw)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_NULL, kw)

        self.casedb.closeDB(cur)

    def test_25_read_notice(self):
        case_no = 25

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_26_read_notice(self):
        case_no = 26

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_NULL, kw)

        self.casedb.closeDB(cur)

    def test_27_read_notice(self):
        case_no = 27

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_VALUE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_28_read_notice(self):
        case_no = 28

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, kw)

        self.casedb.closeDB(cur)

    def test_29_read_notice(self):
        case_no = 29

        header = self.api.get_header()

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ACCESS_TOKEN_LOST, kw)

        self.casedb.closeDB(cur)

    def test_30_read_notice(self):
        case_no = 30

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        kw = self.select_args(cur, case_no)
        response = self.api.op_notice('r', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql,
                            self.ecode.ARGS_TYPE_ERROR, kw)

        self.casedb.closeDB(cur)

    def test_32_read_comment(self):
        case_no = 32
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "userNotice": [{
                    "content": "",
                    "createTime": "",
                    "noticeId": 0,
                    "unread": 1
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('comment', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_31_read_like(self):
        case_no = 31
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "userNotice": [{
                    "content": "",
                    "createTime": "",
                    "noticeId": 0,
                    "unread": 1
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('like', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_33_read_share(self):
        case_no = 33
        r_list = []
        e_list = []
        expect_data = {
            "data": {
                "userNotice": [{
                    "content": "",
                    "createTime": "",
                    "noticeId": 0,
                    "unread": 1
                }]
            }
        }

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.op_notice('share', 'get', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)
        self.casedb.closeDB(cur)

    def test_34_unread_r(self):
        case_no = 34
        r_list = []
        e_list = []
        expect_data = {"data": {"unreadCount": 0}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('r', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_35_unread_comment(self):
        case_no = 35
        r_list = []
        e_list = []
        expect_data = {"data": {"unreadCount": 0}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('comment', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_36_unread_like(self):
        case_no = 36
        r_list = []
        e_list = []
        expect_data = {"data": {"unreadCount": 0}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('like', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)

    def test_37_unread_share(self):
        case_no = 37
        r_list = []
        e_list = []
        expect_data = {"data": {"unreadCount": 0}}

        header = self.t.get_header

        cur = self.casedb.connect_casedb()
        response = self.api.get_unread('share', header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0)

        res = self.t.list_dict_keys(response.json(), r_list)
        exp = self.t.list_dict_keys(expect_data, e_list)
        self.t.cmpkeys(case_no, res, exp)

        self.casedb.closeDB(cur)
예제 #5
0
파일: tool.py 프로젝트: ppyang010/gitdir
class tool:

    def __init__(self):
        self.db = DBManual()
        self.cxe = self.db.connect_casedb()  # 获取cur
        path = os.getcwd()
        self.logpth = os.path.join(path, 'log')
        if not os.path.exists(self.logpth):
            os.mkdir(self.logpth)
        self.uid = ''
        self.h = ''

    def get_login_header(self, api, deviceId, param):
        """返回包含heipaToken 的 header"""
        header = api.get_header(deviceId=deviceId)

        if "phoneNumber" in param.keys():
            params = param
            pwd = params['password']
            encode = base64.b64encode(pwd)
            params['password'] = encode
            res = api.mobile_login(params, header)
        elif "thirdAuthToken" in param.keys():
            res = api.third_login(param['thirdPlatformType'], param, header)
        temp = res.json()
        self.uid = temp['data']['user']['userId']
        self.h = api.get_header(deviceId=deviceId, accessToken=temp['data']['token']['accessToken'])

    @property
    def get_login_id(self):
        return self.uid

    @property
    def get_header(self):
        return self.h

    # 比较期望响应码是否等于实际响应码,将pass or fail 写入数据库
    def error_handle(self, cur, case_no, response, test_time, sql, errorCode=0, *param):
        ps = ''
        if param:
            for i in xrange(len(param)):

                if isinstance(param[i], dict) or isinstance(param[i], list):
                    p = str(param[i])
                    ps = ps + p
                else:
                    ps = ps + str(param[i])
        # _data = json.dumps(eval(ps), ensure_ascii=False, indent=1)
        try:
            data = response.json()
            try:
                d = json.dumps(data, ensure_ascii=False, indent=1)
                self.mylog(case_no, 'header:', response.headers)
                self.mylog(case_no, 'request url:', response.url)
                self.mylog(case_no, 'request json:', ps)
                self.mylog(case_no, 'response data: \n', d)
                print "\n"
                assert data["errorCode"] == errorCode, u"错误信息: %s" % data['message']
                try:
                    cur.execute(sql, (ps, d[:4999], "pass", test_time, case_no))
                    # print type(d)
                except MySQLdb.Error, e:
                    print "manual database error:%s" % e
                    cur.execute(sql, (ps, d[:1000], "pass", test_time, case_no))
            except AssertionError:
                cur.execute(sql, (ps, d[:1000], "fail", test_time, case_no))
        except TypeError:
            data = response.text
            cur.execute(sql, (ps, data[:1000], "fail", test_time, case_no))

    def data_error(self, cur, case_no, expectdata, actualdata, sql):
        self.mylog(case_no, 'database data :%s', expectdata)
        self.mylog(case_no, 'response data:%s', actualdata)
        if expectdata != actualdata:
            cur.execute(sql, ("fail", case_no))

    # 重新定义错误处理函数,包含响应码比较,返回数据比较,日志记录
    # 需要重新写个处理mysql数据库的类函数 1)数据库连接 2)创建数据表 3)插入用例 4)更新用例 5)
    # 重新整理处理Excel的函数 1)读取excel;2)写回excel
    # 日志中包含执行的函数名,用例标题(从excel中读取),尝试将数据格式化 用json.dumps(obj, indent=1)
    def newErrorHandler(self, func_name, status_code, response, test_time, error_code=0, *param):
        """
        思路: 先比较服务器返回的status_code,之后再比较errorCode;
        如果errorCode相等,继续比较响应数据,响应中要比较字段及特定的某些值;如果errorCode不相等,则终止比较,数据库写fail。
        日志要添加function_name, case_title, response_data。打印到控制台的数据,需要格式化
        """
        pass

    def executeSQL(self, sql, params):
        self.cxe.executemany(sql, params)

    def select_result(self, tablename):
        """
        获取测试结果
        :param tablename: 表名
        :return: 返回data
        """
        sql = "select case_no,response,result,test_time from " + tablename
        n = self.cxe.execute(sql)
        data = self.cxe.fetchmany(n)
        return data

    def trans_list(self, data):
        """
        将获取的结果转换为list,供writeExcel使用
        :param data:
        :return:
        """
        result = []
        for i in range(0, len(data)):
            dic = {}
            dic['case_no'] = data[i][0]
            d = data[i][1]
            # print d
            # print d.decode('utf-8').encode('gbk')
            dic['response'] = d
            dic['result'] = data[i][2]
            dic['time'] = data[i][3]
            result.append(dic)
        return result

    def write_to_excel(self, result):    # 将结果写到excel中
        c = CaseMode.CaseConfig()
        files = c.get_case_file()
        handle = HandleExcel(files)
        handle.write_result(files, result, c.get_result_file())

    def cls(self):    #
        self.db.closeDB(self.cxe)

    def mylog(self, func, *args):
        logname = os.path.join(self.logpth, 'log.txt')
        nowtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        f = open(logname, 'a+')
        if len(args) > 1:
            print "[ %s excuting case_no: %s ] %s %s" % (nowtime, func, args[0], args[1])
            f.write("[%s excuting case_no: %s] %s %s " % (nowtime, func, args[0], args[1]) + '\n')
        else:
            print "[ %s excuting case_no: %s ] %s" % (nowtime, func, args)
            f.write("[%s excuting case_no: %s] %s" % (nowtime, func, args) + '\n')
        f.write('\n')
        f.close()

    def list_dict_keys(self, dic, keyl):
        """
        将传入的字典中的键转为数组保存
        :param dic:   dict
        :param keyl: list
        :return: list
        """
        if "errorCode" in dic.keys():
            del dic['errorCode']
        if "message" in dic.keys():
            del dic['message']
        for i in dic.keys():
            keyl.append(i)
            if isinstance(dic[i], dict):
                self.list_dict_keys(dic[i], keyl)
            elif isinstance(dic[i], list):
                if len(dic[i]) > 0:
                    inner = dic[i][0]
                else:
                    continue
                if isinstance(inner, dict) or isinstance(inner, list):
                    if len(inner) > 0:
                        self.list_dict_keys(inner, keyl)
                else:
                    continue
        return keyl

    def cmpkeys(self, case_no, response_list, expect_list):
        """
        比较响应数据与期望数据键是否一致。若一致,返回False
        :param response_list:
        :param expect_list:
        :return:
        """
        minus1 = list(set(response_list).difference(set(expect_list)))
        minus2 = list(set(expect_list).difference(set(response_list)))
        diffrence = list(set(minus1).union(minus2))
        if len(minus1) != 0 or len(minus2) != 0:
            self.mylog(case_no, u"response_list: ", response_list)
            self.mylog(case_no, u"expect_list: ", expect_list)
            self.mylog(case_no, u"response_list 与 expect_list 的差异为: ", diffrence)
            return diffrence
        return False
예제 #6
0
class register_case:
    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual()
        self.t = tool()
        self.sql = """update register_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""

    def test_register_device(self):  # 设备注册正向验证
        case_no = 1
        cur = self.casedb.connect_casedb()
        param = {
            "machineId": "10000003",
            "password": "",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.device_register(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_register_device_same_machineid(self):  # 同一个machineId再次注册
        case_no = 2
        cur = self.casedb.connect_casedb()
        param = {
            "machineId": "10000003",
            "password": "",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.device_register(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_register_device_machineid_null(self):  # machineId为空,不能注册成功
        case_no = 3
        cur = self.casedb.connect_casedb()
        param = {
            "machineId": "",
            "password": "",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.device_register(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_register_device_lack_args(self):  # 设备注册缺少参数
        case_no = 4
        cur = self.casedb.connect_casedb()
        param = {"machineId": ""}
        response = self.api.device_register(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_register_device_platform_wrong(self):  #设备注册 platform取值错误
        case_no = 5
        cur = self.casedb.connect_casedb()
        param = {
            "machineId": "10000004",
            "password": "",
            "platform": "iOOS",
            "clientVersion": "2.0"
        }

        response = self.api.device_register(param)

        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103, param)
        self.casedb.closeDB(cur)

    def test_register_weixin(
            self):  # 微信住注册,注册需要使用deviceID。machineID与deviceID必须一致
        case_no = 6
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "weixintoken3",
            "thirdAccoutName": "weixinq",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code

        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_register_weibo(self):
        case_no = 7
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "weibotoken3",
            "thirdAccoutName": "weibo3",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weibo",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('weibo', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_register_qq(self):
        case_no = 8
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "addmachienId",
            "thirdAccoutName": "qq3",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 10000003
        }
        response = self.api.third_register('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_register_weixin_duplicate(self):
        case_no = 9
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "weixintoken3",
            "thirdAccoutName": "weixinq",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100401, param)
        self.casedb.closeDB(cur)

    def test_register_weibo_duplicate(self):
        case_no = 10
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "weibotoken3",
            "thirdAccountName": "weibo3",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weibo",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('weibo', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100401, param)
        self.casedb.closeDB(cur)

    def test_register_qq_duplicate(self):
        case_no = 11
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "qqtoken3",
            "thirdAccoutName": "qq3",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100401, param)
        self.casedb.closeDB(cur)

    def test_register_weixin_platform_null(self):
        case_no = 12
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "weixintoken3",
            "thirdAccoutName": "weixinq",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "weixin",
            "platform": "",
            "clientVersion": "2.0"
        }
        response = self.api.third_register('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_register_qq_more_args(self):  # 多了参数不做控制
        case_no = 13
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        param = {
            "thirdAuthToken": "addmachienId_1",
            "thirdAccoutName": "qq_1",
            "avatarUrl":
            "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 10000003
        }
        response = self.api.third_register('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_mobile_register(self):  # 先发送注册短信验证码,再注册手机
        pwd = base64.b64encode('888888')
        sms_id = 19  # 用例中短信接口的id
        phone_id = 20  # 手机接口的id
        # cur = self.casedb.connect_casedb()
        # s = "select response from register_case where case_no = 1"
        # cur.execute(s)
        # dr = cur.fetchone()
        # device = eval(dr[0])
        # device_id = device['data']['deviceId']
        header = self.api.get_header(
            deviceId='2e99c2eb-fe73-4d2a-9c1e-7416ba2f1699')
        sms_param = {"phoneNumber": 18782943851}
        phone_param = {
            "phoneNumber": "18782943851",
            "password": pwd,
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0000",
            "registerSmsId": "123456"
        }

        response = self.api.mobile_sms(sms_param, header)
        # assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        # t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        # sql = """update register_case set response=%s,result=%s,test_time=%s WHERE id = %s"""
        # data = response.json()
        # d = json.dumps(data, ensure_ascii=False)

        # registerSmsId = data['data']['registerSmsId']
        # phone_param['registerSmsId'] = registerSmsId
        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        # self.t.error_handle(cur, phone_id, response, t, self.sql, 0, phone_param)
        # self.casedb.closeDB(cur)

    def test_mobile_register_verify_code(self):  #
        case_no = 18
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "18782943854"}
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, sms_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_wrong_number(self):  # 手机格式错误
        """
        case_no =15;手机注册,发送验证码接口,手机中含字母
        :return:
        """
        case_no = 15  # 用例中短信接口的id
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "187829438de"}
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        # sql = """update register_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            sms_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_wrong_verify_code(self):  # 验证码错误
        case_no = 16  # 手机接口的id case_no:16
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 1"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "18782943853"}
        phone_param = {
            "phoneNumber": "18782943853",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0001",
            "registerSmsId": ""
        }
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        # sql = """update register_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        data = response.json()
        # d = json.dumps(data, ensure_ascii=False)
        self.assertEqual(data["errorCode"], 0, u"错误信息: %s" % data['message'])

        registerSmsId = data['data']['registerSmsId']
        phone_param['registerSmsId'] = registerSmsId
        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            sms_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_wrong_smsid(self):  # smsmid错误
        case_no = 17
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "18782943854"}
        phone_param = {
            "phoneNumber": "18782943854",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0000",
            "registerSmsId": "4F2D6B7CFEFA6D2C-1-15DDEE42868-200000028"
        }
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        # t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        # sql = """update register_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        data = response.json()
        # d = json.dumps(data, ensure_ascii=False)
        self.assertEqual(data["errorCode"], 0, u"错误信息: %s" % data['message'])

        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            phone_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_phone_length_shorter(self):  #
        """
        case_no=19;手机注册,发送短信验证码接口,手机号长度非11位
        :return:
        """
        case_no = 19
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "1878294382"}
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100103,
                            sms_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_password_length_shorter(self):  #
        case_no = 20
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "18782943855"}
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        sms_data = response.json()

        phone_param = {
            "phoneNumber": "18782943855",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0000",
            "registerSmsId": ""
        }

        registerSmsId = sms_data['data']['registerSmsId']
        phone_param['registerSmsId'] = registerSmsId
        # sql = """update register_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100108,
                            phone_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_password_length_longer(self):  #
        case_no = 21
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        # cur.execute(s)
        # dr = cur.fetchone()
        # device = eval(dr[0])
        # device_id = device['data']['deviceId']
        header = self.api.get_header(
            deviceId='2e99c2eb-fe73-4d2a-9c1e-7416ba2f1699')
        sms_param = {"phoneNumber": "18782943856"}
        response = self.api.mobile_sms(sms_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        sms_data = response.json()

        phone_param = {
            "phoneNumber": "18782943856",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0000",
            "registerSmsId": ""
        }
        # registerSmsId = sms_data['data']['registerSmsId']
        # registerSmsId = 123456
        phone_param['registerSmsId'] = '123456'

        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100108,
                            phone_param)
        self.casedb.closeDB(cur)

    def test_mobile_register_password_length(self):  #
        case_no = 22
        cur = self.casedb.connect_casedb()
        s = "select response from register_case where case_no = 2"
        cur.execute(s)
        dr = cur.fetchone()
        device = eval(dr[0])
        device_id = device['data']['deviceId']
        header = self.api.get_header(deviceId=device_id)
        sms_param = {"phoneNumber": "18782943858"}
        response = self.api.mobile_sms(sms_param, header)
        sms_data = response.json()
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        phone_param = {
            "phoneNumber": "18782943858",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "registerSmsCode": "0000",
            "registerSmsId": ""
        }

        registerSmsId = sms_data['data']['registerSmsId']
        phone_param['registerSmsId'] = registerSmsId
        response = self.api.mobile_register(phone_param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100108,
                            phone_param)
        self.casedb.closeDB(cur)
예제 #7
0
class login_case:
    def __init__(self, islocal=0):
        self.api = API2(islocal)
        self.casedb = DBManual()
        self.t = tool()
        self.login_param, self.deviceid = runconfig.RunConfig().get_login(
            islocal)
        self.t.get_login_header(self.api, self.deviceId, self.login_param)
        self.sql = """update login_case set args=%s, response=%s,result=%s,test_time=%s WHERE case_no = %s"""

    def test_01_login_mobile(self):
        case_no = 1
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")

        response = self.api.mobile_login(self.login_param, header)
        self.assertEqual(response.status_code, 200,
                         u"http响应错误,错误码 %s" % response.status_code)
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 0,
                            self.login_param)
        self.casedb.closeDB(cur)

    def test_02_mobile_login_phone_wrong(self):
        case_no = 2
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            'phoneNumber': "18300000000",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.mobile_login(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100402, param)
        self.casedb.closeDB(cur)

    def test_03_mobile_login_pwd_wrong(self):
        case_no = 3
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            'phoneNumber': "18782943850",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.mobile_login(param, header)
        # http 响应码
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100404, param)
        self.casedb.closeDB(cur)

    def test_04_mobile_login_lack_args(self):
        case_no = 4
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {'phoneNumber': "18782943850", "password": "******"}
        response = self.api.mobile_login(param, header)
        # http 响应码
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_05_mobile_login_type_wrong(self):
        case_no = 5
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            'phoneNumber': 18782943850,
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.mobile_login(param, header)
        # http 响应码
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100102, param)
        self.casedb.closeDB(cur)

    def test_06_login_weixin(self):
        case_no = 6
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "weixin_token2",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_07_login_weixin_token_wrong(self):
        case_no = 7
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "weixintoke",
            "thirdPlatformType": "weixin",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100402, param)
        self.casedb.closeDB(cur)

    def test_08_login_weixin_lack_args(self):
        case_no = 8
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "weixintoke",
            "thirdPlatformType": "weixin",
            "machineId": 100001
        }
        response = self.api.third_login('weixin', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_09_login_qq(self):
        case_no = 9
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "qqtoken",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_10_login_qq_token_wrong(self):
        case_no = 10
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "qqtoke",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100402, param)
        self.casedb.closeDB(cur)

    def test_11_login_qq_lack_args(self):
        case_no = 11
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "qqtoken",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.third_login('qq', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_12_login_weibo(self):
        case_no = 12
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "weibotoken",
            "thirdPlatformType": "weibo",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('weibo', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_13_login_weibo_token_wrong(self):
        case_no = 13
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "weibotokn",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('weibo', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100402, param)
        self.casedb.closeDB(cur)

    def test_14_login_weibo_lack_args(self):
        case_no = 14
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {"thirdAuthToken": "weibotokn", "thirdPlatformType": "weibo"}
        response = self.api.third_login('weibo', param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_15_device_login(self):
        case_no = 15
        cur = self.casedb.connect_casedb()
        # header = self.api.get_header({"deviceId": "34e7a55f-8fb9-4511-b1b7-55d6148fa9bb"})
        param = {
            "deviceId": "34e7a55f-8fb9-4511-b1b7-55d6148fa9bb",
            "password": "",
            "platform": "iOS",
            "clientVersion": "2.0"
        }
        response = self.api.device_login(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_16_device_login_lack_args(self):
        case_no = 16
        cur = self.casedb.connect_casedb()
        # header = self.api.get_header({"deviceId": "34e7a55f-8fb9-4511-b1b7-55d6148fa9bb"})
        param = {"deviceId": "34e7a55f-8fb9-4511-b1b7-55d6148fa9bb"}
        response = self.api.device_login(param)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    # 刷新token接口,需要去拿已登陆的用户的token。去本地数据库取response。前置条件为case_no 1 6 9 12 result=pass
    def test_17_refresh_token(self):
        case_no = 17

        # qq登陆
        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "thirdAuthToken": "qqtoken",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        response = self.api.third_login('qq', param, header)
        self.assertEqual(response.status_code, 200,
                         u"http响应错误,错误码 %s" % response.status_code)
        res = response.json()
        # 从返回json中获取token
        tokendic = res['data']['token']
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb",
            accessToken=tokendic['accessToken'])
        param["refreshToken"] = tokendic['refreshToken']
        param['accessToken'] = tokendic['accessToken']

        response = self.api.refresh_token(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100404, param)
        self.casedb.closeDB(cur)

    def test_18_refresh_token_wrong(self):
        case_no = 18

        param = {
            "refreshToken": "",
            "accessToken": "",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        select_sql = """select response from login_case where case_no = 1 """
        #数据库取数据
        cur = self.casedb.connect_casedb()
        cur.execute(select_sql)
        re = cur.fetchone()
        res = eval(re[0])  # str数据转为dict
        tokendic = res['data']['token']
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb",
            accessToken=tokendic['accessToken'])

        param["refreshToken"] = "dddddddddddddddddddddddddddd"
        param['accessToken'] = tokendic['accessToken']

        response = self.api.refresh_token(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100208, param)
        self.casedb.closeDB(cur)

    def test_19_access_token_wrong(self):
        case_no = 19
        param = {
            "refreshToken": "",
            "accessToken": "",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        select_sql = """select response from login_case where case_no = 1 """
        #数据库取数据
        cur = self.casedb.connect_casedb()
        cur.execute(select_sql)
        re = cur.fetchone()
        res = eval(re[0])  # str数据转为dict
        tokendic = res['data']['token']
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb",
            accessToken=tokendic['accessToken'])

        param["refreshToken"] = tokendic['refreshToken']
        param['accessToken'] = "ddddddddddddddddddddddddddddddddddddddddd"

        response = self.api.refresh_token(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100208, param)
        self.casedb.closeDB(cur)

    def test_20_modify_pwd(self):
        case_no = 20

        select_sql = """select response from login_case where case_no = 1 """
        # 数据库取数据
        cur = self.casedb.connect_casedb()
        cur.execute(select_sql)
        re = cur.fetchone()
        res = eval(re[0])  # str数据转为dict
        tokendic = res['data']['token']
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb",
            accessToken=tokendic['accessToken'])
        param = {"phoneNumber": "18782943850"}
        response = self.api.password_back_sms(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)
        self.casedb.closeDB(cur)

    def test_21_logout(self):
        case_no = 21
        select_sql = """select response from login_case where case_no = 12 """
        # 数据库取数据
        cur = self.casedb.connect_casedb()
        header = self.t.get_login_header(self.api, self.deviceId,
                                         self.login_param)
        param = {"platform": "iOS", "machineId": 100001}
        response = self.api.login_out(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 0, param)

        self.casedb.closeDB(cur)

    def test_22_logout_lack_args(self):
        """
        退出登陆,缺少参数
        """
        case_no = 22
        # 数据库取数据
        cur = self.casedb.connect_casedb()

        header = self.t.get_header
        param = {"platform": "iOS"}
        response = self.api.login_out(param, header)
        assert response.status_code == 500, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        self.t.error_handle(cur, case_no, response, t, self.sql, 100105, param)
        self.casedb.closeDB(cur)

    def test_23_logout_machineid_wrong(self):
        case_no = 23
        cur = self.casedb.connect_casedb()
        header = self.t.get_header

        param = {"platform": "iOS", "machineId": 1000100}
        response = self.api.login_out(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100209, param)
        self.casedb.closeDB(cur)

    def test_24_logout_unlogin(self):
        case_no = 24
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        cur = self.casedb.connect_casedb()
        header = self.api.get_header()
        param = {"platform": "iOS", "machineId": 100001}
        print "[%s excuting case %s ] params: %s" % (
            t, 'test_24_logout_unlogin', param)
        response = self.api.login_out(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.t.error_handle(cur, case_no, response, t, self.sql, 100201, param)

        self.casedb.closeDB(cur)

    def test_25_login_machineId_not_match_deviceid(self):
        case_no = 25

        cur = self.casedb.connect_casedb()
        header = self.api.get_header(
            deviceId="34e7a55f-8fb9-4511-b1b7-55d6148fa9bb")
        param = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 10001222
        }

        response = self.api.mobile_login(param, header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        sql = """update login_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, sql, 100410, param)
        self.casedb.closeDB(cur)

    def test_26_password_back_phone_has_letter(self):
        case_no = 26

        param = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        cur = self.casedb.connect_casedb()
        header = self.t.get_login_header(self.api, self.deviceId, param)

        response = self.api.password_back_sms({"phoneNumber": "18782943oz0"},
                                              header)

        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        sql = """update login_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, sql, 100401,
                            {"phoneNumber": "18782943oz0"})
        self.casedb.closeDB(cur)

    def test_27_password_back_phone_length_longer(self):
        case_no = 27

        param = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        cur = self.casedb.connect_casedb()
        header = self.t.get_login_header(self.api, self.deviceId, param)

        response = self.api.password_back_sms({"phoneNumber": "1878294385200"},
                                              header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        sql = """update login_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, sql, 100401,
                            {"phoneNumber": "1878294385200"})
        self.casedb.closeDB(cur)

    def test_28_password_back_phone(self):  # 密码修改成功后,查看是否是登陆状态
        case_no = 28

        param = {
            "phoneNumber": "18782943852",
            "password": "******",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": 100001
        }
        cur = self.casedb.connect_casedb()
        header = self.t.get_login_header(self.api, self.deviceId, param)

        res = self.api.password_back_sms({"phoneNumber": "18782943852"},
                                         header)
        assert res.status_code == 200, u"http响应错误,错误码 %s" % res.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        pwd = base64.b64encode("1234567")
        data = res.json()
        pwd_param = {
            "phoneNumber": "18782943852",
            "password": pwd,
            "platform": "iOS",
            "clientVersion": "2.0",
            "retrievalPasswordSmsCode": "0000",
            "retrievalPasswordSmsCode": "0000",
            "retrievalPasswordSmsId": data['data']['retrievalPasswordSmsId']
        }

        response = self.api.password_back(pwd_param, header)
        sql = """update login_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, sql, 0, pwd_param)
        self.casedb.closeDB(cur)

    def test_29_third_modify_pwd_with_no_banding(self):
        case_no = 29

        param = {
            "thirdAuthToken": "qqtoken",
            "thirdPlatformType": "qq",
            "platform": "iOS",
            "clientVersion": "2.0",
            "machineId": "100001"
        }
        cur = self.casedb.connect_casedb()
        header = self.t.get_header()

        response = self.api.password_back_sms({"phoneNumber": "18782943700"},
                                              header)
        assert response.status_code == 200, u"http响应错误,错误码 %s" % response.status_code
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        sql = """update login_case set response=%s,result=%s,test_time=%s WHERE case_no = %s"""
        self.t.error_handle(cur, case_no, response, t, sql, 100401,
                            {"phoneNumber": "18782943700"})
        self.casedb.closeDB(cur)