Esempio n. 1
0
def test_users_all_add_new():
    '''check the list after a new user adding in'''
    other.clear()
    # initialise the users list
    #create a user
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']
    u1_id = user1['u_id']

    #create another user
    user2 = auth.auth_register('*****@*****.**', 'password', 'FirstN2',
                               'LastN2')
    user2 = auth.auth_login('*****@*****.**', 'password')
    u2_id = user2['u_id']

    i = other.users_all(u1_token).get('users')
    i_user1 = i[0]
    i_user2 = i[1]
    assert len(i) == 2
    assert i_user1['u_id'] == u1_id
    assert i_user1['email'] == '*****@*****.**'
    assert i_user1['name_first'] == 'FirstN'
    assert i_user1['name_last'] == 'LastN'
    assert i_user2['u_id'] == u2_id
    assert i_user2['email'] == '*****@*****.**'
    assert i_user2['name_first'] == 'FirstN2'
    assert i_user2['name_last'] == 'LastN2'
Esempio n. 2
0
def test_standup_start():
    '''test for start function'''
    clear()

    #create a user and take the token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    #create a channel by user1 in channels and return its channel id
    channel_1_id = channels.channels_create(u1_token, 'team',
                                            True).get('channel_id')

    channels_t = data.return_channels()

    time_str1 = channels_t[0]['standup'][
        'finish_time']  #get the finish time before the standup starts

    now = datetime.datetime.utcnow()
    timestamp = int(now.replace(tzinfo=datetime.timezone.utc).timestamp())
    time_str3 = timestamp
    #start a standup
    standup.standup_start(u1_token, channel_1_id, 1)

    channels_t = data.return_channels()
    time_str2 = channels_t[0]['standup'][
        'finish_time']  #get the finish time after the standup starts

    assert time_difference(time_str1, time_str2) < 0
    assert time_difference(time_str2, time_str3) == 1

    time.sleep(2)
Esempio n. 3
0
def test_search_basic():
    '''check if the function can collect all the message with query_str'''
    other.clear()
    #initialise the channels list
    #create the first user and take their token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    # create a channel for testing
    channel_test_id1 = channels.channels_create(u1_token, "channel_test1",
                                                True).get('channel_id')
    #add some message to one channel
    message.message_send(u1_token, channel_test_id1,
                         'Today, I am the winner.')  #t
    message.message_send(u1_token, channel_test_id1, 'What about you?')  #f
    message.message_send(u1_token, channel_test_id1,
                         'Yesterday, I was the winner.')  #t
    message.message_send(u1_token, channel_test_id1, 'Cool!')  #f
    message.message_send(u1_token, channel_test_id1,
                         'Tomorrow, I will be the winner.')  #t

    i = other.search(u1_token, 'the winner').get('messages')
    assert len(i) == 3
    assert i[0]['message'] == 'Tomorrow, I will be the winner.'
    assert i[1]['message'] == 'Yesterday, I was the winner.'
    assert i[2]['message'] == 'Today, I am the winner.'
Esempio n. 4
0
def test_search_whitespace_insensitive():
    ''' this function checks for whitespace insensitivity when it comes to message search '''
    other.clear()
    #initialise the channels list
    #create the first user and take their token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    # create a channel for testing
    channel_test_id1 = channels.channels_create(u1_token, "channel_test1",
                                                True).get('channel_id')
    # add some message to one channel
    # the case is different in this case
    message.message_send(u1_token, channel_test_id1,
                         'Today, I am the \nwiNNer.')  #t
    message.message_send(u1_token, channel_test_id1, 'What about you?')  #f
    message.message_send(u1_token, channel_test_id1,
                         'Yesterday, I was the winn    er.')  #t
    message.message_send(u1_token, channel_test_id1, 'Cool!')  #f
    message.message_send(u1_token, channel_test_id1,
                         'Tomorrow, I\t will be the W  inner.')  #t

    i = other.search(u1_token, 'the winner').get('messages')
    assert len(i) == 3
    assert i[0]['message'] == 'Tomorrow, I\t will be the W  inner.'
    assert i[1]['message'] == 'Yesterday, I was the winn    er.'
    assert i[2]['message'] == 'Today, I am the \nwiNNer.'
