def test_channels_list_invalid_token(url):
    clear()
    creatData(url)
    with pytest.raises(requests.exceptions.HTTPError):
        requests.get(url + 'channels/list', json={
            'token': 'nana'
        }).raise_for_status()
def test_channels_create_invalid_token(url):
    clear()
    creatData(url)
    with pytest.raises(requests.exceptions.HTTPError):
        requests.post(url + 'channels/create',
                      json={
                          'token': "INVALIDHHH",
                          'name': 'name1',
                          'is_public': True
                      }).raise_for_status()
def test_message_edit_not_by_authorised_user(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    weiqiang_dict = test_data.register_weiqiang()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    # send a message
    resp_message = requests.post(url + 'message/send',
                                 json={
                                     'token': wenyao_dict['token'],
                                     'channel_id': channel['channel_id'],
                                     'message': "hello"
                                 })
    message_id = json.loads(resp_message.text)
    # invite a new user as channel member
    requests.post(url + 'channel/invite',
                  json={
                      'token': wenyao_dict['token'],
                      'channel_id': channel['channel_id'],
                      'u_id': weiqiang_dict['u_id']
                  })
    # let an unreleated user call edit
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'message/edit',
                     json={
                         'token': weiqiang_dict['token'],
                         'message_id': message_id['message_id'],
                         'message': "hi~"
                     }).raise_for_status()
