def test_edit_profile(self, nickname):
        token = file_operation.read_file('token.json')
        body = {
            'access_token': token['access_token'],
            'birthday': '2000-01-01',
            'city': '',
            'nickname': nickname,
            'province': '',
            'sex': 3
        }
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user/edit_profile'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            print(response.text)
            datas = response.json()

        except Exception as e:
            print('出错了:', e)

        assert_that(response.json()['code']).is_equal_to(0)
        assert_that(datas['msg']).is_equal_to('请求成功')
Example #2
0
    def test_check_nickname_disabled_word(self, nickname):
        token = file_operation.read_file('token.json')
        body = {'access_token': token['access_token'], 'title': nickname}
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user/check_nickname_disabled_word'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            print(response.text)
            datas = response.json()['data']
            if datas['status']:
                print('没有禁词')
            else:
                print('包含禁词')

        except Exception as e:
            print('出错了:', e)

        assert_that(response.json()['code']).is_equal_to(0)
    def test_recommend(self, page):
        config_path = readConfig.ReadConfig.get_config_path('path')
        body = {'page': page, 'pageSize': '20', 'app_key': 'lemondream'}
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/recommend/get_recommend_content_list'
        url = readConfig.ReadConfig.get_http('baseurl') + path
        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            # print(response.text)
            dataList = response.json()['data']
            obj_ids = get_response_value.get_target_value(
                'obj_id', dataList, [])
            obj_id = {"obj_id": obj_ids[0]}
            print(obj_id)
            file_operation.write_file(obj_id, 'datas.json')
            tpyes = get_response_value.get_target_value('type', dataList, [])

        except Exception as e:
            print('出错了:', e)
        assert_that(response.status_code).is_equal_to(200)
        for i in range(0, len(tpyes)):
            assert_that(tpyes[i]).is_not_empty()
            assert_that(['1', '2', '4', '7', '8', '9',
                         '10']).contains(tpyes[i])
Example #4
0
 def get_request_headers(self, index, body):
     Authorization = HmacSHA256.auth(json.dumps(body))  # 请求头Authorization
     AuthorizationV2 = HmacSHA256.auth2(json.dumps(body))  #请求头AuthorizationV2
     biData = json.dumps(file_operation.read_file('biD.json'))
     XToken = file_operation.read_file('token.json')['X-Token']
     versionCode = readConfig.ReadConfig.get_http('versionCode')
     accessToken = file_operation.read_file('token.json')['access_token']
     headers = eval(self.datas.get_request_headers(index))
     return headers
    def test_recommend_content(self, page):
        body = {"page": "1", "pageSize": "20", "app_key": "lemondream"}
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/recommend/get_recommend_content_list'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        with open("../config/headers.json", 'r') as load_f:
            headers = json.load(load_f)
        print(headers)
        response = requests.post(url, json=body, headers=headers, verify=False)
        status = response.json()['msg']
        self.assertEqual(status, '请求成功')
        print(response.text)
Example #6
0
    def test_user_home_page(self):
        token = file_operation.read_file('token.json')
        uid = file_operation.read_file('datas.json')
        body = {'user_id':uid['uid'],'access_token':token['access_token']}
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user_home_page/get_user_home_page_info'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
	        headers = file_operation.read_file('headers.json')
	        response = requests.post(url, json=body, headers=headers, verify=False)
	        print(response.text)
	        # datas = response.json()['data']

        except Exception as e:
	        print('出错了:', e)
        assert_that(response.json()['code']).is_equal_to(0)
    def test_get_module_unread(self):
        token = file_operation.read_file('token.json')
        body = {'access_token': token['access_token']}
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/app/get_module_unread'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            datas = response.json()['data']
        except Exception as e:
            print('出错了:', e)

        assert_that(response.status_code).is_equal_to(200)
    def test_get_external_content_info(self, value):
        body = {'content_id': 190648615}
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/External/get_external_content_info'
        url = readConfig.ReadConfig.get_http('baseurl') + path
        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            # print(response.text)

        except Exception as e:
            print('出错了:', e)
        assert_that(response.json()['code']).is_equal_to(0)
        single_info = response.json()['data']['info']
        assert_that(single_info['content']).is_not_none()
	def test_get_recommend_tag(self):
		token = file_operation.read_file('token.json')
		body = {'access_token': token['access_token'], 'page': '1', 'pagesize': '12', }
		# print(json.dumps(body))
		HmacSHA256.sh256(json.dumps(body))

		path = '/api/user_tag/get_recommend_tag_list'
		url = readConfig.ReadConfig.get_http('baseurl') + path

		try:
			headers = file_operation.read_file('headers.json')
			response = requests.post(url, json=body, headers=headers, verify=False)
			# print(response.text)
			datas = response.json()['data']
			print(datas['list'])
			assert_that(datas['list']).is_not_none()

		except Exception as e:
			print('出错了:', e)
		assert_that(response.status_code).is_equal_to(200)
    def test_get_game_single_info(self, value):
        token = file_operation.read_file('token.json')
        body = {'single_id': value, 'access_token': token['access_token']}
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/adventure/get_game_single_info'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            # print(response.text)
        except Exception as e:
            print('出错了:', e)
        assert_that(response.json()['code']).is_equal_to(0)
        single_info = response.json()['data']['single_info']
        assert_that(single_info['author_id']).is_not_none()
        assert_that(single_info['data_json']).is_not_none()
