示例#1
0
def test_auth_register_invalid_name():
    data = clearData()
    host = get_host()
    email = "*****@*****.**"
    password = "******"
    name_first = ""
    name_last = ""

    register_output = register(data, email, password, name_first, name_last,
                               host)
    assert register_output == {
        'ValueError': "First name or last name too \
short"
    }

    data = clearData()

    name_first = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    name_last = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    assert register_output == {
        'ValueError': "First name or last name too \
long"
    }
示例#2
0
def test_setemail():
    global data, host
    data = Data()
    # Register two user for testing
    auth_key = register(data, '*****@*****.**', 'password', 'name_first',
                        'name_last', host)
    register(data, '[email protected]', 'password1', 'name_first1',
             'name_last1', host)

    invalid_email = 'dffgfddfsa.com'
    email_used_already = '*****@*****.**'

    # Invalid input
    result = usersetemail(data, None, invalid_email)
    assert result == {'ValueError': "token not valid"}

    result = usersetemail(data, auth_key["token"], invalid_email)
    assert result == {'ValueError': 'Email entered is not a valid email'}

    result = usersetemail(data, auth_key["token"], email_used_already)
    assert result == {
        'ValueError': 'Email address is already being used by \
another user'
    }

    result = usersetemail(data, 'token_not_registed', '*****@*****.**')
    assert result == {'ValueError': 'token not valid'}

    # Valid input
    usersetemail(data, auth_key["token"], '*****@*****.**')
    result = getprofile(data, auth_key["token"], auth_key["u_id"], host)
    assert result["email"] == '*****@*****.**'
