def testSendGift(self, test_input, expected): sqlList = [] sqlList.append("update remain_points set remain_points = " + str(test_input[2]) + " where identity_id = '" + idlist[2] + "'") dbConnect.dbSetting(test_parameter['db'], sqlList) if expected == 2: sqlStr = "select experience, identity_id from user_experience where identity_id in ('" + idlist[ 0] + "', '" + idlist[2] + "') order by identity_id" bfExperience = dbConnect.dbQuery(test_parameter['db'], sqlStr) header['X-Auth-Token'] = test_input[0] header['X-Auth-Nonce'] = test_input[1] apiName = '/api/v2/identity/sendGift' body = {'giftId': test_input[3], 'postId': test_input[4]} res = api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) #pprint(json.loads(res.text)) assert res.status_code // 100 == expected if expected == 2: restext = json.loads(res.text) self.postGetTotalPoint += 1000 assert restext['data']['pointLeft'] == 9000 assert restext['data']['postPoint'] == self.postGetTotalPoint sqlStr = "select experience, identity_id from user_experience where identity_id in ('" + idlist[ 0] + "', '" + idlist[2] + "') order by identity_id" afExperience = dbConnect.dbQuery(test_parameter['db'], sqlStr) for i in range(2): if bfExperience[i][1] == idlist[0]: assert afExperience[i][0] - bfExperience[i][0] == 1000 else: assert afExperience[i][0] - bfExperience[i][0] == 3000
def testRegisterToActive(self, condition, expected): url = '/api/v2/identity/register/email/activate' tempToken, actCode = self.getActiveCode() body = { "tmpToken": tempToken, "activateCode": actCode, "pushToken": "emailRegrjhjayegrkldfkhgdkfasd" } if condition == 'tokenWrong': body["tmpToken"] = "wJalrXUtnFEMI..." elif condition == 'codeWrong': body["activateCode"] = "214520" elif condition == 'wihtoutPushToken': body["pushToken"] = "" elif condition == 'expired': sqlStr = "select max(id) from identity_email_register_history" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sqlList = [ "update identity_email_register_history set expires_in = 1 where id = " + str(result[0][0]) ] dbConnect.dbSetting(test_parameter['db'], sqlList) time.sleep(2) pprint(condition) res = api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body) assert res.status_code // 100 == expected if res.status_code // 100 == 2: restext = json.loads(res.text) sqlStr = "select nickname from identity where token = '" + restext[ 'data']['token'] + "' and nonce = '" + restext['data'][ 'nonce'] + "'" record = dbConnect.dbQuery(test_parameter['db'], sqlStr) #pprint(record) assert '初樂用戶 ' in record[0][0]
def createAccountByEmail(): sqlStr = "select id from identity where login_id = '*****@*****.**'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sqlStr = "update identity set login_id = '" + str(int(time.time())) + "' where id = '" + result[0] + "'" dbConnect.dbSetting(test_parameter['db'], [sqlStr]) head = {'Content-Type': 'application/json'} url = '/api/v2/identity/register/email/send' body = { 'email': '*****@*****.**', 'password': '******', 'pushToken': 'emailRegrjhjayegrkldfkhgdkfasd' } res = api.apiFunction(test_parameter['prefix'], head, url, 'post', body) restext = json.loads(res.text) tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_email_register_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] url = '/api/v2/identity/register/email/activate' body = { "tmpToken": tempToken, "activateCode": actCode, "pushToken": "emailRegrjhjayegrkldfkhgdkfasd" } api.apiFunction(test_parameter['prefix'], head, url, 'post', body) sqlStr = "select id from identity where login_id = '*****@*****.**'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) print('email註冊的uid(%s)'%result[0][0]) return result[0][0]
def getActiveCode(self, bindMail): url = '/api/v2/identity/binding/email/send' body = {'email': bindMail} api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body) sqlStr = "select max(id) from identity_email_bind_history" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sqlStr = "select activate_code from identity_email_bind_history where id = " + str( result[0][0]) result = dbConnect.dbQuery(test_parameter['db'], sqlStr) #pprint(result) return result[0][0]
def testlineFlow(self, condition, expected): url = '/api/v2/3rdParty/line/verify' #print('condition=%s'%condition) if condition == 'firstLogin': idToken, accessToken = (lineLogin.line_login()) body = {'accessToken': accessToken, 'idToken': idToken} self.auth.append({'idToken': idToken, 'accessToken': accessToken}) elif condition == 'secondLogin': idToken, accessToken = (lineLogin.line_login()) body = {'accessToken': accessToken, 'idToken': idToken} self.auth.append({'idToken': idToken, 'accessToken': accessToken}) elif condition == 'accToken_Wrong': body = { 'accessToken': 'sUpdewDer123Oi', 'idToken': self.auth[1]['idToken'] } elif condition == 'idToken_Wrong': body = { 'accessToken': self.auth[1]['accessToken'], 'idToken': 'aBcdoeiDp' } elif condition == 'suspend': sqlStr = "select identity_id from identity_third_party where remote_user_id = 'U28ec1317311a7e4da93b5da156a376f4'" record = dbConnect.dbQuery(test_parameter['db'], sqlStr) header['X-Auth-Token'] = test_parameter['backend_token'] header['X-Auth-Nonce'] = test_parameter['backend_nonce'] self.userId = record[0][0] api.change_user_mode(test_parameter['prefix'], self.userId, -2, header) body = { 'accessToken': self.auth[1]['accessToken'], 'idToken': self.auth[1]['idToken'] } res = api.apiFunction(test_parameter['prefix'], {}, url, 'post', body) assert res.status_code // 100 == expected if condition == 'firstLogin': restext = json.loads(res.text) assert restext['data']['isNew'] == 1 assert 'nonce' in restext['data'] assert 'token' in restext['data'] assert 'idToken' in restext['data'] restext = json.loads(res.text) sqlStr = "select nickname from identity where token = '" + restext[ 'data']['token'] + "' and nonce = '" + restext['data'][ 'nonce'] + "'" record = dbConnect.dbQuery(test_parameter['db'], sqlStr) assert '初樂用戶 ' in record[0][0] time.sleep(10) if condition == 'secondLogin': restext = json.loads(res.text) assert restext['data']['isNew'] == 0 assert 'nonce' in restext['data'] assert 'token' in restext['data'] assert 'idToken' in restext['data']
def sendPostGift(timeList, today, yesterday, thisWeek, thisMonth, lastMonth): sqlStr = "select id, point from gift where category_id = 108 and status = 1" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) giftId = result[0][0] point = result[0][1] photo.createPhoto(test_parameter['broadcaster_token'], test_parameter['broadcaster_nonce'], test_parameter['prefix'], test_parameter['photo_url'], 3) photoId = photo.getPhotoList(test_parameter['broadcaster_token'], test_parameter['broadcaster_nonce'], test_parameter['prefix'], idList[2]) photo.sendPhotoGift(test_parameter['user1_token'], test_parameter['user1_nonce'], test_parameter['prefix'], photoId[0], giftId) if idList[1] in today: today[idList[1]] += point else: today[idList[1]] = point if idList[1] in thisMonth: thisMonth[idList[1]] += point else: thisMonth[idList[1]] = point if idList[1] in thisWeek: thisWeek[idList[1]] += point else: thisWeek[idList[1]] = point
def test_changeRole(self, token, nonce, idInfo, role, experience, expected): ori_experience = 0 if ori_experience != experience: sqlList = [ "update user_experience set experience = " + str(experience) + " where identity_id = '" + idInfo[0] + "'" ] dbConnect.dbSetting(test_parameter['db'], sqlList) ori_experience = experience header['X-Auth-Token'] = test_parameter[token] header['X-Auth-Nonce'] = test_parameter[nonce] url = '/api/v2/backend/user/role' body = {'ids': idInfo, 'role': role} res = api.apiFunction(test_parameter['prefix'], header, url, 'patch', body) if type(idInfo) == list: id = idInfo[0] else: id = idInfo sqlStr = "select count(*) from identity_tag_association where identity_id = '" + id + "' and tag_id = 6" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) print('dbcount=%d' % result[0][0]) assert res.status_code // 100 == expected if role == 4 and experience < 4577455: assert result[0][0] == 1 else: assert result[0][0] == 0
def testBKForbidden(self, scenario, token, nonce, isReset, funName, way, id, words, item, page, totalCount, expected): self.reset() if isReset else None restext = {} fundic = { 'add': {'apiName': '/api/v2/backend/forbidden', 'body': {'word': words}}, 'edit': {'apiName': '/api/v2/backend/forbidden', 'body': {'id': id, 'word': words}}, 'all': {'apiName': '/api/v2/backend/forbidden/list?' + 'item=' + str(item) + '&page=' + str(page), 'body': None}, 'single': {'apiName': '/api/v2/backend/forbidden/' + str(id), 'body': None}, 'del': {'apiName': '/api/v2/backend/forbidden/' + str(id), 'body': None} } header['X-Auth-Token'] = test_parameter[token] header['X-Auth-Nonce'] = test_parameter[nonce] res = api.apiFunction(test_parameter['prefix'], header, fundic[funName]['apiName'], way, fundic[funName]['body']) assert res.status_code // 100 == expected if expected == 2: global fid fid += 1 restext = json.loads(res.text) assert restext['Status'] == 'Ok' assert restext['Message'] == 'SUCCESS' compareDic = { 'add': [funName, '', fid, words, 0], 'edit': [funName, '', id, words, 0], 'all': [funName, restext, abs(page - 3) + 1, self.words[abs(page - 3)], totalCount], 'single':[funName, restext, id, self.words[id - 1], 0] } if funName != 'del': #pprint(restext) self.compareResult(compareDic[funName][0], compareDic[funName][1], compareDic[funName][2], compareDic[funName][3], compareDic[funName][4]) else: sqlStr = "select count(*) from forbidden where id = " + str(id) + " and delete_at <> ''" record = dbConnect.dbQuery(test_parameter['db'], sqlStr) assert record[0][0] == 1
def sendGiftToPost(masterid, userid): sql = "select g.id, g.point from gift g join gift_category gc on category_id = gc.id where gc.type = 'post_gif'" dbResult = dbConnect.dbQuery(test_parameter, sql) giftId = dbResult[0][0] giftPoint = dbResult[0][1] result = api.user_login(test_parameter['prefix'], 'broadcaster100', test_parameter['user_pass']) header['X-Auth-Token'] = result['token'] header['X-Auth-Nonce'] = result['nonce'] apiName = '/api/v2/liveMaster/photoPost' body = {"photoPath": test_parameter['photo_url'], "content": "動態送禮。。測試中"} api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) apiName = '/api/v2/liveMaster/' + masterid + '/photoPost?item=5&page=1' res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) restext = json.loads(res.text) postId = restext['data'][0]['id'] result = api.user_login(test_parameter['prefix'], 'track0077', test_parameter['user_pass']) header['X-Auth-Token'] = result['token'] header['X-Auth-Nonce'] = result['nonce'] apiName = '/api/v2/identity/sendGift' body = {'giftId': giftId, 'postId': postId} api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) totalPoint[userid] += giftPoint totalMaster[masterid] += giftPoint newMaster[masterid] += giftPoint
def sendPostGift(self): sql = "select g.id, g.name, g.point from gift_v2 g join gift_category_v2 gc on category_id = gc.id where gc.type = 'post_gift' and g.point > 0" dbResult = dbConnect.dbQuery(test_parameter['db'], sql) giftId = dbResult[0][0] giftName = dbResult[0][1] giftPoint = dbResult[0][2] header['X-Auth-Token'] = test_parameter['broadcaster2_token'] header['X-Auth-Nonce'] = test_parameter['broadcaster2_nonce'] apiName = '/api/v2/liveMaster/photoPost' body = { "photoPath": test_parameter['photo_url'], "content": "動態送禮。。測試中" } api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) apiName = '/api/v2/liveMaster/' + idlist[4] + '/photoPost?item=5&page=1' res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) restext = json.loads(res.text) postId = restext['data'][0]['id'] apiName = '/api/v2/identity/sendGift' header['X-Auth-Token'] = test_parameter['user1_token'] header['X-Auth-Nonce'] = test_parameter['user1_nonce'] body = {'giftId': giftId, 'postId': postId} api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) today1List.append({ 'name': giftName, 'point': giftPoint, 'createAt': int(time.time()) })
def testLiveMasertSendOver10_giver(self): # 直播主每天最多僅發10筆給送禮的用戶 valuesList = [] sendCount = 0 apiName = '/api/v2/liveMaster/instantMessage' header['X-Auth-Token'] = test_parameter['broadcaster_token'] header['X-Auth-Nonce'] = test_parameter['broadcaster_nonce'] content = '哈囉,你好。謝謝你送的禮物 ' sqlStr = "select count(*) from quota_log where permission = 'gift_givers_to_send_im' and user_id = '" + idList[ 0] + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sendCount = int(result[0][0]) for i in range(10, 18): valuesList.extend([ userList[i], 'giftGiversToSendIM', 'text', content, '', '', '' ]) body = self.createBody(valuesList) res = api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) if sendCount < 10: sendCount += 1 assert res.status_code // 100 == 2 else: assert res.status_code // 100 == 4 break valuesList.clear()
def testMailCreateTime(self, regEmail, PWD, expected): url = '/api/v2/identity/binding/email/send' for i in range(len(regEmail)): sqlList = [] createTime = '' body = {'email': regEmail[i]} res = api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body) restext = json.loads(res.text) pprint(restext) assert res.status_code // 100 == expected[i] if i == 0: createTime = (datetime.today() - timedelta(days=8 + datetime.today().weekday()) - timedelta(hours=8)).strftime('%Y-%m-%d 16:00:00') elif i == 1: createTime = (datetime.today() - timedelta(days=2 + datetime.today().weekday()) - timedelta(hours=8)).strftime('%Y-%m-%d 15:59:59') elif i == 2: createTime = (datetime.today() - timedelta(days=2 + datetime.today().weekday()) - timedelta(hours=8)).strftime('%Y-%m-%d 16:00:00') if len(createTime) > 0: sqlStr = "select max(id) from identity_email_bind_history" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sqlList = [ "update identity_email_bind_history set created_at = '" + createTime + "' where id = " + str(result[0][0]) ] dbConnect.dbSetting(test_parameter['db'], sqlList)
def getTestData(funName): sqlStr = "select max(id) from voice_chat_room where status = 1" result = dbConnect.dbQuery(DB, sqlStr) vRoom = result[0][0] testData = [] if funName == 'admin': #scenario, account, method, roomId, admin, adminList, expected testData = [ ('僅房主可以新增管理員資料', 'broadcaster011', 'post', vRoom, 'broadcaster012', ['broadcaster012'],200), ('新增的管理員資料重複', 'broadcaster011', 'post', vRoom, 'broadcaster012', ['broadcaster012'], 400), ('一般user不可以新增管理員資料', 'track0010', 'post', vRoom, 'broadcaster013', ['broadcaster012'], 403), ('管理員不可以新增管理員資料', 'broadcaster012', 'post', vRoom, 'broadcaster013', ['broadcaster012'], 403), ('經營管理者不可以新增管理員資料', 'tl-lisa', 'post', vRoom, 'broadcaster013', ['broadcaster012'], 403), ('官方場控不可以新增管理員資料', 'lv000', 'post', vRoom, 'broadcaster013', ['broadcaster012'], 403), ('房間不存在卻要加管理員', 'broadcaster011', 'post', vRoom + 1, 'broadcaster013', ['broadcaster012'], 404), ('經營管理者不可為管理員', 'broadcaster011', 'post', vRoom, 'tl-lisa',['broadcaster012'], 404), ('官方場控不可為管理員', 'broadcaster011', 'post', vRoom, 'lv000', ['broadcaster012'], 404), ('一般user不可為管理員', 'broadcaster011', 'post', vRoom, 'track0010', ['broadcaster012'], 404), ('房主不可為管理員', 'broadcaster011', 'post', vRoom, 'broadcaster011', ['broadcaster012'], 400), ('他房房主可為管理員', 'broadcaster011', 'post', vRoom, 'broadcaster010', ['broadcaster010', 'broadcaster012'], 200), ('他房房主不可新增本房管理員', 'broadcaster010', 'post', vRoom, 'broadcaster013', ['broadcaster010', 'broadcaster012'], 403), ('非本房房主不可刪除本房管理員', 'broadcaster010', 'delete', vRoom, 'broadcaster010', ['broadcaster010', 'broadcaster012'], 403), ('經營管理者不可刪除本房管理員', 'tl-lisa', 'delete', vRoom, 'broadcaster010', ['broadcaster010', 'broadcaster012'], 403), ('官方場控不可刪除本房管理員', 'lv000', 'delete', vRoom, 'broadcaster010', ['broadcaster010', 'broadcaster012'], 403), ('刪除不存在的管理員', 'broadcaster011', 'delete', vRoom, 'broadcaster010', ['broadcaster010', 'broadcaster012'], 404), ('刪除存在的管理員', 'broadcaster011', 'delete', vRoom, 'broadcaster010', ['broadcaster012'], 200) ] elif funName == 'edit': #scenario, account, roomId, key, value, payload, expected testData = [ ('僅房主可以更新該房的訊息(title)', 'broadcaster011', vRoom, 'title', 'update voice room title', {'password': '******'}, 200), ('僅房主可以更新該房的訊息(description)', 'broadcaster011', vRoom, 'description', 'owner update voice room description', {'password': '******'},200), ('僅房主可以更新該房的訊息(password=!@123a)', 'broadcaster011', vRoom, 'password', '!@123a', {'password': '******'}, 200), ('僅房主可以更新該房的訊息(password=空白)', 'broadcaster011', vRoom, 'password', '', {}, 200), ('僅房主可以更新該房的訊息(password=None)', 'broadcaster011', vRoom, 'password', None, {}, 200), ('該房的管理員可以更新(title)', 'broadcaster012', vRoom, 'title', '管理員修改聲聊房的標題123', {}, 200), ('該房的管理員可以更新(description)', 'broadcaster012', vRoom, 'description', '管理員修改聲聊房的描述123', {}, 200), ('該房的管理員可以更新(password)', 'broadcaster012', vRoom, 'password', 'qq123a', {'password': '******'}, 200), ('原本該房的管理員,已被移除則不可以更新(title)', 'broadcaster010', vRoom, 'title', '1房房主修改2房的標題123', {}, 403), ('原本該房的管理員,已被移除則不可以更新(description)', 'broadcaster010', vRoom, 'description', '1房房主修改2房的描述123', {}, 403), ('原本該房的管理員,已被移除則不可以更新(password)', 'broadcaster010', vRoom, 'password', 'bb123a', {'password': '******'}, 403), ('原本該房的管理員,已變成一般用戶則不可以更新(title)', 'broadcaster010', vRoom, 'title', '1房房主修改2房的標題123', {}, 403), ('原本該房的管理員,已變成一般用戶則不可以更新(description)', 'broadcaster010', vRoom, 'description', '1房房主修改2房的描述123', {}, 403), ('原本該房的管理員,已變成一般用戶則不可以更新(password)', 'broadcaster010', vRoom, 'password', 'bb123a', {'password': '******'}, 403), ('他房的房主不可以更新(title)', 'broadcaster010', vRoom, 'title', '1房房主修改2房的標題123', {}, 403), ('他房的房主不可以更新(description)', 'broadcaster010', vRoom, 'description', '1房房主修改2房的描述123', {}, 403), ('他房的房主不可以更新(password)', 'broadcaster010', vRoom, 'password', 'bb123a', {'password': '******'}, 403), ('經營管理者不可以更新(title)', 'tl-lisa', vRoom, 'title', '修改聲聊房的title', {}, 403), ('官方場控不可以更新(title)', 'lv000', vRoom, 'title', '修改聲聊房的title', {}, 403), ('使用者不可以更新(title)', 'track0010', vRoom, 'title', '修改聲聊房的title', {}, 403), ('經營管理者不可以更新(description)', 'tl-lisa', vRoom, 'description', '修改聲聊房的描述', {}, 403), ('官方場控不可以更新(description)', 'lv000', vRoom, 'description', '修改聲聊房的描述', {}, 403), ('使用者不可以更新(description)', 'track0010', vRoom, 'description', 'user cannot update description', {}, 403) ] return testData
def loginByLine(): url = '/api/v2/3rdParty/line/verify' idToken, accessToken = (lineLogin.line_login()) body = { 'accessToken': accessToken, 'idToken': idToken } api.apiFunction(test_parameter['prefix'], {}, url, 'post', body) sqlStr = "select identity_id from identity_third_party" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) return result[0][0]
def getExperience(self, idInfo): sqlStr = "select identity_id, experience from user_experience where identity_id in ('" for i in range(len(idInfo)): sqlStr += idInfo[i] if len(idInfo) - i == 1: sqlStr += "')" else: sqlStr += "', '" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) #pprint(result) return result
def runActiveCode(self, bindMail): sqlStr = "select activate_code from identity_email_bind_history where id = (select max(id) from identity_email_bind_history)" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] url = '/api/v2/identity/binding/email/activate' body = { "source": "advance", "email": bindMail, "password": '******', "activateCode": actCode } api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body)
def getActiveCode(self): urlName = '/api/v2/identity/password/send' body = {'identifier': '*****@*****.**', 'source': 'email'} res = api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, urlName, 'post', body) restext = json.loads(res.text) tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_pwd_reset_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] self.info.append({"tmpToken": tempToken, "activateCode": actCode}) return
def runActiveCode(self, restext): tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_email_register_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] url = '/api/v2/identity/register/email/activate' body = { "tmpToken": tempToken, "activateCode": actCode, "pushToken": "emailRegrjhjayegrkldfkhgdkfasd" } pprint(body) api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body)
def setCondition(self, categoryId, isActive, isDelete, isDuriation, isExpired): sqlList = [] result = dbConnect.dbQuery(test_parameter['db'], "select min(id) from gift_v2 where category_id = " + str(categoryId)) if not isActive: sqlStr = "update gift_v2 set is_active = 0 where id = " + str(result[0][0]) elif isDelete: sqlStr = "update gift_v2 set deleted_at = '" + (datetime.today() - timedelta(hours=7)).strftime('%Y-%m-%d %H:%M:%S') + "' where id = " + str(result[0][0]) elif isDuriation: sqlStr = "update gift_category_v2 set end_time = '" + (datetime.today() - timedelta(hours=6)).strftime('%Y-%m-%d %H:%M:%S') sqlStr += "', start_time = '" + (datetime.today() - timedelta(hours=7)).strftime('%Y-%m-%d %H:%M:%S') + "' where id = " + str(categoryId) elif isExpired: sqlStr = "update gift_category_v2 set end_time = '" + (datetime.today() - timedelta(hours=9)).strftime('%Y-%m-%d %H:%M:%S') + "' where id = " + str(categoryId) sqlList.append(sqlStr) dbConnect.dbSetting(test_parameter['db'], sqlList) if sqlList else None
def getActiveCode(self): url = '/api/v2/identity/register/email/send' body = { 'email': '*****@*****.**', 'password': '******', 'pushToken': 'emailRegrjhjayegrkldfkhgdkfasd' } res = api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, url, 'post', body) restext = json.loads(res.text) pprint(restext) tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_email_register_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] return tempToken, actCode
def verifyAddResult(self, restext, body): typeList = ['live_room', 'live_show'] assert restext['data'][0]['type'] == body['type'] assert restext['data'][0]['categoryName'] == body['categoryName'] assert restext['data'][0]['banner'] == body.get('banner') assert restext['data'][0]['url'] == body.get('url') assert restext['data'][0]['startTime'] == body['startTime'] assert restext['data'][0]['endTime'] == body['endTime'] if body['type'] in (1, 2): sqlStr = "select category_name, status, type, start_time, end_time from gift_category where id = " + str( restext['data'][0]['id']) result = dbConnect.dbQuery(test_parameter['db'], sqlStr) assert result[0][0] == body['categoryName'] assert result[0][1] == 1 assert result[0][2] == typeList[body['type'] - 1] assert result[0][3] == body['startTime'] * 1000 assert result[0][4] == body['endTime'] * 1000
def emailReg(emailAddr, PWD): url = '/api/v2/identity/register/email/send' body = { 'email': emailAddr, 'password': PWD } res = api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, url, 'post', body) restext = json.loads(res.text) tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_email_register_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] url = '/api/v2/identity/register/email/activate' body = { "tmpToken": tempToken, "activateCode": actCode, "pushToken": "dshfklkrxkeiyegrkldfkhgdkfasd" } api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, url, 'post', body)
def test_getProductInfo(scenario, platformName): sqlStr = "select id, platforms, points, price, product_id, product_type, remark " sqlStr += "from product_info where status = 1 and production = 1 and product_type = '" + py_mapping[ platformName] + "' order by points" dbResult = dbConnect.dbQuery('35.234.17.150', sqlStr) pprint(dbResult) header = {'Connection': 'Keep-alive'} apiNmae = '/api/v2/productInfo/' + platformName + '/enableList' res = api.apiFunction('http://35.234.17.150', header, apiNmae, 'get', None) resText = json.loads(res.text) assert res.status_code == 200 assert len(dbResult) == len(resText['productInfos']) for i in range(len(dbResult)): assert dbResult[i][0] == resText['productInfos'][i]['id'] assert ast.literal_eval( dbResult[i][1]) == resText['productInfos'][i]['platforms'] assert dbResult[i][2] == resText['productInfos'][i]['points'] assert int(dbResult[i][3]) == resText['productInfos'][i]['price'] assert dbResult[i][4] == resText['productInfos'][i]['productId'] assert dbResult[i][5] == resText['productInfos'][i]['productType'] assert dbResult[i][6] == resText['productInfos'][i]['remark']
def regByMail(): url = '/api/v2/identity/register/email/send' body = { 'email': '*****@*****.**', 'password': '******' } res = api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, url, 'post', body) restext = json.loads(res.text) tempToken = restext['data']['tmpToken'] sqlStr = "select activate_code from identity_email_register_history where token = '" + tempToken + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) actCode = result[0][0] url = '/api/v2/identity/register/email/activate' body = { "tmpToken": tempToken, "activateCode": actCode, "pushToken": "dshfklkrxkeiyegrkldfkhgdkfasd" } res = api.apiFunction(test_parameter['prefix'], {'Content-Type': 'application/json'}, url, 'post', body) restext = json.loads(res.text) return(restext['data']['token'], restext['data']['nonce'], restext['data']['idToken'])
def testGetCategory(self, test_input, startTime, endTime, isDelete, expected): TimeCondition1 = (datetime.today() - timedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S') TimeCondition2 = (datetime.today() + timedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S') #驗證權限及查詢類別 self.setData(startTime, endTime, isDelete) apiName = '/api/v2/identity/giftCategory/list?type=' + str( test_input[2]) + '&item=30&page=1' header['X-Auth-Token'] = test_input[0] header['X-Auth-Nonce'] = test_input[1] time.sleep(60) res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) restext = json.loads(res.text) #pprint(restext) assert res.status_code // 100 == expected if expected == 2: if test_input[2] < 5: sql = "select id, name, banner, url, start_time, end_time from gift_category_v2 where type = '" + self.gctype[ test_input[2] - 1] + "' and deleted_at is null and " sql += "((start_time <= '" + TimeCondition1 + "' or start_time is null) and (end_time >= '" + TimeCondition2 + "' or end_time is null)) order by id desc" dbResult = dbConnect.dbQuery(test_parameter['db'], sql) #pprint(dbResult) assert restext['totalCount'] == len(dbResult) if restext['totalCount'] > 0: for i in range(len(dbResult)): #print('i = %d; data id = %d; db id = %d'%(i, restext['data'][i]['id'], dbResult[i][0])) assert restext['data'][i]['id'] == dbResult[i][0] assert restext['data'][i]['type'] == test_input[2] assert restext['data'][i]['categoryName'] == dbResult[ i][1] assert restext['data'][i]['banner'] in ('', dbResult[i][2]) assert restext['data'][i]['url'] in ('', dbResult[i][3]) else: assert restext['totalCount'] == 0
def testGetSingleUserInfo(self, scenario, token, nonce, idIndex, compareKey, compareValue, roleType, expect): apiName = '/api/v2/backend/user/' + idList[idIndex] header['X-Auth-Nonce'] = test_parameter[nonce] header['X-Auth-Token'] = test_parameter[token] res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) assert res.status_code // 100 == expect if expect == 2: restext = json.loads(res.text) #assert restext['roles'][0]['name'] == roleType sqlStr = "select truelove_id from identity where id = '" + idList[idIndex] + "'" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) expectID = initdata.getTrueLoveId(result[0][0]) print('trueloveId = %d; api trueloveId: %s, my hash Id: %s '%(result[0][0], restext['trueLoveId'], expectID)) assert len(restext['profilePicture']) > 0 assert restext['id'] == idList[idIndex] assert restext['trueLoveId'] == expectID if compareKey != '': if compareKey != 'trueLoveId': assert restext[compareKey] == compareValue else: assert restext['trueLoveId'] == expectID assert restext['userLevel']['levelId'] == 'bronze' assert restext['userLevel']['levelNum'] == 1
def test_getInfo(self, scenario, token, nonce, action, expected): actionDic = { 'getId': 'select liveshow_id, title, pool_id from liveshow where id = 1', 'empty': '', 'wrongId': 'errId' } if action == 'getId': result = dbConnect.dbQuery(test_parameter['db'], actionDic[action]) liveshowId = result[0][0] else: liveshowId = actionDic[action] header['X-Auth-Token'] = test_parameter[token] header['X-Auth-Nonce'] = test_parameter[nonce] apiName = '/api/v2/liveshow/info' res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', {'liveshowId': liveshowId}) restext = json.loads(res.text) assert res.status_code // 100 == expected if expected == 2: assert restext['title'] == result[0][1] assert restext['masterId'] == result[0][2] assert all([len(str(restext['liveStartTime'])) == 10, type(restext['liveStartTime']) == int]) assert all([len(str(restext['liveEndTime'])) == 10, type(restext['liveEndTime']) == int]) assert all([len(str(restext['serverTimeStamp'])) == 10, type(restext['serverTimeStamp']) == int])
def preparePostGift(self): sqlStr = "select g.id, g.name, g.point from gift_v2 g join gift_category_v2 gc on category_id = gc.id where gc.type = 'post_gift' and g.point > 0 limit 1" dbResult = dbConnect.dbQuery(test_parameter['db'], sqlStr) pprint(dbResult) self.giftId = dbResult[0][0] self.giftName = dbResult[0][1] self.giftPoint = dbResult[0][2] header['X-Auth-Token'] = test_parameter['broadcaster_token'] header['X-Auth-Nonce'] = test_parameter['broadcaster_nonce'] apiName = '/api/v2/liveMaster/photoPost' body = { "photoPath": test_parameter['photo_url'], "content": "動態送禮。。測試中" } api.apiFunction(test_parameter['prefix'], header, apiName, 'post', body) #print('/api/v2/liveMaster/photoPost') #pprint(json.loads(res.text)) apiName = '/api/v2/liveMaster/' + idlist[0] + '/photoPost?item=5&page=1' res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) restext = json.loads(res.text) self.postId = restext['data'][0]['id']
def testAuthAndType(self, initDB, scenario, token, nonce, typeNum, categoryId, isActive, isDelete, isDuriation, isExpired, expected): #驗證權限及查詢類別 self.setCondition(categoryId, isActive, isDelete, isDuriation, isExpired) TimeCondition1 = (datetime.today() - timedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S') TimeCondition2 = (datetime.today() + timedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S') apiName = '/api/v2/identity/gift/list?giftCategoryId=' + str(categoryId) + '&item=20&page=1' header['X-Auth-Token'] = test_parameter[token] header['X-Auth-Nonce'] = test_parameter[nonce] time.sleep(30) res = api.apiFunction(test_parameter['prefix'], header, apiName, 'get', None) assert res.status_code // 100 == expected if expected == 2: restext = json.loads(res.text) sqlStr = "select g.id, g.name, g.point, g.thumb_url, g.animation_url, g.is_multiple, g.uuid from gift_v2 g inner join gift_category_v2 c " sqlStr += "on g.category_id = c.id and c.id = " + str(categoryId) + " " sqlStr += "and c.deleted_at is Null and ((c.start_time <= '" + TimeCondition1 + "' or c.start_time is null) " sqlStr += "and (c.end_time >= '" + TimeCondition2 + "' or c.end_time is null)) " sqlStr += "where g.is_active = 1 and g.deleted_at is Null order by g.point" dbResult = dbConnect.dbQuery(test_parameter['db'], sqlStr) assert restext['totalCount'] == len(dbResult) if restext['totalCount'] > 0: for i in range(restext['totalCount']): assert restext['data'][i]['id'] == dbResult[i][0] assert restext['data'][i]['categoryId'] == categoryId assert restext['data'][i]['name'] == dbResult[i][1] assert restext['data'][i]['point'] == dbResult[i][2] assert restext['data'][i]['thumbUrl'] == dbResult[i][3] assert restext['data'][i]['url'] == dbResult[i][3] assert restext['data'][i]['animationUrl'] == dbResult[i][4] assert int(restext['data'][i]['isMultiple']) == dbResult[i][5] assert restext['data'][i]['uuid'] == dbResult[i][6] if restext['data'][i]['isMultiple']: assert restext['data'][i]['multiples'] == [1, 20, 520, 999] else: assert restext['data'][i]['multiples'] == [1, 2, 4, 6, 8] if i > 0: assert restext['data'][i-1]['point'] <= restext['data'][i]['point']
def testBindToActive(self, isSendMail, condition, bindMail, PWD, expected): actCode = 0 url = '/api/v2/identity/binding/email/activate' if isSendMail: actCode = self.getActiveCode(bindMail) body = { "source": "advance", "email": bindMail, "activateCode": actCode } if condition == 'sourceWrong': body["source"] = "test" elif condition == 'codeWrong': body["activateCode"] = "214520" elif condition == 'mailDismatch': body["email"] = "*****@*****.**" elif condition == 'codeExpired': sqlStr = "select max(id) from identity_email_bind_history" result = dbConnect.dbQuery(test_parameter['db'], sqlStr) sqlList = [ "update identity_email_bind_history set expires_in = 1 where id = " + str(result[0][0]) ] dbConnect.dbSetting(test_parameter['db'], sqlList) time.sleep(2) if type(PWD) == list: for i in range(len(PWD)): body["password"] = PWD[i] res = api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body) assert res.status_code // 100 == expected else: body["password"] = PWD #pprint(body) res = api.apiFunction(test_parameter['prefix'], self.head, url, 'post', body) assert res.status_code // 100 == expected