def test_users_all_alright():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)
    profile1 = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg/440px-An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg"

    email2 = "*****@*****.**"
    name_first2 = "Builder"
    name_last2 = "Bob"
    authRegisterDict2 = auth_register(email2, "GoodPassword2", name_first2, name_last2)
    token2 = authRegisterDict2['token']
    uid2 = getUidFromToken(token2)
    profile2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg/440px-An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg"

    
    #do some tests
    # test if the function works properly
    profile = users_all(token1)
    # List of dictionaries, where each dictionary contains types 
    # u_id, email, name_first, name_last, handle_str, profile_img_url
    print(profile)
    assert profile == {'users': [{
        'u_id': uid1,
        'email': email1,  
        'name_first': name_first1, 
        'name_last': name_last1, 
        'handle_str': name_first1,
        'profile_img_url': profile1
        },{ 
        'u_id': uid2,
        'email': email2, 
        'name_first': name_first2, 
        'name_last': name_last2, 
        'handle_str': name_first2,
        'profile_img_url': profile2
        }]
    }
def test_user_profile_sethandle_usedHandle():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    email2 = "*****@*****.**"
    name_first2 = "Builder"
    name_last2 = "Bob"
    authRegisterDict2 = auth_register(email2, "GoodPassword2", name_first2, name_last2)
    token2 = authRegisterDict2['token']
    uid2 = getUidFromToken(token2)

    #do some tests
    # function fails if handle used by other
    with pytest.raises(ValueError_http):
        user_profile_sethandle(token1, name_first2)
def test_user_profile_invalidId():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' test that error is raised if u_id is not a valid user '''
    with pytest.raises(ValueError_http):
        profile = user_profile(token1, 6508)
def test_user_profile_invalidToken():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' test that function rasies error if token doesn't belong to the correct user '''
    with pytest.raises(ValueError_http):
        profile = user_profile('wrong', uid1)
def test_user_profile_sethandle_tooShort():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    # error raised when handle lower than 3 characters
    with pytest.raises(ValueError_http):
        user_profile_sethandle(token1, "a"*2)
Esempio n. 6
0
def standup_start(token, channel_id, length):
    channel = getChannelFromChannelId(channel_id)
    #check for started standup
    if channel['standup_active'] is True:
        raise ValueError_http('Standup has already started')

    #change standup status to active
    channel['standup_active'] = True
    channel['standup_started_by'] = getUidFromToken(token)
    #store the time finish
    finish_time = datetime.datetime.now(
        datetime.timezone.utc).astimezone().timestamp() + length

    channel['standup_finish'] = finish_time
    return {'time_finish': finish_time}
Esempio n. 7
0
def standup_active(token, channel_id):
    channel = getChannelFromChannelId(channel_id)
    #check if standup_finish time is in the future
    if channel['standup_finish'] > datetime.datetime.now(
            datetime.timezone.utc).astimezone().timestamp():
        is_active = True
    else:
        is_active = False
        channel['standup_active'] = is_active
        send_compiled_standup_msg(getUidFromToken(token), channel_id)

    return {
        'is_active': is_active,  #channel['standup_active'],
        'time_finish': channel['standup_finish']
    }
def search(token, query_str):
    data = getData()
    returnMessage = []
    u_id = getUidFromToken(token)
    # condition for query_str is an empty string
    if query_str == '':
        return []
    # search for messages with query_str and add to returnMessage
    for channels in data['channel']:
        if u_id in channels['all_members']:
            for msg in channels['messages']:
                if re.search(query_str.lower(), msg['message'].lower()):
                    returnMessage.append(msg)
    # print(returnMessage)
    return returnMessage
def test_user_profile_sethandle_alright():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' function runs fine under normal condition '''
    user_profile_sethandle(token1, 'new_handle')
    profile = user_profile(token1, uid1)
    newHandle = profile['handle_str']
    assert newHandle == 'new_handle'
def test_user_profile_alright():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)
    
    #do some tests
    profile = user_profile(token1, uid1)
    ''' test that the returned values are correct '''
    assert(profile['email']) == email1
    assert(profile['name_first']) == name_first1
    assert(profile['name_last']) == name_last1
    assert(profile['handle_str']) == name_first1
def test_user_profile_setemail_alright():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' function runs fine under normal condition '''
    ''' check that email is changed to desired email input '''
    user_profile_setemail(token1, "*****@*****.**")
    profile = user_profile(token1, uid1)
    newEmail = profile['email']
    assert newEmail == "*****@*****.**"
def test_user_profile_setname_tooLong():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' error is raised when name_first is more than 50 characters '''
    with pytest.raises(ValueError_http):
        user_profile_setname(token1, "a"*51, "evans")

    ''' error is raised when name_last is more than 50 characters '''
    with pytest.raises(ValueError_http):
        user_profile_setname(token1, "james", "a"*51)
def test_user_profile_setname_alright():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' function runs fine if everything is valid '''
    #initially the user's name is sally, and is changed to NewSally
    user_profile_setname(token1, 'NewSuper', 'NewSally')
    profile2 = user_profile(token1, uid1)
    #print(userProfileDict2)
    assert(profile2['name_first']) == "NewSuper"
    assert(profile2['name_last']) == "NewSally"
def test_user_profile_setemail_invalidEmail():
    data = reset_data()
    #create some users
    email1 = "*****@*****.**"
    name_first1 = "Super"
    name_last1 = "Sally"
    authRegisterDict = auth_register(email1, "GoodPassword1", name_first1, name_last1)
    token1 = authRegisterDict['token']
    uid1 = getUidFromToken(token1)

    #do some tests
    ''' fucntion fails if email entered is invalid '''
    # No prefix
    with pytest.raises(ValueError_http):
        user_profile_setemail(token1, "@gmail.com")
    # No suffix
    with pytest.raises(ValueError_http):
        user_profile_setemail(token1, "[email protected]")
    # No .com
    with pytest.raises(ValueError_http):
        user_profile_setemail(token1, "sally@gmail.")
    # no @
    with pytest.raises(ValueError_http):
        user_profile_setemail(token1, "sallygmail.com")