示例#3
0
def test_sethandle():
    global data, host
    data = Data()
    user = register(data, '*****@*****.**', 'password', 'name_first',
                    'name_last', 'http://127.0.0.1:5555/')
    other_user = register(data, '*****@*****.**', 'password', 'first', 'last',
                          'http://127.0.0.1:5555/')

    handle_long = 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww'
    handle_normal = 'normal'

    handle_used = 'handle_str'
    usersethandle(data, other_user['token'], handle_used)

    # Invalid input
    # handle_str is no more than 20 charaters
    result = usersethandle(data, None, handle_normal)
    assert result == {'ValueError': "token not valid"}

    result = usersethandle(data, user["token"], handle_long)
    assert result == {'ValueError': "handle_str must be between 3 and 20"}

    result = usersethandle(data, user["token"], handle_used)
    assert result == {'ValueError': "handle is already used by another user"}

    result = usersethandle(data, 'token_not_registed', handle_normal)
    assert result == {'ValueError': 'token not valid'}

    # Valid input
    usersethandle(data, user["token"], 'testing')
    result = getprofile(data, user["token"], user["u_id"], host)
    assert result["handle_str"] == 'testing'
    '''
示例#4
0
def generate_data():
    test_data = Data()
    user_admin = register(test_data, '*****@*****.**', 'password',
                          'name_first1', 'name_last', 'http://127.0.0.1:5555/')
    user_channel_owner = register(test_data, '*****@*****.**', 'password',
                                  'name_first2', 'name_last',
                                  'http://127.0.0.1:5555/')
    user_in_channel = register(test_data, '*****@*****.**', 'password',
                               'name_first4', 'name_last',
                               'http://127.0.0.1:5555/')
    user_notin_channel = register(test_data, '*****@*****.**', 'password',
                                  'name_first3', 'name_last',
                                  'http://127.0.0.1:5555/')

    channel = ch_create(test_data, user_channel_owner['token'], 'test_channel',
                        True)
    ch_join_leave(test_data, user_admin['token'], channel['channel_id'],
                  'join')
    ch_join_leave(test_data, user_in_channel['token'], channel['channel_id'],
                  'join')

    send_message(test_data, user_in_channel['token'], channel['channel_id'],
                 'test3')
    send_message(test_data, user_channel_owner['token'], channel['channel_id'],
                 'test2')
    send_message(test_data, user_admin['token'], channel['channel_id'], 'test')

    return test_data
示例#5
0
def getdata():
    data = Data()
    ch_owner = register(data, '*****@*****.**', 'testtest', 'test', 'test',
                        'http://127.0.0.1:5555/')
    ch_member = register(data, '*****@*****.**', 'test2test2', 'test2',
                         'test2', 'http://127.0.0.1:5555/')
    register(data, '*****@*****.**', 'tests2', 'not in channel', 'test',
             'http://127.0.0.1:5555/')
    channel1 = ch_create(data, ch_owner['token'], 'ch_test', True)
    ch_join_leave(data, ch_member['token'], channel1['channel_id'], 'join')
    # data, token, channel_id, message, time_create=datetime.now()
    send_message(data, ch_owner['token'], channel1['channel_id'], 'test')
    send_message(data, ch_member['token'], channel1['channel_id'], 'test2')
    return data
示例#6
0
def auth_register():
    global data
    host = request.host_url
    email, password, name_first, name_last = do_get(
        request.form, ['email', 'password', 'name_first', 'name_last'])
    result = register(data, email, password, name_first, name_last, host)
    catch_error_and_return(result)
    save()
    return dumps(result)
示例#7
0
def test_auth_register_invalid_password():
    data = clearData()
    host = get_host()
    email = "*****@*****.**"
    password = "******"
    name_first = "hello"
    name_last = "goodbye"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    assert register_output == {'ValueError': "This password is too short"}
示例#8
0
def test_auth_register_invalid_email():
    data = clearData()
    host = get_host()
    email = "hi"
    password = "******"
    name_first = "hello"
    name_last = "goodbye"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    assert register_output == {'ValueError': "This email is not valid"}
示例#9
0
def get_data():
    test_data = Data()
    user_chowner = register(test_data, '*****@*****.**', 'password',
                            'name_first1', 'name_last',
                            'http://127.0.0.1:5555/')
    user_inch = register(test_data, '*****@*****.**', 'password',
                         'name_first2', 'name_last', 'http://127.0.0.1:5555/')
    register(test_data, '*****@*****.**', 'password', 'name_first3',
             'name_last', 'http://127.0.0.1:5555/')
    channel = ch_create(test_data, user_chowner['token'], 'test_channel', True)
    ch_join_leave(test_data, user_inch['token'], channel['channel_id'], 'join')
    message_inch = send_message(test_data, user_inch['token'],
                                channel['channel_id'], 'test2')
    message_chowner = send_message(test_data, user_chowner['token'],
                                   channel['channel_id'], 'test')
    react_unreact(test_data, user_inch['token'], message_inch['message_id'], 1,
                  'react')
    react_unreact(test_data, user_inch['token'], message_chowner['message_id'],
                  1, 'react')
    ch_create(test_data, user_chowner['token'], 'test_channel2', True)
    return test_data
示例#10
0
def auth_register():
    global data

    email = request.form.get('email')

    password = request.form.get('password')
    name_first = request.form.get('name_first')
    name_last = request.form.get('name_last')

    result = register(data, email, password, name_first, name_last)
    save()
    return dumps(result)
示例#11
0
def test_auth_register_handle():
    data = testData()
    host = get_host()
    email = "*****@*****.**"
    password = "******"
    name_first = "hello"
    name_last = "goodbye"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    check_handle = generate_handle_str(data, name_first, name_last, email)
    u_id = register_output['u_id']
    user = data.get_element('users_group', 'u_id', u_id)
    assert user.handle_str == check_handle
示例#12
0
def test_auth_register_already_user():
    data = testData()
    host = get_host()
    email = "*****@*****.**"
    password = "******"
    name_first = "hello"
    name_last = "goodbye"

    register_output = register(data, email, password, name_first, name_last,
                               host)

    assert register_output == {
        'ValueError': "This email is already in use by \
a registered user"
    }
示例#13
0
def test_profile():
    global data, host
    # Create one user for testing
    auth_key = register(data, '*****@*****.**', 'password', 'name_first',
                        'name_last', host)

    # Invalid input
    result = getprofile(data, None, None, host)
    assert result == {'ValueError': "token not valid"}

    result = getprofile(data, auth_key['token'], 'not_valid_u_id', host)
    assert result == {'ValueError': "User with u_id is not a valid user"}

    # Valid input
    result = getprofile(data, auth_key["token"], auth_key["u_id"], host)
    assert result["email"] == '*****@*****.**'
    assert result["name_first"] == 'name_first'
    assert result["name_last"] == 'name_last'
    # Assume the default handle is the first_namelast_name
    assert result["handle_str"] == 'name_firstname_last'
示例#14
0
def test_setname():
    global data, host
    data = Data()
    # create one user
    auth_key = register(data, '*****@*****.**', 'password', 'name_first',
                        'name_last', host)

    # name_first more than 50 characters but not name_last
    first_long = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    first_short = 'asdfzxcv'

    last_short = 'abcd'
    last_long = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

    # Invalid input
    result = usersetname(data, None, first_long, last_short)
    assert result == {'ValueError': "token not valid"}

    result = usersetname(data, auth_key["token"], first_long, last_short)
    assert result == {
        'ValueError': 'name_first is not between 1 and 50 \
characters in length'
    }

    result = usersetname(data, auth_key["token"], first_short, last_long)
    assert result == {
        'ValueError': 'name_last is not between 1 and 50 \
characters in length'
    }

    result = usersetname(data, 'token_not_registed', first_short, last_short)
    assert result == {'ValueError': 'token not valid'}

    # Valid input
    usersetname(data, auth_key["token"], first_short, last_short)
    result = getprofile(data, auth_key["token"], auth_key["u_id"], host)
    assert result["name_first"] == first_short
    assert result["name_last"] == last_short
示例#15
0
def test_auth_register_valid():
    data = clearData()
    host = get_host()
    email = "*****@*****.**"
    password = "******"
    name_first = "hello"
    name_last = "goodbye"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    check_token_1 = generateToken(email)

    u_id1 = register_output['u_id']
    assert register_output['token'] == check_token_1
    assert data.get_all_user_detail(host) == [{
        'u_id':
        u_id1,
        'email':
        "*****@*****.**",
        'name_first':
        "hello",
        'name_last':
        "goodbye",
        'handle_str':
        "hellogoodbye",
        'profile_img_url':
        'http://127.0.0.1:5555/static/default.jpg'
    }]
    user = data.get_element('users_group', 'u_id', u_id1)
    assert user.password == hashlib.sha256(
        "123456".encode("utf-8")).hexdigest()
    assert user.permission_id == 1

    email = "*****@*****.**"
    password = "******"
    name_first = "hellohowareyou"
    name_last = "imfinethankyou"

    register_output = register(data, email, password, name_first, name_last,
                               host)
    check_token_2 = generateToken(email)

    u_id2 = register_output['u_id']
    assert register_output['token'] == check_token_2
    assert data.get_all_user_detail(host) == [{
        'u_id':
        u_id1,
        'email':
        "*****@*****.**",
        'name_first':
        "hello",
        'name_last':
        "goodbye",
        'handle_str':
        "hellogoodbye",
        'profile_img_url':
        'http://127.0.0.1:5555/static/default.jpg'
    }, {
        'u_id':
        u_id2,
        'email':
        "*****@*****.**",
        'name_first':
        "hellohowareyou",
        'name_last':
        "imfinethankyou",
        'handle_str':
        "hellohowareyouimfine",
        'profile_img_url':
        'http://127.0.0.1:5555/static/default.jpg'
    }]
    user = data.get_element('users_group', 'u_id', u_id2)
    assert user.password == hashlib.sha256(
        "9876543".encode("utf-8")).hexdigest()
    assert user.permission_id == 3