Esempio n. 5
0
def test_channels_create():
    clear()

    #create a user and take its  id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    u1_id = user1['u_id']
    u1_token = user1['token']

    #check the error when the channelname is too long
    with pytest.raises(InputError):
        channels.channels_create(u1_token, 'A_very_very_very_ver_long_name',
                                 True)

    #create a channel in channels and return its channel id
    channel_1_id = channels.channels_create(u1_token, 'team',
                                            True).get('channel_id')
    #assert channel_1_id is int
    assert data.return_channels()[-1]['name'] == 'team'
    assert data.return_channels()[-1]['channel_id'] == channel_1_id
    assert data.return_channels()[-1]['is_public'] == True
    assert data.return_channels()[-1]['owner_members'][0]['u_id'] == u1_id
    assert data.return_channels(
    )[-1]['owner_members'][0]['name_first'] == 'FirstN'
    assert data.return_channels(
    )[-1]['owner_members'][0]['name_last'] == 'LastN'

    assert data.return_channels()[-1]['all_members'][0]['u_id'] == u1_id
    assert data.return_channels(
    )[-1]['all_members'][0]['name_first'] == 'FirstN'
    assert data.return_channels()[-1]['all_members'][0]['name_last'] == 'LastN'
Esempio n. 6
0
def test_auth_login_input_error_nonexistent_email():
    ''' tests whether login checks nonexistent emails'''
    clear()
    # - email is not in data structure i.e. user isn't registered
    with pytest.raises(InputError):
        # this was never registered previously
        auth.auth_login('*****@*****.**', 'password')
Esempio n. 7
0
def test_incorrect_u_id_for_photo():
    ''' test that photos with incorrect u_ids are not returned '''
    clear()

    # no u_id registered so no possible photo exists
    with pytest.raises(InputError):
        data.get_profile_photo_path('0')
Esempio n. 8
0
def test_user_profile_input_error_existing_email():
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']
    with pytest.raises(InputError):
        user.user_profile_setemail(token, "*****@*****.**")
Esempio n. 9
0
def test_currect_u_id_for_photo(url):
    ''' test that photos with correct u_ids are saved '''
    clear()

    # register a new user
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']
    u_id = registration['u_id']

    url_test = url + 'one'
    url_cropped = url_test + '/crop'

    # get the first already cropped image from the test server
    r = requests.get(url_cropped, stream=True)
    test_image = Image.open(r.raw)

    # test that the function doesn't crash
    assert user.user_profile_uploadphoto(token, url_test, 0, 0, 10, 10) == {}

    # get the saved image from saved path
    path = 'src/data/profiles/{u_id}.jpg'.format(u_id=str(u_id))
    saved_image = Image.open(path)

    # check that image was cropped correctly
    assert compare_images(test_image, saved_image) == True
Esempio n. 10
0
def test_auth_register_multiple_users():
    """
    - u_id is unique when multiple users are entered
    creates a large  number of u_id's and make sure none of them conflict
    tested it up to 10,000 array_size but takes a while, can go higher for sure
    """

    clear()

    array_size = 100
    array = [0] * array_size

    i = 0
    while i < array_size:
        array[i] = (auth.auth_register('test' + str(i)
        + '@example.com', 'password', 'Test', 'Personmanperson')['u_id'])
        i += 1

    assert len(array) == len(set(array))

    # a unique handle is produced
    new_list = []
    for user in data.return_users():
        new_list.append(user['handle_str'])
    assert len(new_list) == len(set(new_list))
Esempio n. 11
0
def test_channels_listall():
    clear()

    #create two user and take their id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    user2 = auth.auth_register('*****@*****.**', 'password', 'FirstN2',
                               'LastN2')
    user2 = auth.auth_login('*****@*****.**', 'password')
    u2_token = user2['token']

    #create a channel by user1 in channels and return its channel id
    channel_1_id = channels.channels_create(u1_token, 'team',
                                            True).get('channel_id')

    #create a channel by user2 in channels and return its channel id
    channel_2_id = channels.channels_create(u2_token, 'team2',
                                            True).get('channel_id')

    #check if the function return them all
    l_test = channels.channels_listall(u1_token).get('channels')
    assert len(l_test) == 2
    assert l_test[0]['channel_id'] == channel_1_id
    assert l_test[1]['channel_id'] == channel_2_id
    assert l_test[0]['name'] == 'team'
    assert l_test[1]['name'] == 'team2'
Esempio n. 12
0
def test_passwordreset_reset_valid_code():
    ''' test passwordreset with a valid code '''
    clear()

    # register a user
    u_id = auth.auth_register('*****@*****.**', 'password', 'Mate', 'Old').get('u_id')

    # send the password reset
    auth.passwordreset_request('*****@*****.**')
    code = get_reset_code(u_id).get('code')
    now = datetime.datetime.utcnow()

    # reset the password
    assert auth.passwordreset_reset(code, 'passwordTime') is not None

    new_hash = auth.hash_('passwordTime')

    # check the password
    valid = False
    for user in data.return_users():
        if (user.get('password') == new_hash
        and abs((now - user.get('password_reset').get('origin')).total_seconds()) < 500):
            valid = True
            break
    # if new password wasn't stored, assert
    assert valid
