class MapTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.data = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = MapAPI(self.baseurl) # self.err=[] def test_Near_success(self): unequal = 0 latitude = 30.56088604184985 longitude = 104.05446182158 radius = 5000 addition = radius/(1000*111) medley_sql = 'SELECT COUNT(*) FROM song_basic_info WHERE create_latitude < %s AND create_longitude <%s ' \ 'and create_latitude> %s and create_longitude >%s and song_status=1 or song_status =5 and audio_type=4'\ % (latitude+addition, longitude+addition,latitude-addition,longitude-addition) complaint_sql = 'SELECT COUNT(*) FROM song_basic_info WHERE create_latitude < %s AND create_longitude <%s ' \ 'and create_latitude> %s and create_longitude >%s and song_status=1 and audio_type=1' \ % (latitude + addition, longitude + addition, latitude - addition, longitude - addition) rap_sql = 'SELECT COUNT(*) FROM song_basic_info WHERE create_latitude < %s AND create_longitude <%s ' \ 'and create_latitude> %s and create_longitude >%s and song_status=1 and audio_type=2' \ % (latitude + addition, longitude + addition, latitude - addition, longitude - addition) medley = self.db.getSet(medley_sql) complaint = self.db.getSet(medley_sql) rap = self.db.getSet(rap_sql) medleynum = medley[0][0] complaintnum = complaint[0][0] rapnum = rap[0][0] response = self.user.map_Near(latitude, longitude, radius, '') args = {'latitude': latitude, 'longitude': longitude, 'radius': radius} try: self.assertEqual(200, response.status_code) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) if medleynum != len(r['data']['songs']['medleys']): print "medley actual has %s and we get %s" % (medleynum, len(r['data']['songs']['medleys'])) unequal += 1 if complaintnum != len(r['data']['songs']['complaints']): print "complaint actual has %s and we get %s" % (complaintnum, len(r['data']['songs']['complaints'])) unequal += 1 if rapnum != len(r['data']['songs']['raps']): print "rap actual has %s and we get %s" % (rapnum, len(r['data']['songs']['raps'])) unequal += 1 self.assertEqual(0, unequal) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args:%s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) '''def test_Near_all_null(self):
def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.user = LoginAPI(self.baseurl) login = testData(self.baseurl) self.udata = login.getUserData[0] self.api = MyAPI() self.result = ""
def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.user = NewAPIv1_2(self.baseurl)
def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.data = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual()
def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.data = self.d.getUserData self.sidList = self.d.getSongIds self.auList = self.d.getAudios() self.cidList = self.d.getComments() self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = DiscoverAPI(self.baseurl)
def setUp(self): self.api = MyAPI() cfg = RunConfig() self.baseurl = cfg.get_base_url() #java # self.baseurl = 'http://139.129.208.77:9091' self.cateIdList = [ 10000001, 10000002, 10000003, 10000004, 10000005, 10000006, 10000007, 1000000, 10000009 ]
def __init__(self, url): self.baseurl = url self.api = MyAPI()
class MessageTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.d = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = MessageAPI(self.baseurl) def test_message_Unread(self): token = self.d[0]['token'] response = self.user.message_Unread(token) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) """def test_message_Unread_token_null(self): # token = self.d.login_data[0]['token'] response = self.user.message_Unread(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) # self.assertEqual(num, len(r['data']['songs'])) def test_message_Unread_token_wrong(self): # token = self.d.login_data[0]['token'] response = self.user.message_Unread('ddd') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status'])""" def test_message_History_sys(self): token = self.d[0]['token'] response = self.user.message_History(token, 'sys') try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_message_History_notice(self): token = self.d[0]['token'] response = self.user.message_History(token, 'notice') try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) """def test_message_History_notice_token_null(self):
class userinfoTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.data = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() # self.err=[] def test_FollowedSong_success(self): user = UserAPI(self.baseurl) response = user.user_FollowedSong(self.data[0]['token']) try: self.assertEqual(200, response.status_code) # response.status_code == 200 r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, ) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % self.data['token'] print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_followedList_success(self): user = UserAPI(self.baseurl) response = user.user_followedList(self.data[0]['id']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) try: self.assertEqual(0, r['status']) except AssertionError as e: print "test_cancelFocus_again failed" # self.verificationErrors.append(e) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % self.data[0]['id'] print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_FansList_success(self): user = UserAPI(self.baseurl) response = user.user_fansList(int(self.data[0]['id'])) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % self.data[0]['id'] print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_BlackList_data_check(self): user = UserAPI(self.baseurl) response = user.user_BlackList(self.data[0]['token']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'select count(*) from user_blacklist where user_id= %s' % self.data[ 0]['id'] num = self.db.getSingle(sql) self.assertEqual(len(r['data']['blacklist']), int(num[0])) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % ar print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Create_Medley_success(self): args = { 'audios': [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], 'images': [], 'latitude': 104, 'longitude': 30.56089, 'maxCount': 5, 'title': 'interface' } user = UserAPI(self.baseurl) response = user.user_Create_Medley(self.data[0]['token'], [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], [], 104, 30.56089, 5, 'interface') params = { 'audios': [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], 'images': [], 'latitude': 104, 'longitude': 30.56089, 'maxCount': 5, 'title': 'interface' } try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (params, response.url, response.status_code, response.text)) def test_Medley_Participant_success(self): user = UserAPI(self.baseurl) response = user.user_Medley_Participanter("100000003") try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % "100000003" print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_ModifyInfo(self): user = UserAPI(self.baseurl) response = user.user_ModifyInfo(self.data[0]['token'], self.data[0]['id'], 'sleepydog', 18782943855) args = { 'area': u'四川 成都', 'birthday': "2015-06-06", 'emotionStatus': 1, 'hasFocus': '', 'personalProfile': 'per', 'phoneNumber': '18782943855', 'portrait': '', 'sex': 1, 'userName': '******', 'id': self.data[0]['id'] } try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print '\nurl: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) def test_get_userInfo(self): user = UserAPI(self.baseurl) response = user.user_getUserInfo(self.data[0]['id']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % self.data[0]['id'] print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_get_myMedley(self): user = UserAPI(self.baseurl) response = user.user_getMyMedley(self.data[0]['token'], 100) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_get_myComplaint(self): args = {'token': self.data[0]['token'], 'status': 100} user = UserAPI(self.baseurl) response = user.user_getMyComplaint(self.data[0]['token'], 3) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_get_myRap(self): args = {'token': self.data[0]['token'], 'status': 100} user = UserAPI(self.baseurl) response = user.user_getMyRap(self.data[0]['token'], 100) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url:%s' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_get_Statistic(self): user = UserAPI(self.baseurl) response = user.user_Statistic(self.data[0]['id']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % self.data[0]['id'] print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def tearDown(self): self.assertEqual([], self.verificationErrors)
class IndexErrorTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.data = self.d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = IndexAPI(self.baseurl) def test_Recommend_type_error(self): response = self.user.index_Recommend('', '') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Recommend_arg_error(self): response = self.user.index_Recommend(0, 10) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Song_State_token_error(self): # token = self.d.login_data[0]['token'] response = self.user.index_Song_State('sdfsdfsdfewsf', 1, 20) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status']) def test_Song_State_token_null(self): # token = self.d.login_data[0]['token'] response = self.user.index_Song_State(None, 1, 20) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) def test_Hot_Rap_range_error(self): response = self.user.index_Hot_Music('raps', size=-1) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Rank_range_error(self): response = self.user.index_Rank(0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Rank_range_error2(self): response = self.user.index_Rank(1, 0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Rank_type_error(self): response = self.user.index_Rank('') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Song_state_null(self): response = self.user.index_Song_State(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) self.assertIn(u'需要token', r['msg']) def test_Song_state_page_wrong(self): response = self.user.index_Song_State(self.data[0]['token'], 0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) self.assertIn(u'取值错误', r['msg']) """def test_Homepage(self):
class LoginTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.user = LoginAPI(self.baseurl) login = testData(self.baseurl) self.udata = login.getUserData[0] self.api = MyAPI() self.result = "" # self.classifycode = ClassifyCode() def tearDown(self): print self.result def test_login_success(self): u"""登陆成功测试""" print "-----------------------------------running test_login_success----------------------------------------- " response = self.user.login_Login(self.udata['phoneNumber'], self.udata['password']) args = { "terminal": 2, 'password': self.udata['password'], 'phone': self.udata['phoneNumber'] } try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 0, 'wrong') print r['data']['user']['id'] except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) '''def test_login_password_wrong(self): u"""密码错误测试""" print "-----------------------------------running test_login_password_wrong----------------------------------------- " response = self.user.login_Login('18782943850', 'A1dAKkZ1s34ML1Y02YoGTErwpxVzh0T5kChN5y5OTcJYAqUJfwsjkQ==') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 97) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_login_arguements_wrong(self): u"""参数错误""" print "-----------------------------------running test_login_arguements_wrong----------------------------------------- " url = self.baseurl + '/api/user/login' postdata = {} response = requests.post(url, json=postdata) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(r['status'], 2) except: print 'status code:%s' % response.status_code # self.api.writeLog(sys._getframe().f_code.co_name, # 'api: %s\nstatus_code: %s' % (response.url, response.status_code)) raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_login_phone_user_not_exist(self): u"""参数错误""" print "-----------------------------------running test_login_arguements_wrong----------------------------------------- " url = self.baseurl + '/api/user/login' postdata = {"terminal": 2, 'arg1': 1, 'password': '******', 'phone': '187829438dd'} response = requests.post(url, json=postdata) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 98) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_register_phone_exists(self): u"""手机已注册""" print "-----------------------------------running test_register_phone_exists----------------------------------------- " response = self.user.register_msgCode('18109053700') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(r['status'], 111) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text))''' def test_login_Update_andriod(self): response = self.user.login_Update('andriod') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 0) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % 'andriod' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_login_Update_ios(self): response = self.user.login_Update('ios') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 0) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % 'ios' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_login_ThirdParty_QQ(self): args = { 'userName': '******', 'sex': '1', 'thirdPartyType': '2', 'token': 'UID_E5471C281EF0A4C785B31A0A58A55342' } response = self.user.login_ThirdParty(args) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 0) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) '''def test_login_ThirdParty_QQ_token_wrong(self): response = self.user.login_ThirdParty('', 'sin', 2, 0) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 4) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_forgetpwd_msgCode_no_pbone(self): response = self.user.forgetpwd_msgCode() try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(r['status'], 103) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_forgetpwd_msgCode(self): response = self.user.forgetpwd_msgCode('18782943850') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(r['status'], 0) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text))''' def test_forgetpwd(self): """忘记密码""" args = { 'phoneNumber': '18782943850', 'password': '******', "code": '0000' } response = self.user.forgetpwd_msgCode('18782943850') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) try: r = self.user.forgetpwd_modifyPwd(args) self.assertEqual(200, r.status_code) except: print 'url: %s\n' % r.url print u'状态码: %s' % r.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % r.text except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args['phoneNumber'] print u'响应内容: %s\n' % response.text '''def test_register(self):
class userErrorCheck(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.data = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() # self.err=[] def test_FollowedSong_token_null(self): '''token不传''' user = UserAPI(self.baseurl) response = user.user_FollowedSong(None) self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) # self.assertIn(u'token', r['msg']) def test_FollowedSong_token_wrong(self): '''token不传''' user = UserAPI(self.baseurl) response = user.user_FollowedSong('') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status']) # self.assertIn(u'token', r['msg']) def test_FollowedSong_type_error(self): '''传值类型错误''' user = UserAPI(self.baseurl) response = user.user_FollowedSong( random.choice(self.data)['token'], 'a') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) self.assertIn(u'page', r['msg']) def test_Recommend_null(self): user = UserAPI(self.baseurl) response = user.user_Recommend(None, None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Recommend_range_out(self): user = UserAPI(self.baseurl) response = user.user_Recommend(0, 10) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Recommend_type_error(self): user = UserAPI(self.baseurl) response = user.user_Recommend(1, 'a') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Newest_Medley_type_error(self): '''传值类型错误''' user = UserAPI(self.baseurl) response = user.user_Newest_Medley("a", 20) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Newest_Medley_range_error(self): '''传值超出范围''' user = UserAPI(self.baseurl) response = user.user_Newest_Medley(0, 10) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Newest_Medley_size_range(self): user = UserAPI(self.baseurl) response = user.user_Newest_Medley(1, 0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Newest_Complaint_type_error(self): user = UserAPI(self.baseurl) response = user.user_Newest_Complaint("", 20) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Newest_Complaint_range_error(self): user = UserAPI(self.baseurl) response = user.user_Newest_Complaint(0, 10) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Newest_Complaint_size_range(self): user = UserAPI(self.baseurl) response = user.user_Newest_Complaint(1, 0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Newest_Rap_type_error(self): user = UserAPI(self.baseurl) response = user.user_Newest_Rap("a", 20) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Newest_Rap_range_error(self): user = UserAPI(self.baseurl) response = user.user_Newest_Rap(0, 10) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Newest_Rap_null(self): user = UserAPI(self.baseurl) response = user.user_Newest_Rap(None, None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Fouce_token_null(self): #关注 user = UserAPI(self.baseurl) response = user.user_Focus(None, None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status']) def test_Fouce_wrong_null(self): user = UserAPI(self.baseurl) response = user.user_Focus(None, random.choice(self.data)['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_Fouce_wrong_id(self): user = UserAPI(self.baseurl) response = user.user_Focus('aaaaa', random.choice(self.data)['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_Focus_self(self): user = UserAPI(self.baseurl) response = user.user_Focus(self.data[0]['id'], self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(204, r['status']) def test_Focus_again(self): '''已关注用户再此关注''' user = UserAPI(self.baseurl) response = user.user_Focus(self.data[1]['id'], self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(105, r['status']) def test_cancelFocus_unfocus(self): '''取消关注未关注用户''' user = UserAPI(self.baseurl) response = user.user_cancelFocus(self.data[1]['id'], self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(105, r['status']) def test_cancelFocus_token_null(self): user = UserAPI(self.baseurl) response = user.user_cancelFocus(self.data[1]['id'], None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status']) def test_cancelFocus_id_null(self): user = UserAPI(self.baseurl) response = user.user_cancelFocus(None, self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_followedList_wrong_id(self): user = UserAPI(self.baseurl) response = user.user_followedList('aa') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_followedList_null(self): user = UserAPI(self.baseurl) response = user.user_followedList(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_FansList_null(self): user = UserAPI(self.baseurl) response = user.user_fansList(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) # self.assertEqual(len(r['data']['followers']), 0) def test_FansList_id_wrong(self): user = UserAPI(self.baseurl) response = user.user_fansList('a') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertEqual(len(r['data']['followers']), 0) def test_Violate_null(self): user = UserAPI(self.baseurl) response = user.user_Violate(None, None, None, None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_Violate_id_wrong(self): """举报id错误""" user = UserAPI(self.baseurl) response = user.user_Violate('18782943850', 'aaa', '', 'ssssasdsadfwef') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_Add_BlackList_token_null(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList('', None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) self.assertIn(u'无效的token值', r['msg']) def test_Add_BlackList_token_wrong(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList('', 'a') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(4, r['status']) self.assertIn(u'无效的token值', r['msg']) def test_Add_BlackList_id_null(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList(None, self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) self.assertIn(u'未知错误', r['msg']) def test_Add_BlackList_id_type_wrong(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList('abcd', self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) self.assertIn(u'参数uid不是', r['msg']) def test_Add_BlackList_again(self): user = UserAPI(self.baseurl) user.user_Add_BlackList(100000029, self.data[0]['token']) response = user.user_Add_BlackList(100000029, self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(100101, r['status']) self.assertIn(u'已在黑名单', r['msg']) def test_Add_BlackList_self(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList(self.data[0]['id'], self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) # self.assertIn(u'', r['msg']) def test_BlackList_token_null(self): user = UserAPI(self.baseurl) response = user.user_BlackList(None, '') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) self.assertIn(u'需要token', r['msg']) def test_BlackList_del_unexsit(self): user = UserAPI(self.baseurl) response = user.user_Del_BlackList(100000001, self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(100100, r['status']) # sql = 'select count(*) from user_blacklist where user_id= %s' % self.data[0]['id'] # num = self.db.getSingle(sql) self.assertIn(u'不在黑名单', r['msg']) def test_Participant_Medley_range_out(self): user = UserAPI(self.baseurl) response = user.user_Participant_Medley(self.data[0]['token'], 0, None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Participant_Medley_type_error(self): user = UserAPI(self.baseurl) response = user.user_Participant_Medley(self.data[0]['token'], 'a') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Create_Medley_token_null(self): user = UserAPI(self.baseurl) response = user.user_Create_Medley(None, [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], [], 104, 30.56089, 5, 'interface') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) self.assertIn(u'需要token', r['msg']) def test_Create_Medley_maxcount_zero(self): user = UserAPI(self.baseurl) response = user.user_Create_Medley(self.data[0]['token'], [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], [], 104, 30.56089, 0, 'interface') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) self.assertIn(u'参数maxCount=0取值错误', r['msg']) def test_Create_Medley_title_null(self): user = UserAPI(self.baseurl) response = user.user_Create_Medley(self.data[0]['token'], [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], [], 104, 30.56089, 5, '') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(5, r['status']) self.assertIn(u'错误', r['msg']) def test_Create_Medley_lalo_wrong(self): user = UserAPI(self.baseurl) response = user.user_Create_Medley(self.data[0]['token'], [{ 'key': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/audio/20170503134112_100001775_aa5aad11b8b0060d98a53fefda6fd3ab.m4a', 'duration': 3, 'lyric': '' }], [], -104, -30.56089, 5, '') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(112, r['status']) self.assertIn(u'错误', r['msg']) def test_Medley_Participant_id_null(self): user = UserAPI(self.baseurl) response = user.user_Medley_Participanter(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_Medley_Participant_id_type_error(self): user = UserAPI(self.baseurl) response = user.user_Medley_Participanter("10000002a") r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_get_userInfo_id_wrong(self): user = UserAPI(self.baseurl) response = user.user_getUserInfo("110001779") r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(98, r['status']) def test_ModifyInfo_id_wrong(self): user = UserAPI(self.baseurl) response = user.user_ModifyInfo(self.data[0]['token'], "110001779", 'sleepydog', 187829748888) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_ModifyInfo_token_null(self): user = UserAPI(self.baseurl) response = user.user_ModifyInfo(None, self.data[0]['id'], 'sleepydog', 187829748888) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) def test_ModifyInfo_args_miss(self): headers = { "token": self.data[0]['token'], "Host": "139.129.208.77:8080", "User-Agent": "HeiPa/1.0.1 (iPhone; iOS 9.3.5; Scale/2.00)", "Accept": "*/*", "Accept-Language": "zh-Hans-CN;q=1", "Accept-Encoding": "gzip, deflate", "Content-Type": "application/json;charset=UTF-8", "Connection": "keep-alive" } url = self.baseurl + '/api/modifyUserInfo' params = {'userName': '******', 'id': 100001775} response = requests.post(url, json=params, headers=headers) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(2, r['status']) def test_Statistic_id_wrong(self): user = UserAPI(self.baseurl) response = user.user_Statistic("110001779") r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(98, r['status']) def test_Statistic_id_null(self): user = UserAPI(self.baseurl) response = user.user_Statistic(None) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def tearDown(self): self.assertEqual([], self.verificationErrors)
class newAPITest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.user = NewAPIv1_2(self.baseurl) # self.err=[] def test_banner(self): response = self.user.banner('0') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (0, response.url, response.status_code, response.text)) '''def test_homepage(self): response = self.user.homepage() try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (0, response.url, response.status_code, response.text))''' def test_usermedley(self): # 测试查看其他用户串烧 uid = '100001773' response = self.user.medley_other(uid) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (uid, response.url, response.status_code, response.text)) def test_usercomplaint(self): uid = '100001773' response = self.user.complaint_other(uid) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (uid, response.url, response.status_code, response.text)) def test_usersolo(self): uid = '100001773' response = self.user.solo_other(uid) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (uid, response.url, response.status_code, response.text)) def test_mymedley(self): token = self.d.getUserData[0]['token'] response = self.user.medley_my(token) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (token, response.url, response.status_code, response.text)) def test_mycomplaint(self): token = self.d.getUserData[0]['token'] response = self.user.complaint_my(token) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (token, response.url, response.status_code, response.text)) def test_mysolo(self): token = self.d.getUserData[0]['token'] response = self.user.solo_my(token) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (token, response.url, response.status_code, response.text)) def test_myinfo(self): token = self.d.getUserData[0]['token'] response = self.user.my_info(token) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (token, response.url, response.status_code, response.text))
class coreTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.data = self.d.getUserData self.sidList = self.d.getSongIds self.auList = self.d.getAudios() self.cidList = self.d.getComments() self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = CoreAPI(self.baseurl) # self.err=[] def test_Compose_rap(self): audio = random.choice(self.auList) print audio response = self.user.core_Compose(self.data[0]['token'], 'rap', u'qiuwj post', [{"key":audio[1], "lyric": audio[4], "duration": audio[2]}], [], 104, 30.508, [audio[4]], 100001775) args = {'title': u'接口post', 'audios': [{"key": audio[1], "lyric": audio[4], "duration": audio[2]}], 'images': [], 'latitude': 104, 'longitude': 30.508, 'lyric': [audio[4]], 'description': '', 'userId': 100001775, 'isPublic': 1} print audio[2] try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) def test_Compose_complaint(self): audio = random.choice(self.auList) print audio response = self.user.core_Compose(self.data[0]['token'], 'complaint', u'接口post',[{"key": audio[1], "lyric": "", "duration": audio[2]}], [], 104, 30.508, [audio[4]], 100001775) args = {'title': u'接口post', 'audios': [{"key": audio[1], "lyric": "", "duration": audio[2]}], 'images': [], 'latitude': 104, 'longitude': 30.508, 'lyric': [audio[4]], 'description': '', 'userId': 100001775, 'isPublic': 1} try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) def test_RecommendLyric(self): response = self.user.core_RecommendLyrics(100) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) num = self.db.getALL('solo_recommend_lyric') self.assertEqual(len(num), len(r['data']['lyrics'])) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Listen(self): id = random.choice(self.sidList) print id sql = 'SELECT listen_count FROM song_basic_info WHERE id=%s' % id init_count =self.db.getSingle(sql) response = self.user.core_Listen(id, self.data[0]['token']) args = id try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sec_count = self.db.getSingle(sql) self.assertEqual(init_count[0]+1, sec_count[0]) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) def test_Comment_V1(self): """获取评论,按热门""" response = self.user.core_Comment_V1('100000933') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '100000933' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Comment_V1_Time(self): """获取评论,按时间""" response = self.user.core_Comment_V1('100000933', sort='hot') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '100000933' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Comment_Praise(self): """评论点赞""" response = self.user.core_Comment_Praise(self.data[0]['token'], 888, 1) args = {'token':self.data[0]['token'], 'id': 888, 'idType': 1} try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '888' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) def test_Comment_cancelPraise(self): response = self.user.core_Comment_CancelPraise(self.data[0]['token'], 888, 1) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '888' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_SongDetail_V1(self): songid = random.choice(self.sidList) response = self.user.core_SongDetail_V1(songid) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % songid print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Song_Praise(self): id = random.choice(self.sidList) print sql = 'SELECT user_id FROM song_praise_info WHERE song_id = %s' % id uids = self.db.getSet(sql) print uids uidList = [] if len(uids) > 0: for i in range(len(uids)): uidList.append(uids[i][0]) response = self.user.core_Praise(self.data[0]['token'], id) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) if self.data[0]['id'] not in uidList: self.assertEqual(0, r['status']) else: self.assertEqual(105, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % id print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) else: response = self.user.core_Praise(self.data[0]['token'], id) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % id print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Song_cancelPraise(self): sql = 'SELECT song_id FROM song_praise_info WHERE user_id = 100001775' sids = self.db.getSet(sql) print sids sidList = [] try: if len(sids)>0: for i in range(len(sids)): sidList.append(int(sids[i][0])) id = random.choice(sidList) sql = 'SELECT count(*) FROM song_praise_info WHERE song_id = %s' % id print id count = self.db.getSingle(sql) response = self.user.core_cancelPraise(self.data[0]['token'], id) self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) if count > 0: self.assertEqual(0, r['status']) else: self.assertEqual(999, r['status']) else: self.api.writeLog(sys._getframe().f_code.co_name, 'has no sid') except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % id print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Collect(self): uid = self.data[0]['id'] sid = random.choice(self.sidList) sql = 'SELECT user_id FROM song_collect_info WHERE song_id = %s' % sid uids = self.db.getSet(sql) response = self.user.core_Collect(self.data[0]['token'], sid) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) if len(uids) == 0: self.assertEqual(0, r['status']) else: uidList = [] for i in range(len(uids)): uidList.append(int(uids[i][0])) if uid in uidList: self.assertEqual(105, r['status']) else: self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % sid print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_cancelCollect(self): uid = self.data[0]['id'] sql = 'SELECT song_id FROM song_collect_info WHERE user_id = %s' % uid sids = self.db.getSet(sql) sidList = [] try: if len(sids) > 0: for i in range(len(sids)): sidList.append(int(sids[i][0])) id = random.choice(sidList) sql = 'SELECT count(*) FROM song_collect_info WHERE song_id = %s' % id print id count = self.db.getSingle(sql) response = self.user.core_cancelCollect(self.data[0]['token'], id) self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) if count > 0: self.assertEqual(0, r['status']) else: self.assertEqual(999, r['status']) else: self.api.writeLog(sys._getframe().f_code.co_name, 'user_id %s has no collection' % uid) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % id print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Mycollect(self): token = self.data[0]['token'] uid = self.data[0]['id'] response = self.user.core_MyCollection(token) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'SELECT count(*) from song_collect_info c,song_basic_info b where c.user_id = %s and c.song_id=b.id ' % uid collect = self.db.getSet(sql) print collect self.assertEqual(int(collect[0][0]), len(r['data']['songs'])) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code # print u'传递的参数是: %s\n' % songid print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Get_New_subComment(self): # token = self.data[0]['token'] response = self.user.core_Get_SubComment(912, sort='new') try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '912' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Get_Hot_subComment(self): # token = self.data[0]['token'] response = self.user.core_Get_SubComment(912) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '912' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_subComment(self): """发布子评论""" sql = 'SELECT * FROM sub_comment WHERE status=1 AND song_comment_id=912' commentset = self.db.getSet(sql) # print commentset comm = random.choice(commentset) print comm token = self.data[0]['token'] response = self.user.core_Post_SubComment(token, '912', str(comm[0]), u'图片', str(comm[2]), comm[3], []) args = {'toCommentId': str(comm[0]), 'songCommentId': 912, 'content': u'图片', 'toUserId': str(comm[2]), 'toUserName': comm[3], 'commentAsset': []} try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % args print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) '''def test_Del_subComment(self): token = self.data[0]['token'] response = self.user.core_Del_SubComment(token, 240) r = response.json() # r = self.user.core_Del_Comment(token, 240) self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) ''' def test_Del_Music(self): """删除我的歌曲""" user_id = self.data[0]['id'] token = self.data[0]['token'] sql = 'SELECT * FROM song_basic_info WHERE user_id = %s AND song_status = 1 AND audio_type=%s' % (user_id, 2) songSet = self.db.getSet(sql) ran_song = random.choice(songSet) sid = ran_song[0] print sid response = self.user.core_Del_Music(token, 'raps', sid) try: self.assertEqual(200, response.status_code) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % sid print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args:%s\napi: %s\nstatus_code: %s\ntext: %s' % (sid, response.url, response.status_code, response.text)) def test_Join_Medley(self): token = self.data[0]['token'] audioSet = self.d.getMedleyAudio() # 从数据库中抓取一组音频 medleySet = self.d.getUndoneMedley() # 从数据库主抓取一组待加入的串烧 ran_audio = random.choice(audioSet) # 随机选择一首音频 ran_medley = random.choice(medleySet) # 随机获取一首待加入的串烧 mid = ran_medley[1] print ran_audio participanter = ran_medley[5] print 'audio id is %s and medley id is %s'%(ran_audio[0], mid) audio = [{'key': ran_audio[1], 'duration': ran_audio[2], 'lyric': ran_audio[4]}] response = self.user.core_JoinMedley(token, audio, mid) args = {'audios': audio, 'songId': mid} try: r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'SELECT curr_participant_count FROM medley_song_info WHERE song_id =%s ' % mid ran_medley = self.db.getSingle(sql) cur_participanter = ran_medley[0] self.assertEqual(participanter+1, cur_participanter) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % mid print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args:%s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text)) '''def test_songComment(self): # 评论歌曲,主评论 token = self.data[0]['token'] sid = random.choice(self.sidList) # 随机获取歌曲id print sid cr = self.user.core_Comment_V1(sid) try: self.assertEqual(200, cr.status_code) comments = cr.json() comNum = len(comments['data']['comments']) content = 'comment' except: print 'get comments failed, status code wrong. code:%s' % cr.status_code raise response = self.user.core_songComment(token, sid, content) args = {'id': sid, 'content': content, 'resource': []} try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) cur_response = self.user.core_Comment_V1(sid) cur_comments = cur_response.json() cur_comNum = len(cur_comments['data']['comments']) self.assertEqual(comNum+1, cur_comNum) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'args: %s\napi: %s\nstatus_code: %s\ntext: %s' % (args, response.url, response.status_code, response.text))''' '''def test_Del_songComment(self):
class ComplextTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() # self.baseurl = 'http://139.129.208.77:9091' self.d = data_init.testData(self.baseurl) self.data = self.d.getUserData self.sidList = self.d.getSongIds self.auList = self.d.getAudios() self.cidList = self.d.getComments() self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = CoreAPI(self.baseurl) # self.err=[] def test_check_Rank_num(self): # 检查返回的歌曲是否是30首 rank = IndexAPI(self.baseurl) response = rank.index_Rank(1, 40) r = response.json() self.api.writeLog('ranking json', response.text) # self.assertEqual(30, len(r['data']['songs'])) '''def test_check_Rank_score(self): # 检查返回的歌曲排行是否是按照计算规则排序 rank = IndexAPI(self.baseurl) response = rank.index_Rank(1, 10) # self.api.writeLog(sys._getframe().f_code.co_name, response.text) r = response.json() err = 0 # self.assertEqual(30, len(r['data']['songs'])) for i in range(len(r['data']['songs'])): score = r['data']['songs'][i]['score'] praise = r['data']['songs'][i]['praiseCount'] listen = r['data']['songs'][i]['listenCount'] # repo = r['data']['songs'][i]['repost'] collect = r['data']['songs'][i]['collectCount'] s = self.api.hotWork(listen, praise, 0.0, collect) if abs(score - s) > 1.0: print "rank %s: socre is %s, compute result is %s, song id is %s" % (i+1, score, s, r['data']['songs'][i]['id']) err += 1 self.assertEqual(0, err)''' def test_Comment(self): # 评论 sid = random.choice(self.sidList) response = self.user.core_Comment_V1(sid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name + '%s' % sid, response.text) count = len(r['data']['comments']) content = u'这是接口评论' self.user.core_songComment(self.data[0]['token'], sid, content) newresponse = self.user.core_Comment_V1(sid) self.api.writeLog(sys._getframe().f_code.co_name + 'after', newresponse.text) newr = newresponse.json() newcount = len(newr['data']['comments']) self.assertEqual(newcount, count + 1) def test_delComment(self): # 删除评论 err = 0 sid = random.choice(self.sidList) self.user.core_Comment_V1(sid) content = u'这是要删除的接口评论' response = self.user.core_songComment(self.data[0]['token'], sid, content) r = response.json() cid = r['data']['id'] # 获取评论id self.user.core_Del_Comment(self.data[0]['token'], cid) newr = self.user.core_Comment_V1(sid) newres = newr.json() for i in range(len(newres['data']['comments'])): if cid == newres['data']['comments'][i]['id']: err = 1 self.assertEqual(0, err) def test_Add_BlackList_success(self): user = UserAPI(self.baseurl) response = user.user_Add_BlackList('100000001', self.data[0]['token']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'select * from user_blacklist where user_id= %s and black_user_id= %s' % ( self.data[0]['id'], 100000001) data = self.db.getSingle(sql) if len(data) == 0: raise AssertionError('insert into database failed') user.user_Del_BlackList('100000001', self.data[0]['token']) except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '100000001' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Focus_success(self): """关注成功后取消关注""" user = UserAPI(self.baseurl) response = user.user_Focus('100001774', self.data[0]['token']) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) try: self.assertEqual(0, r['status']) r2 = user.user_cancelFocus('100001774', self.data[0]['token']) except: print "test_Focus_mix" print 'url: %s\n' % r2.url print u'状态码: %s' % r2.status_code print u'传递的参数是: %s\n' % '100001774' print u'响应内容: %s\n' % r2.text except: print 'url: %s\n' % response.url print u'状态码: %s' % response.status_code print u'传递的参数是: %s\n' % '100001774' print u'响应内容: %s\n' % response.text raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text))
class discoverTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.data = self.d.getUserData self.sidList = self.d.getSongIds self.auList = self.d.getAudios() self.cidList = self.d.getComments() self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = DiscoverAPI(self.baseurl) # self.err=[] def test_Latest(self): response = self.user.discover_Latest() r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Followed(self): response = self.user.discover_Followed() r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Newest_Medley_success(self): # 最新串烧 response = self.user.user_Newest_Medley(1, 10) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code # self.api.writeLog(sys._getframe().f_code.co_name, # 'api: %s\nstatus_code: %s' % (response.url, response.status_code)) raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Newest_Complaint_success(self): response = self.user.user_Newest_Complaint(1, 10) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) def test_Newest_Rap_success(self): response = self.user.user_Newest_Rap(1, 10) try: self.assertEqual(200, response.status_code, 'status code:%s' % response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog(sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % ( response.url, response.status_code, response.text)) """
class IndexTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() d = data_init.testData(self.baseurl) self.d = d.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = IndexAPI(self.baseurl) def test_Recommend(self): response = self.user.index_Recommend(1, 20) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Song_State(self): token = self.d[0]['token'] response = self.user.index_Song_State(token, 1, 20) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Hot_Rap(self): response = self.user.index_Hot_Music('raps') try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Hot_Complaint(self): response = self.user.index_Hot_Music('complaints') try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Hot_Medley(self): response = self.user.index_Hot_Music('medleys') try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Rank(self): response = self.user.index_Rank() try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_Homepage(self): response = self.user.index_Homepage() try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text))
class ShareTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.s = data_init.testData(self.baseurl) self.d = self.s.getUserData self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = ShareAPI(self.baseurl) def test_ShareList(self): token = self.d[0]['token'] id = self.d[0]['id'] response = self.user.share_ShareList(token, id) try: self.assertEqual(200, response.status_code) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) """def test_ShareList_token_null(self): # token = self.d.login_dat[0]['token'] id = self.d.login_data[0]['id'] response = self.user.share_ShareList(None, id) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) def test_ShareList_id_wrong(self): token = self.d.login_data[0]['token'] # id = self.d.login_data[0]['id'] response = self.user.share_ShareList(None, 'adfasdf') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status'])""" def test_Share_Inner(self): sidList = self.s.getSongIds sid = random.choice(sidList) token = self.d[0]['token'] share_reason = 'share reason' response = self.user.share_Share_Inner(token, sid, share_reason) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) """def test_Share_Inner_sid_wrong(self):
class coreErrorTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() # self.baseurl = 'http://139.129.208.77:9091' self.d = data_init.testData() self.data = self.d.getUserData self.sidList = self.d.getSongIds self.auList = self.d.getAudios() self.cidList = self.d.getComments() self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = CoreAPI(self.baseurl) # self.err=[] def test_Compose_rap_token_null(self): audio = random.choice(self.auList) print audio response = self.user.core_Compose(None, 'rap', u'接口post', [{ "key": "http://user-storage.oss-cn-qingdao.aliyuncs.com/song/20170503171829_100000930_61dc8cb9345ba2c4b1eb04b79ab3a420.mp3", "lyric": audio[4], "duration": audio[2] }], [], 104, 30.508, [audio[4]], 100001775) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(3, r['status']) def test_Compose_rap_longitude_wrong(self): audio = random.choice(self.auList) print audio response = self.user.core_Compose( self.data[0]['token'], 'rap', u'接口post', [{ "key": "http://user-storage.oss-cn-qingdao.aliyuncs.com/song/20170503171829_100000930_61dc8cb9345ba2c4b1eb04b79ab3a420.mp3", "lyric": audio[4], "duration": audio[2] }], [], 's', 30.508, [audio[4]], 100001775) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(112, r['status']) def test_Compose_rap_id_wrong(self): audio = random.choice(self.auList) print audio response = self.user.core_Compose( self.data[0]['token'], 'rap', u'接口post', [{ "key": "http://user-storage.oss-cn-qingdao.aliyuncs.com/song/20170503171829_100000930_61dc8cb9345ba2c4b1eb04b79ab3a420.mp3", "lyric": audio[4], "duration": audio[2] }], [], 's', 30.508, [audio[4]], 100001776) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(999, r['status']) def test_RecommendLyric_range_out(self): response = self.user.core_RecommendLyrics(-5) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(110, r['status']) def test_RecommendLyric_type_out(self): response = self.user.core_RecommendLyrics(1.666) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(116, r['status']) def test_Listen(self): id = random.choice(self.sidList) print id sql = 'SELECT listen_count FROM song_basic_info WHERE id=%s' % id init_count = self.db.getSingle(sql) response = self.user.core_Listen(id, self.data[0]['token']) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sec_count = self.db.getSingle(sql) self.assertEqual(init_count[0] + 1, sec_count[0]) def test_Comment_V1(self): '''获取评论,按热门''' response = self.user.core_Comment_V1(100000933) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Comment_V1_Time(self): '''获取评论,按时间''' response = self.user.core_Comment_V1(100000933, sort=0) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Comment_Praise(self): '''评论点赞''' response = self.user.core_Comment_Praise(self.data[0]['token'], 888, 1) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) # num = self.db.getALL('solo_recommend_lyric') # self.assertEqual(len(num), len(r['data']['lyrics'])) def test_Comment_cancelPraise(self): response = self.user.core_Comment_CancelPraise(self.data[0]['token'], 888, 1) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_SongDetail_V1(self): songid = random.choice(self.sidList) response = self.user.core_SongDetail_V1(songid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Song_Praise(self): id = random.choice(self.sidList) print sql = 'SELECT user_id FROM song_praise_info WHERE song_id = %s' % id uids = self.db.getSet(sql) print uids uidList = [] if len(uids) > 0: for i in range(len(uids)): uidList.append(uids[i][0]) response = self.user.core_Praise(self.data[0]['token'], id) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) if self.data[0]['id'] not in uidList: self.assertEqual(0, r['status']) else: self.assertEqual(105, r['status']) else: response = self.user.core_Praise(self.data[0]['token'], id) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Song_cancelPraise(self): sql = 'SELECT song_id FROM song_praise_info WHERE user_id = 100001775' sids = self.db.getSet(sql) print sids sidList = [] if len(sids) > 0: for i in range(len(sids)): sidList.append(int(sids[i][0])) id = random.choice(sidList) sql = 'SELECT count(*) FROM song_praise_info WHERE song_id = %s' % id print id count = self.db.getSingle(sql) response = self.user.core_cancelPraise(self.data[0]['token'], id) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) if count > 0: self.assertEqual(0, r['status']) else: self.assertEqual(999, r['status']) else: self.api.writeLog(sys._getframe().f_code.co_name, 'has no sid') def test_Collect(self): uid = self.data[0]['id'] sid = random.choice(self.sidList) sql = 'SELECT user_id FROM song_collect_info WHERE song_id = %s' % sid uids = self.db.getSet(sql) response = self.user.core_Collect(self.data[0]['token'], sid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) if len(uids) == 0: self.assertEqual(0, r['status']) else: uidList = [] for i in range(len(uids)): uidList.append(int(uids[i][0])) if uid in uidList: self.assertEqual(105, r['status']) else: self.assertEqual(0, r['status']) def test_cancelCollect(self): uid = self.data[0]['id'] sql = 'SELECT song_id FROM song_collect_info WHERE user_id = %s' % uid sids = self.db.getSet(sql) sidList = [] if len(sids) > 0: for i in range(len(sids)): sidList.append(int(sids[i][0])) id = random.choice(sidList) sql = 'SELECT count(*) FROM song_collect_info WHERE song_id = %s' % id print id count = self.db.getSingle(sql) response = self.user.core_cancelCollect(self.data[0]['token'], id) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) if count > 0: self.assertEqual(0, r['status']) else: self.assertEqual(999, r['status']) else: self.api.writeLog(sys._getframe().f_code.co_name, 'user_id %s has no collection' % uid) def test_Mycollect(self): token = self.data[0]['token'] uid = self.data[0]['id'] response = self.user.core_MyCollection(token) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'SELECT count(*) from song_collect_info c,song_basic_info b where c.user_id = %s and c.song_id=b.id and b.song_status=1' % uid collect = self.db.getSet(sql) print collect self.assertEqual(int(collect[0][0]), len(r['data']['songs'])) def test_Get_New_subComment(self): '''获取子评论''' # token = self.data[0]['token'] response = self.user.core_Get_SubComment(912, sort='new') r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Get_Hot_subComment(self): '''获取子评论''' token = self.data[0]['token'] response = self.user.core_Post_SubComment( token, 906, '', '图片', '', '', [{ 'resourceType': 1, 'url': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/img/20170505025853_100001811_88bf6884e7d205dbabd79965393194ca.png' }]) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_subComment(self): '''发布子评论''' token = self.data[0]['token'] response = self.user.core_Post_SubComment( token, 912, '', '图片', '', '', [{ 'resourceType': 1, 'url': 'http://user-storage.oss-cn-qingdao.aliyuncs.com/img/20170505025853_100001811_88bf6884e7d205dbabd79965393194ca.png' }]) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Del_subComment(self): token = self.data[0]['token'] id = self.data[0]['id'] sql = 'SELECT id FROM sub_comment WHERE user_id = %s AND status = 1' % id subids = self.db.getSet(sql) subid = random.choice(subids) response = self.user.core_Del_SubComment(token, subid[0]) r = response.json() # r = self.user.core_Del_Comment(token, 240) self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Del_Music(self): '''删除我的歌曲''' user_id = self.data[0]['id'] token = self.data[0]['token'] sql = 'SELECT * FROM song_basic_info WHERE user_id = %s AND song_status = 1 AND audio_type=%s' % ( user_id, 2) songSet = self.db.getSet(sql) ran_song = random.choice(songSet) sid = ran_song[0] print sid response = self.user.core_Del_Music(token, 'raps', sid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) def test_Join_Medley(self): token = self.data[0]['token'] audioSet = self.d.getMedleyAudio() medleySet = self.d.getUndoneMedley() ran_audio = random.choice(audioSet) ran_medley = random.choice(medleySet) mid = ran_medley[1] print ran_audio participanter = ran_medley[5] print 'audio id is %s and medley id is %s' % (ran_audio[0], mid) audio = [{ 'key': ran_audio[1], 'duration': ran_audio[2], 'lyric': ran_audio[4] }] response = self.user.core_JoinMedley(token, audio, mid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) sql = 'SELECT curr_participant_count FROM medley_song_info WHERE song_id =%s ' % mid ran_medley = self.db.getSingle(sql) cur_participanter = ran_medley[0] self.assertEqual(participanter + 1, cur_participanter) def test_songComment(self): token = self.data[0]['token'] sid = random.choice(self.sidList) print sid comments = self.user.core_Comment_V1(sid).json() comNum = len(comments['data']['comments']) content = 'comment' response = self.user.core_songComment(token, sid, content) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) cur_comments = self.user.core_Comment_V1(sid).json() cur_comNum = len(cur_comments['data']['comments']) self.assertEqual(comNum + 1, cur_comNum) def test_Del_songComment(self): token = self.data[0]['token'] uid = self.data[0]['id'] sql = 'SELECT id FROM song_comment_info WHERE user_id=%s AND status = 0' % uid commentSet = self.db.getSet(sql) cid = random.choice(commentSet)[0] #随机获取评论id response = self.user.core_Del_Comment(token, cid) r = response.json() self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) cur_sql = 'SELECT status FROM song_comment_info WHERE id=%s ' % uid comment_status = self.db.excuteSQL(cur_sql) self.assertEqual(99, comment_status)
class SearchTest(unittest.TestCase): def setUp(self): cfg = RunConfig() self.baseurl = cfg.get_base_url() self.d = data_init.testData(self.baseurl) self.verificationErrors = [] self.accept_next_alert = True self.api = MyAPI() self.db = dbManual.DBManual() self.user = SearchAPI(self.baseurl) def test_search_Song_CN(self): keyword = u'木头人' # sql = 'SELECT COUNT(*) FROM song_basic_info where song_name LIKE "%' + keyword.encode('utf-8') + '%" and song_status=1' # num = self.db.excuteSQL(sql) # print num response = self.user.search_Song(keyword) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertNotEqual(0, len(r['data']['songs'])) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_search_Song_EN(self): keyword = u'oo' # sql = 'SELECT COUNT(*) FROM song_basic_info where song_name LIKE "%' + keyword + '%"and song_status=1' # num = self.db.excuteSQL(sql) # print num response = self.user.search_Song(keyword) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertNotEqual(0, len(r['data']['songs'])) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_search_Song_DIG(self): keyword = u'11' # sql = 'SELECT COUNT(*) FROM song_basic_info where song_name LIKE "%' + keyword + '%" and song_status=1' # num = self.db.getSingle(sql) # print num response = self.user.search_Song(keyword) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertNotEqual(0, len(r['data']['songs'])) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_search_User_CN(self): keyword = u'罗亮' sql = 'SELECT COUNT(*) FROM user_profile_basic where user_name LIKE "%' + keyword.encode( 'utf-8') + '%"' num = self.db.getSingle(sql) print num response = self.user.search_User(keyword) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertEqual(num[0], len(r['data']['users'])) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_search_User_EN(self): keyword = u'sleepyhead' sql = 'SELECT COUNT(*) FROM user_profile_basic where user_name LIKE "%' + keyword + '%"' num = self.db.getSingle(sql) response = self.user.search_User(keyword) try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) self.assertEqual(num[0], len(r['data']['users'])) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text)) def test_search_Hot(self): response = self.user.search_Hot() try: self.assertEqual(200, response.status_code) r = response.json() # self.api.writeLog(sys._getframe().f_code.co_name, response.text) self.assertEqual(0, r['status']) except: print 'status code:%s' % response.status_code raise finally: self.api.writeLog( sys._getframe().f_code.co_name, 'api: %s\nstatus_code: %s\ntext: %s' % (response.url, response.status_code, response.text))