Example #11
0
    def test_third_login(self):
        config_path = readConfig.ReadConfig.get_config_path('path')
        body = {
            'avatar':
            'http://thirdqq.qlogo.cn/g?b=oidb&k=edlgyevh0NKzuOHe2SX6yg&s=100',
            'birthday': '2000-01-01',
            'city': '',
            'device': 1,
            'nickname': 'ssk',
            'openid': 'FD717EC03696FFB9E78AADEC85E6565D',
            'province': '',
            'sex': 2,
            'type': 2
        }
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user/third_login'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        headers = file_operation.read_file('headers.json')
        try:
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            datas = response.json()['data']
            token = {
                'access_token': datas['access_token'],
                'refresh_token': datas['refresh_token']
            }
            # print(token)
            file_operation.write_file(token, 'token.json')
        except Exception as e:
            print('出错了:', e)
        assert_that(response.json()['code']).is_equal_to(0)

        assert_that(datas['uid']).is_equal_to(1042)
        assert_that(datas['is_bind']).is_equal_to(1)
Example #12
0
    def test_get_tab_list(self):
        token = file_operation.read_file('token.json')
        body = {
            'access_token': token['access_token'],
            'page': '1',
            'pagesize': '20'
        }
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/voice_template/get_tab_list'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)

        except Exception as e:
            print('出错了:', e)

        assert_that(response.status_code).is_equal_to(200)
Example #13
0
    def test_get_external_content_info(self, value):
        token = file_operation.read_file('token.json')
        body = {'content_id': value, 'access_token': token['access_token']}
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/External/get_external_content_info'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url, json=body, headers=headers, verify=False)
            info = response.json()['data']['info']
            print(info['video_obj'])

        except Exception as e:
	        print('出错了:', e)

        assert_that(response.json()['code']).is_equal_to(0)
        if info['type'] == 2:
            assert_that(info['type']).is_not_none()
            assert_that(info['video_obj']).contains_entry({'max_height': 1280}, {'max_width': 720})
        elif type  == 1:
	        assert_that(info['video_obj']).is_empty()
    def test_check_nickname(self, nickname):
        token = file_operation.read_file('token.json')
        body = {'access_token': token['access_token'], 'nickname': nickname}
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user/check_nickname'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
	        headers = file_operation.read_file('headers.json')
	        response = requests.post(url, json=body, headers=headers, verify=False)
	        print(response.text)
	        datas = response.json()['data']

	        if datas['is_used'] == 0:
		        print('可以调用编辑昵称接口')
	        elif datas['is_used'] == 1:
		        print('昵称已被占用')
        except Exception as e:
            print('出错了:',e)

        assert_that(response.json()['code']).is_equal_to(0)
Example #15
0
    def test_user_profile(self):
        token = file_operation.read_file('token.json')
        body = {'access_token': token['access_token']}
        # print(json.dumps(body))
        HmacSHA256.sh256(json.dumps(body))

        path = '/api/user/profile'
        url = readConfig.ReadConfig.get_http('baseurl') + path

        try:
            headers = file_operation.read_file('headers.json')
            response = requests.post(url,
                                     json=body,
                                     headers=headers,
                                     verify=False)
            # print(response.text)
            datas = response.json()['data']
        except Exception as e:
            print('出错了:', e)

        assert_that(response.json()['code']).is_equal_to(0)
        assert_that(datas['id']).is_equal_to(1042)
        assert_that(datas['nickname']).is_not_none()
Example #16
0
    def test_api(self, index, casesname, module, id):
        # 判断测试用例是否有依赖的字段
        if len(MyTestSuite.datas.get_request_parameter(index)) == 0:
            body = {'': ''}
        else:
            body = eval(MyTestSuite.datas.get_request_parameter(index))

        Authorization = HmacSHA256.sh258(
            json.dumps(body))  # 请求头需要Authorization
        biData = str(file_operation.read_file('biD.json'))
        XToken = file_operation.read_file('token.json')['X-Token']
        versionCode = readConfig.ReadConfig.get_http('versionCode')
        headers = eval(MyTestSuite.datas.get_request_headers(index))
        path = MyTestSuite.datas.get_request_url(index)
        url = readConfig.ReadConfig.get_http('baseurl') + path
        except_data = MyTestSuite.datas.get_expect_data(index)

        try:
            if MyTestSuite.datas.get_request_method(index) == 'post':
                response = requests.post(url,
                                         json=body,
                                         headers=headers,
                                         verify=False)
                # print(json.dumps(response.json(), ensure_ascii=False, sort_keys=True, indent=2))  #格式化显示返回的数据

            else:
                response = requests.get(url, params=body, headers=headers)
            MyTestSuite.result.set_actual_data(
                globals()['sheet_id'], index,
                str(response.json()))  # 将实际结果写入excel

        except Exception as e:
            globals()['result'] = '报错啦'
            print('报错啦', response.text)
            MyTestSuite.result.set_actual_data(globals()['sheet_id'], index,
                                               str(e))
            MyTestSuite.result.set_pass_fail(globals()['sheet_id'], index,
                                             globals()['result'])  # 写入测试结果

        MyTestSuite.result.set_pass_fail(globals()['sheet_id'], index,
                                         globals()['result'])  # 先写入测试结果为不通过
        result = result_assert.result_assert(response.text,
                                             response.status_code,
                                             except_data)  #断言,判断接口状态和预期结果
        if result == 'pass':
            globals()['result'] = 'pass'
            MyTestSuite.result.set_pass_fail(globals()['sheet_id'], index,
                                             globals()['result'])  # 更新为测试通过