def get_posts(username, password, text, userNum): postList = requests.get(urls.posts_url(), auth=(username, password), verify=False) #print ( res ) if postList.status_code != 200: print('test error: sns_admin cannot get user list') exit(1) for i in range(0, userNum): uname = "test" + str(i) postExistFlag = False for post in postList.json(): if post['user'] == uname: postExistFlag = True if post['text'] != text: print('error: get posts user {0} fail'.format(username)) exit(1) break if postExistFlag == False: print('error: get posts user {0} fail'.format(username)) exit(1) print('{0} get posts success'.format(username))
def do_timeline_permission_test(): #create test user test_users = [] for i in range(0, 2): username = '******' + str(i) test_user = (username, username + '@test.com', '1234qwer') utils.delete_user(test_user[0]) utils.sign_up_success(test_user[0], test_user[1], test_user[2]) test_users.append(test_user) utils.posting_success(test_users[0][0], test_users[0][2], 'test0 posts this posting') utils.posting_success(test_users[1][0], test_users[1][2], 'test1 posts this posting') postList = requests.get(urls.posts_url(), auth=(test_users[1][0], test_users[1][2])) for post in postList.json(): if post['user'] == test_user[0][0]: print( 'error: test1 can access post by test0 who is not friend of him.' ) utils.post_friendrequest((test_users[0][0], test_users[0][2]), test_users[1][0]) request_id = [] request_id.append(0) request_id.append( utils.get_friendrequest((test_users[1][0], test_users[1][2]), test_users[0][0])) utils.accept_friendrequest((test_users[1][0], test_users[1][2]), request_id[1]) postList = requests.get(urls.posts_url(), auth=(test_users[1][0], test_users[1][2])) friendPostShow = False for post in postList.json(): # print( post ) if post['user'] == test_users[0][0]: friendPostShow = True if not friendPostShow: print('error: test1 cannot access post by test0 who is his friend') exit(1)
def get_posts_fail(testNum): res = requests.get(urls.posts_url(), verify=False) #print ( res ) if res.status_code != 403: print('error!: {0} get posts success'.format(testNum)) exit(1) else: print("get posts fail: {0}".format(testNum))
def posting_fail(testNum, text): data = {'text': text} res = requests.post(urls.posts_url(), data, verify=False) #print ( res ) if res.status_code != 403: print('error!: {0} post success'.format(testNum)) exit(1) else: print("posting fail: {0}".format(testNum))
def posting_success(username, password, text): data = {'text': text} res = requests.post(urls.posts_url(), data, auth=(username, password)) # print ( res.json() ) if res.status_code != 200: print('error: {0} posting fail'.format(username)) exit(1) print('{0} posting success'.format(username)) return res
import requests from time import sleep import urls import json import base64 data = { 'username': '******', 'email': '*****@*****.**', 'password': '******'} res = requests.post( urls.userlist_url(), data ) auth = ('sns_admin', '123') data = { 'text': 'test' } res = requests.post( urls.posts_url(), data, auth=auth ) comment = 'testing comment' data = {'post': 1, 'comment': comment} res = requests.post(urls.update_comment_url(), data, auth=auth)