def test_user_profile_uploadphoto(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    resp_uploadphoto = requests.post(url + '/user/profile/uploadphoto', json={
        'token': wenyao_dict['token'],
        'img_url': IMG_URL,
        'x_start': 10,
        'y_start': 10,
        'x_end': 100,
        'y_end': 100
    })
    uploadphoto_result = json.loads(resp_uploadphoto.text)
    assert uploadphoto_result == {}
    # call channel details
    resp_details = requests.get(url + 'channel/details', params={
        'token': wenyao_dict['token'],
        'channel_id': channel['channel_id']
    })
    channel_details = json.loads(resp_details.text)
    image_url = url + 'image/' + str(wenyao_dict['u_id']) + '.jpg'
    # check the return dictionary
    assert channel_details['owner_members'][0] == {
        'u_id': wenyao_dict['u_id'],
        'name_first': 'Wenyao',
        'name_last': 'Chen',
        'profile_img_url': image_url,
    }
def test_channel_messages_start_greater_than_total(url):
    clear()
    data = creatData(url)
    user = data.register_weiqiang()
    channel = data.creat_channel(user['token'], 'channel01', True)
    # add 2 messages
    requests.post(url + 'message/send',
                  json={
                      'token': user['token'],
                      'channel_id': channel['channel_id'],
                      'message': "VSCode is good."
                  })
    requests.post(url + 'message/send',
                  json={
                      'token': user['token'],
                      'channel_id': channel['channel_id'],
                      'message': "Though I'dont like it."
                  })
    with pytest.raises(requests.exceptions.HTTPError):
        requests.get(url + 'channel/messages',
                     params={
                         'token': user['token'],
                         'channel_id': channel['channel_id'],
                         'start': 10
                     }).raise_for_status()
Esempio n. 6
0
def test_users_all(url):
    clear()
    test_data = creatData(url)
    boyu1_dict = test_data.register_user('*****@*****.**', 'boyupass',
                                         'Boyu', 'Caiiiiiiiiiiiiiiiii')
    boyu2_dict = test_data.register_user('*****@*****.**', 'boyupass', 'Boyu',
                                         'Caiiiiiiiiiiiiiiiii')
    resp_users = requests.get(url + 'users/all',
                              params={'token': boyu1_dict['token']})
    users_dict = json.loads(resp_users.text)
    # check details in users_dict
    assert len(users_dict['users']) == 2
    assert len(users_dict['users'][0].keys()) == 6
    assert len(users_dict['users'][1].keys()) == 6
    assert users_dict['users'][0]['u_id'] == boyu1_dict['u_id']
    assert users_dict['users'][0]['email'] == '*****@*****.**'
    assert users_dict['users'][0]['name_first'] == 'Boyu'
    assert users_dict['users'][0]['name_last'] == 'Caiiiiiiiiiiiiiiiii'
    assert len(users_dict['users'][0]['handle_str']) <= 20
    assert users_dict['users'][1]['u_id'] == boyu2_dict['u_id']
    assert users_dict['users'][1]['email'] == '*****@*****.**'
    assert users_dict['users'][1]['name_first'] == 'Boyu'
    assert users_dict['users'][1]['name_last'] == 'Caiiiiiiiiiiiiiiiii'
    assert len(users_dict['users'][1]['handle_str']) <= 20
    assert users_dict['users'][1]['handle_str'] != users_dict['users'][0][
        'handle_str']
def test_message_pin_valid_outcome(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    #send a message:
    message_test = requests.post(
        url + 'message/send',
        json={
            'token':
            wenyao_dict['token'],
            'channel_id':
            channel['channel_id'],
            'message':
            "YOU were the chosen ONE, it was said you would destory the Sith, not join them "
        })
    message_id1 = json.loads(message_test.text)
    # pin the message
    message_pin_1 = requests.post(url + 'message/pin',
                                  json={
                                      'token': wenyao_dict['token'],
                                      'message_id': message_id1['message_id'],
                                  })
    return_text = json.loads(message_pin_1.text)
    assert return_text == {}
def test_user_profile_setname(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    # test first name is already changed
    resp_first_name = requests.put(url + 'user/profile/setname', json={
        'token': boyu_dict['token'],
        'name_first': 'Boyu',
        'name_last': 'He'
    })
    profile_dict1 = json.loads(resp_first_name.text)
    assert profile_dict1 == {}
    resp_profile = requests.get(url + 'user/profile', params={
        'token': boyu_dict['token'],
        'u_id': boyu_dict['u_id']
    })
    users = json.loads(resp_profile.text)
    assert users['user']['name_first'] == 'Boyu'
    assert users['user']['name_last'] == 'He'
    # test last name is aleardy changed
    resp_last_name = requests.put(url + 'user/profile/setname', json={
        'token': boyu_dict['token'],
        'name_first': 'Xukun',
        'name_last': 'Cai'
    })
    profile_dict2 = json.loads(resp_last_name.text)
    assert profile_dict2 == {}
    resp_profile = requests.get(url + 'user/profile', params={
        'token': boyu_dict['token'],
        'u_id': boyu_dict['u_id']
    })
    users = json.loads(resp_profile.text)
    assert users['user']['name_first'] == 'Xukun'
    assert users['user']['name_last'] == 'Cai'
def test_channels_list_join_some_channels(url):
    clear()
    data = creatData(url)
    user1_dict = data.register_wenyao()
    user2_dict = data.register_boyu()
    # get channels for user1 and user2
    channels_list_1 = requests.get(url + 'channels/list',
                                   params={'token': user1_dict['token']})
    list_wenyao_pre = json.loads(channels_list_1.text)
    channels_list_2 = requests.get(url + 'channels/list',
                                   params={'token': user2_dict['token']})
    list_boyu_pre = json.loads(channels_list_2.text)
    # create 2 channels
    name1_dict = data.creat_channel(user1_dict['token'], 'TeamOrange', True)
    name2_dict = data.creat_channel(user2_dict['token'], 'TeamGrape', True)
    team_orange_id = name1_dict['channel_id']
    team_grape_id = name2_dict['channel_id']
    # append the new added channel to the previous channels respectively
    team_orange_dict = {'channel_id': team_orange_id, 'name': 'TeamOrange'}
    team_grape_dict = {'channel_id': team_grape_id, 'name': 'TeamGrape'}
    list_wenyao_pre['channels'].append(team_orange_dict)
    list_boyu_pre['channels'].append(team_grape_dict)
    # get the current list of channel for the user1 and user2
    channels_list_3 = requests.get(url + 'channels/list',
                                   params={'token': user1_dict['token']})
    list_wenyao_aft = json.loads(channels_list_3.text)
    channels_list_4 = requests.get(url + 'channels/list',
                                   params={'token': user2_dict['token']})
    list_boyu_aft = json.loads(channels_list_4.text)
    # check if list are same
    assert list_boyu_aft == list_boyu_pre
    assert list_wenyao_aft == list_wenyao_pre
def test_message_pin_2nd_times(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    #send a message:
    message_test = requests.post(
        url + 'message/send',
        json={
            'token':
            wenyao_dict['token'],
            'channel_id':
            channel['channel_id'],
            'message':
            "YOU were the chosen ONE, it was said you would destory the Sith, not join them "
        })
    message_id1 = json.loads(message_test.text)
    # pin the message
    requests.post(url + 'message/pin',
                  json={
                      'token': wenyao_dict['token'],
                      'message_id': message_id1['message_id'],
                  })
    # pin the message for the second time
    with pytest.raises(requests.exceptions.HTTPError):
        requests.post(url + 'message/pin',
                      json={
                          'token': wenyao_dict['token'],
                          'message_id': message_id1['message_id'],
                      }).raise_for_status()
def test_message_unreact_valid_message_id(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    #send a message:
    message_test = requests.post(url + 'message/send',
                                 json={
                                     'token': wenyao_dict['token'],
                                     'channel_id': channel['channel_id'],
                                     'message': "General Kenobi !"
                                 })
    message_id1 = json.loads(message_test.text)
    #react a message
    requests.post(url + 'message/react',
                  json={
                      'token': wenyao_dict['token'],
                      'message_id': message_id1['message_id'],
                      'react_id': 1
                  })
    # unreact the message
    message_unreact_1 = requests.post(url + 'message/unreact',
                                      json={
                                          'token': wenyao_dict['token'],
                                          'message_id':
                                          message_id1['message_id'],
                                          'react_id': 1
                                      })
    return_text = json.loads(message_unreact_1.text)
    assert return_text == {}
def test_message_unreact_and_unreact_again(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    #send a message:
    message_test = requests.post(url + 'message/send',
                                 json={
                                     'token': wenyao_dict['token'],
                                     'channel_id': channel['channel_id'],
                                     'message': "You underestimate my POWER!"
                                 })
    message_id1 = json.loads(message_test.text)
    requests.post(url + 'message/react',
                  json={
                      'token': wenyao_dict['token'],
                      'message_id': message_id1['message_id'],
                      'react_id': 1
                  })
    requests.post(url + 'message/unreact',
                  json={
                      'token': wenyao_dict['token'],
                      'message_id': message_id1['message_id'],
                      'react_id': 1
                  })
    with pytest.raises(requests.exceptions.HTTPError):
        requests.post(url + 'message/unreact',
                      json={
                          'token': wenyao_dict['token'],
                          'message_id': message_id1['message_id'],
                          'react_id': 1
                      }).raise_for_status()
def test_message_sendlater_data(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    time_sent = int(time.time())
    time_sent += 5
    #send_later a message
    requests.post(url + 'message/sendlater',
                  json={
                      'token': wenyao_dict['token'],
                      'channel_id': channel['channel_id'],
                      'message': "General Kenobi !",
                      'time_sent': time_sent
                  })
    resp_messages_1 = requests.get(url + 'channel/messages',
                                   params={
                                       'token': wenyao_dict['token'],
                                       'channel_id': channel['channel_id'],
                                       'start': 0
                                   })
    messages_detail = json.loads(resp_messages_1.text)
    assert messages_detail['messages'] == []
    # sleep for 5s
    time.sleep(5)
    resp_messages_2 = requests.get(url + 'channel/messages',
                                   params={
                                       'token': wenyao_dict['token'],
                                       'channel_id': channel['channel_id'],
                                       'start': 0
                                   })
    message_detail_2_re = json.loads(resp_messages_2.text)
    assert len(message_detail_2_re['messages']) == 1
    assert message_detail_2_re['messages'][0]['message'] == "General Kenobi !"
def test_message_edit_empty_string(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    channel = test_data.creat_channel(wenyao_dict['token'], 'team1', True)
    # send a message in to a channel
    resp_message1 = requests.post(url + 'message/send',
                                  json={
                                      'token': wenyao_dict['token'],
                                      'channel_id': channel['channel_id'],
                                      'message': "hello"
                                  })
    # edit the message with empty string
    message_id1 = json.loads(resp_message1.text)
    resp_edit = requests.put(url + 'message/edit',
                             json={
                                 'token': wenyao_dict['token'],
                                 'message_id': message_id1['message_id'],
                                 'message': ""
                             })
    # check the return value
    assert json.loads(resp_edit.text) == {}
    # check the return value from messages details
    resp_messages = requests.get(url + 'channel/messages',
                                 params={
                                     'token': wenyao_dict['token'],
                                     'channel_id': channel['channel_id'],
                                     'start': 0
                                 })
    messages_detail = json.loads(resp_messages.text)
    assert len(messages_detail['messages']) == 0
Esempio n. 15
0
def test_auth_logout_valid_token(url):
    clear()
    test_data = creatData(url)
    user = test_data.register_weiqiang()
    resp_logout = requests.post(url + 'auth/logout',
                                json={'token': user['token']})
    logout_status = json.loads(resp_logout.text)
    assert logout_status['is_success'] is True
def test_channels_list_havent_join_channels(url):
    clear()
    data = creatData(url)
    user1_dict = data.register_wenyao()
    channels_listall_re = requests.get(url + 'channels/listall',
                                       params={'token': user1_dict['token']})
    listall_dict = json.loads(channels_listall_re.text)
    assert len(listall_dict['channels']) == 0
def test_user_profile_setemail_email_not_valid(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/setemail', json={
            'token': boyu_dict['token'],
            'email': '....123'
        }).raise_for_status()
Esempio n. 18
0
def test_users_all_token_invalid(url):
    clear()
    test_data = creatData(url)
    test_data.register_user('*****@*****.**', 'boyupass', 'Boyu',
                            'Caiiiiiiiiiiiiiiiii')
    with pytest.raises(requests.exceptions.HTTPError):
        requests.get(url + 'users/all', params={
            "token": "invalid.token"
        }).raise_for_status()
def test_user_profile_setemail_token_not_valid(url):
    clear()
    test_data = creatData(url)
    test_data.register_boyu()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/setemail', json={
            'token': "invlid_token",
            'email': '*****@*****.**'
        }).raise_for_status()
def test_standup_active_channel_id_invalid(url):
    clear()
    #initialise data
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.get(url + 'standup/active', params={
            'token': boyu_dict['token'],
            'channel_id': -1,
        }).raise_for_status()
def test_channel_join_channelid_not_valid(url):
    clear()
    data = creatData(url)
    user = data.register_wenyao()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.post(url + 'channel/join',
                      json={
                          'token': user['token'],
                          'channel_id': -1
                      }).raise_for_status()
def test_message_remove_id_not_exist(url):
    clear()
    test_data = creatData(url)
    wenyao_dict = test_data.register_wenyao()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.delete(url + 'message/remove',
                        json={
                            'token': wenyao_dict['token'],
                            'message_id': -1
                        }).raise_for_status()
def test_user_profile_sethandle_greaterthan20(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    #test the handle is greater than 20
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/sethandle', json={
            'token': boyu_dict['token'],
            'handle_str': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        }).raise_for_status()
def test_user_profile_sethandle_token_not_valid(url):
    clear()
    test_data = creatData(url)
    test_data.register_boyu()
    # give invalid token
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/sethandle', json={
            'token': "invalid_token",
            'handle_str': 'wulifanfan'
        }).raise_for_status()
def test_user_profile_setname_name_empty_lastname(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    #make last name is empty
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/setname', json={
            'token': boyu_dict['token'],
            'first_name': 'xukun',
            'last_name': ''
        }).raise_for_status()
def test_user_profile_setname_token_not_valid(url):
    clear()
    test_data = creatData(url)
    test_data.register_boyu()
    # give invlid token
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/setname', json={
            'token': "invlid_token",
            'first_name': 'yifan',
            'last_name': 'Wu'
        }).raise_for_status()