Esempio n. 13
0
def test_standup_active():
    '''test for the active function'''
    clear()

    #create a user and take their id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    #create two channels by user1 in channels and return their channel id
    channel_1_id = channels.channels_create(u1_token, 'team',
                                            True).get('channel_id')
    channel_2_id = channels.channels_create(u1_token, 'team1',
                                            True).get('channel_id')

    standup_1 = standup.standup_start(
        u1_token, channel_1_id,
        2)  #start a standup in channel_1 but not in channel_2_id

    res1 = standup.standup_active(u1_token, channel_1_id)
    assert res1['is_active'] == True
    assert res1['time_finish'] == standup_1['time_finish']

    res2 = standup.standup_active(u1_token, channel_2_id)
    assert res2['is_active'] == False
    assert res2['time_finish'] == None

    time.sleep(2.5)
Esempio n. 14
0
def test_owner_from_token():
    clear()
    #create a user and take its  id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    u1_token = user1['token']
    token_tem = u1_token + ' '
    with pytest.raises(InputError):
        channels.owner_from_token(token_tem)
Esempio n. 15
0
def test_user_profile_handle_input_error_invalid_handle():
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']
    with pytest.raises(InputError):
        user.user_profile_sethandle(token, "27")
    with pytest.raises(InputError):
        user.user_profile_setemail(token, "2367brehjrtjehjtrghjtjrtjtjk")
Esempio n. 16
0
def test_user_profile_input_error_invalid_u_id():
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']
    with pytest.raises(InputError):
        user.user_profile(token, "3263fdhr")
    with pytest.raises(InputError):
        user.user_profile(token, 26157890314)
Esempio n. 17
0
def test_auth_login_input_error_invalid_email():
    ''' tests if login checks valid email'''
    clear()
    # - spits out 'InputError' if:
    # - email is not a valid email (check with regex)
    with pytest.raises(InputError):
        auth.auth_login('invalidexample.com', 'password')
    with pytest.raises(InputError):
        auth.auth_login('invalid@example', 'password')
Esempio n. 18
0
def test_auth_login_input_error_incorrect_password():
    ''' tests whether login checks password'''
    clear()
    auth.auth_register('*****@*****.**', 'correct_password', 'test', 'person')

    # - password is not correct (we love storing raw passwords)
    # correct password is 'correct_password'
    with pytest.raises(InputError):
        auth.auth_login('*****@*****.**', 'incorrect_password')
Esempio n. 19
0
def test_user_profile_setname_invalid_name():
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']

    with pytest.raises(InputError):
        user.user_profile_setname(token, '', 'Old')
    with pytest.raises(InputError):
        user.user_profile_setname(token, 'Mate', '')
Esempio n. 20
0
def test_user_profile_setname_correct_return():
    ''' checks correct return from login'''
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']
    result = user.user_profile_setname(token, "Mate1", "Old2")

    # - Dict structure -> {u_id, token}
    assert isinstance(result, dict)
Esempio n. 21
0
def test_auth_register_input_error_existing_email():
    ''' tests whether register checks existing emails'''

    clear()

    # - email address is already used
    # this is the email registered at the top of the test function
    auth.auth_register('*****@*****.**', 'emilyisshort', 'Emily', 'Luo?')
    with pytest.raises(InputError):
        auth.auth_register('*****@*****.**', 'emilyisshort', 'Emily', 'Luo?')
Esempio n. 22
0
def test_token_into_name():
    '''test for the transformation from token into first name'''
    clear()

    #create a user and take their id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    assert standup.token_into_name(u1_token) == 'FirstN'
Esempio n. 23
0
def test_token_to_user():
    '''test for the token_to_user function'''
    clear()

    #create a user and take their id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN', 'LastN')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']

    assert standup.token_into_user_id(u1_token) != -1
Esempio n. 24
0
def test_user_profile_setname_invalid_token():
    clear()
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']

    invalid_token = '500000'
    if invalid_token == token:
        raise Exception('The token in program is actually valid')
    is_success = user.user_profile_setname(invalid_token, "Mate", "Old")
    assert is_success['is_success'] is False
Esempio n. 25
0
def test_auth_register_input_error_valid_email():
    ''' tests whether register checks valid emails'''

    clear()
    ##########################################################################
    # - spits out 'InputError' if: (raise InputError)
    # - email is not a valid email (check with regex)
    with pytest.raises(InputError):
        auth.auth_register('invalidexample.com', 'password', 'Mate', 'Old')
    with pytest.raises(InputError):
        auth.auth_register('invalid@example', 'password', 'Mate', 'Old')
