Esempio n. 1
0
def do_get_messages_test():
    # create users for test
    test_users = []
    for i in range(0, 4):
        test_user = ('test' + str(i), 'test' + str(i) + '@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)

    # create room for test
    url = urls.chatroomlist_url()
    auth = (test_users[0][0], test_users[0][2])
    data = {'user2': test_users[1][0]}
    res = requests.post(url, data, auth=auth)
    roomid = res.json()['id']

    # test
    for i in range(0, 2):
        utils.get_chat_messages_success((test_users[i][0], test_users[i][2]),
                                        roomid)

    for i in range(2, 4):
        utils.get_chat_messages_fail((test_users[i][0], test_users[i][2]),
                                     roomid)
Esempio n. 2
0
def get_chat_rooms_success(auth):
    url = urls.chatroomlist_url()
    res = requests.get(url, auth=auth, verify=False)

    if res.status_code != 200:
        print('error!: user {0} cannot get chat room list'.format(auth[0]))
        exit(1)

    else:
        print('user {0} get chat room list success'.format(auth[0]))
Esempio n. 3
0
def get_chat_rooms_fail(auth):
    url = urls.chatroomlist_url()
    res = requests.get(url, auth=auth, verify=False)

    if res.status_code != 403:
        print('error!: unauthenticated user {0} get chat room list'.format(
            auth[0]))
        exit(1)

    else:
        print('user {0} get chat room list fail success'.format(auth[0]))
Esempio n. 4
0
def post_chat_rooms_fail(auth):
    url = urls.chatroomlist_url()
    data = {'user2': 'nonExistUser'}
    res = requests.post(url, data, auth=auth, verify=False)

    if res.status_code != 500:
        print('error!: user {0} post chat room with {1}'.format(
            auth[0], 'nonExistUser'))
        exit(1)

    else:
        print('user {0} with {1} post chat room fail success'.format(
            auth[0], 'nonExistUser'))
Esempio n. 5
0
def post_chat_rooms_success(auth, user2):
    url = urls.chatroomlist_url()
    data = {'user2': user2}
    res = requests.post(url, data, auth=auth, verify=False)

    if res.status_code != 200:
        print('error!: user {0} cannot post chat room with user {1}'.format(
            auth[0], user2))
        exit(1)

    else:
        print('user {0} post chat room with user {1} success'.format(
            auth[0], user2))