Esempio n. 27
0
def test_admin_userpermission_invalid_permission_id(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    with pytest.raises(requests.exceptions.HTTPError):
        requests.post(url + 'admin/userpermission/change',
                      json={
                          'token': boyu_dict['token'],
                          'u_id': boyu_dict['u_id'],
                          'permission_id': 1.5
                      }).raise_for_status()
def test_user_profile_u_id_not_valid(url):
    clear()
    #initialise data
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    # give invalid u_id -1
    with pytest.raises(requests.exceptions.HTTPError):
        requests.get(url + 'user/profile', params={
            'token': boyu_dict['token'],
            'u_id': -1
        }).raise_for_status()
Esempio n. 29
0
def test_admin_user_remove(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    wenyao_dict = test_data.register_wenyao()
    res = requests.delete(url + 'admin/user/remove',
                          json={
                              'token': boyu_dict['token'],
                              'u_id': wenyao_dict['u_id'],
                          })
    assert res.status_code == 200
def test_user_profile_setname_firstname_longerthan50(url):
    clear()
    test_data = creatData(url)
    boyu_dict = test_data.register_boyu()
    # reset first name is longer than 20
    with pytest.raises(requests.exceptions.HTTPError):
        requests.put(url + 'user/profile/setname', json={
            'token': boyu_dict['token'],
            'first_name': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
            'last_name': 'He'
        }).raise_for_status()