Esempio n. 26
0
def test_standup_all_message_sent_out_twice():
    '''check if the message in message package has been sent out after ending'''
    clear()

    #create three user and take their id and token
    user1 = auth.auth_register('*****@*****.**', 'password', 'FirstN1',
                               'LastN1')
    user1 = auth.auth_login('*****@*****.**', 'password')
    u1_token = user1['token']
    u1_id = user1['u_id']
    user2 = auth.auth_register('*****@*****.**', 'password', 'FirstN2', 'LastN2')
    user2 = auth.auth_login('*****@*****.**', 'password')
    u2_token = user2['token']
    u2_id = user2['u_id']
    user3 = auth.auth_register('*****@*****.**', 'password', 'FirstN3', 'LastN3')
    user3 = auth.auth_login('*****@*****.**', 'password')
    u3_token = user3['token']
    u3_id = user3['u_id']

    #create a channel by user1 in channels and invite other two users
    channel_1_id = channels.channels_create(u1_token, 'team',
                                            True).get('channel_id')
    channel.channel_invite(u1_token, channel_1_id, u2_id)
    channel.channel_invite(u1_token, channel_1_id, u3_id)
    #start a standup by u1
    standup.standup_start(u1_token, channel_1_id, 3)

    standup.standup_send(u1_token, channel_1_id, 'WE')
    standup.standup_send(u2_token, channel_1_id, 'ARE')
    standup.standup_send(u3_token, channel_1_id, 'FRIENDS')
    #sleep until the standup ending
    time.sleep(4)

    #start another standup by u2
    standup.standup_start(u2_token, channel_1_id, 3)

    standup.standup_send(u1_token, channel_1_id, 'SHE')
    standup.standup_send(u2_token, channel_1_id, 'HE')
    standup.standup_send(u3_token, channel_1_id, 'THEY')

    #sleep until the standup ending
    time.sleep(4)
    channels_t = data.return_channels()
    m_c_1 = channels_t[0]['message'][1]
    m_c_2 = channels_t[0]['message'][0]
    #check the message has been sent
    assert m_c_1['u_id'] == u1_id
    assert m_c_2['u_id'] == u2_id
    assert m_c_1['message'] == 'FirstN1: WE\nFirstN2: ARE\nFirstN3: FRIENDS\n'
    assert m_c_2['message'] == 'FirstN1: SHE\nFirstN2: HE\nFirstN3: THEY\n'

    #check the message package
    assert channels_t[0]['standup'][
        'message_package'] == 'FirstN1: SHE\nFirstN2: HE\nFirstN3: THEY\n'
Esempio n. 27
0
def test_user_profile_uploadphoto_invalid_url(url):
    ''' see if it throws Inputerror with an incorrect url '''
    clear()
    # register a new user
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']

    # test InputError for a png
    url_test = url + '/thisdoesntexist'
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(token, url_test, 0, 0, 10, 10)
Esempio n. 28
0
def test_user_profile_uploadphoto_txt(url):
    ''' test to see if it throws InputError on files that aren't a jpg '''
    clear()
    # register a new user
    registration = auth.auth_register('*****@*****.**', 'password', 'Mate',
                                      'Old')
    token = registration['token']

    # test InputError for a png
    url_test = url + '/txt'
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(token, url_test, 0, 0, 10, 10)
Esempio n. 29
0
def test_auth_register_input_error_wrong_len_name_last():
    ''' tests whether register checks wrong last name length'''
    clear()
    # - len(name_last) < 1 || len(name_last) > 50
    long_last_name = ""
    for _ in range(55):
        long_last_name += "a"
    with pytest.raises(InputError):
        auth.auth_register('*****@*****.**', 'password', 'Test', long_last_name)
    # make a short name
    with pytest.raises(InputError):
        auth.auth_register('*****@*****.**', 'password', 'Test', '')
Esempio n. 30
0
def test_auth_register_permission_id():
    ''' checks that the correct permission_id's are given '''
    clear()

    u_id1 = auth.auth_register('*****@*****.**', 'emilyisshort', 'Emily', 'Luo?').get('u_id')
    u_id2 = auth.auth_register('*****@*****.**', 'emilyisshor2t', 'Emil2y', 'Luo2?').get('u_id')
    u_id3 = auth.auth_register('*****@*****.**', 'emilyissh3or2t', 'Emi3l2y', 'Lu3o2?').get('u_id')

    # test permission_id's are correct
    assert user_from_u_id(u_id1).get('permission_id') == 1
    assert user_from_u_id(u_id2).get('permission_id') == 2
    assert user_from_u_id(u_id3).get('permission_id') == 2