예제 #1
0
def test_flockr_owner():
    clear()

    # Register and login the global owner
    auth_register("*****@*****.**", "password", "First", "Last")
    flockr_owner = auth_login("*****@*****.**", "password")

    # Register and login 2 other users
    auth_register("*****@*****.**", "password", "First", "Last")
    owner_1 = auth_login("*****@*****.**", "password")

    auth_register("*****@*****.**", "password", "First", "Last")
    owner_2 = auth_login("*****@*****.**", "password")

    # Create a channel for owner_1
    public = True
    owner_1_c_id = channels_create(owner_1['token'], "Channel",
                                   public)['channel_id']
    channel_join(owner_2['token'], owner_1_c_id)

    # Make owner_2 actually an owner
    channel_addowner(owner_1['token'], owner_1_c_id, owner_2['u_id'])

    # The flockr_owner removes owner_2 as an owner
    channel_removeowner(flockr_owner['token'], owner_1_c_id, owner_2['u_id'])

    details = channel_details(owner_1['token'], owner_1_c_id)
    assert len(details['owner_members']) == 1
    assert details['owner_members'][0]['u_id'] == 1
예제 #2
0
def register_login():
    # Using the clear function in the register_login fixture so it won't have to be called after
    clear()
    # registers and logs in a user
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    user = auth_login("*****@*****.**", "password")
    return {"u_id": user["u_id"], "token": user["token"]}
예제 #3
0
def register():
    # Fixture registers two users but does not log them in
    # No return value
    # Create dummy users for email testing
    clear()
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    auth_register("*****@*****.**", "password", "Angus", "Boe")
예제 #4
0
def test_flockr_owner_remover(channel_with_user):
    clear()
    # Creating the flockr owner
    auth_register("*****@*****.**", "flockr_ownerpassword",
                  "flockr_ownerFirstname", "flockr_ownerLastname")
    flockr_owner = auth_login("*****@*****.**", "flockr_ownerpassword")

    # Creating the owner and their own channel
    auth_register("*****@*****.**", "ownerpassword", "ownerFirstname",
                  "ownerLastname")
    owner = auth_login("*****@*****.**", "ownerpassword")
    public = True
    channel_id = channels_create(owner['token'], "Channel", public)

    # Creating the message via the owner
    message_id = message_send(owner['token'], channel_id['channel_id'],
                              "Test Message 1")
    message = channel_messages(owner['token'], channel_id['channel_id'],
                               0)['messages']
    # assert message == [
    #     {'message_id': 0, 'u_id': 1, 'message': 'Test Message 1', 'time_created': timestamp}
    # ]
    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 1
    assert message[0]['message'] == 'Test Message 1'

    # Removing the message via the flockr owner
    message_remove(flockr_owner['token'], message_id['message_id'])
    messages = channel_messages(owner['token'], channel_id['channel_id'],
                                0)['messages']
    assert not messages
예제 #5
0
def test_valid_firstname_onechar():
    clear()
    result = auth_register("*****@*****.**", "password", "A", "Doe")
    token = token_hash(0)
    assert result == {
        'u_id': 0,
        'token': token,
    }
예제 #6
0
def register_login():
    # Using the clear function in the register_login fixture so it won't have to be called after
    clear()
    auth_register("*****@*****.**", "password", "Richard", "Shen")
    user = auth_login("*****@*****.**", "password")
    return {
        "u_id": user["u_id"],
        "token": user["token"]
    }
예제 #7
0
def register_login_create_channel():
    clear()
    # register and login a user
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    login = auth_login("*****@*****.**", "password")
    token = login['token']

    # create channel using that user
    channels_create(token, "test channel", True)

    return token
예제 #8
0
def register_login():
    # Fixture registers a user and then logs them in
    # Returns dictionary containing their u_id and token.
    clear()
    
    # Create dummy user to make sure right user is being targetted
    auth_register("*****@*****.**", "password", "Anguss", "Doee")

    auth_register("*****@*****.**", "password", "Angus", "Doe")
    user = auth_login("*****@*****.**", "password")
    return user
예제 #9
0
def test_password_reset_invalid_password():
    clear()
    # Register a user
    auth_register("*****@*****.**", "password", "Wilson", "Doe")
    auth_login("*****@*****.**", "password")
    # Retrieve the reset code
    reset_code = encoded_resetcode("*****@*****.**")
    invalid_password = "******"
    # Fails as the password is not valid
    with pytest.raises(InputError):
        auth_passwordreset_reset(reset_code, invalid_password)
예제 #10
0
def channel_with_user():
    clear()
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user = auth_login("*****@*****.**", "password")
    public = True
    c_id = channels_create(user['token'], "Channel", public)

    return {
        'u_id': user['u_id'], 
        'token': user['token'], 
        'c_id': c_id['channel_id'],
    }
예제 #11
0
def channel_with_user():
    # A user is registered, logged in and owns a channel
    clear()
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    token = auth_login("*****@*****.**", "password")
    public = True
    c_id = channels_create(token['token'], "Channel", public)

    return {
        'u_id': token['u_id'], 
        'token': token['token'], 
        'c_id': c_id['channel_id'],
    }
예제 #12
0
def register_login():
    # A user is registered, logged in and owns a channel
    clear()

    # Dummy 
    auth_register("*****@*****.**", "password", "Antomum", "Lepejian")

    auth_register("*****@*****.**", "password", "Anto", "Lepejian")
    owner = auth_login("*****@*****.**", "password")

    return {
        'u_id': owner['u_id'], 
        'token': owner['token'],
    }
예제 #13
0
def test_success_one_user():
    clear()
    auth_register("*****@*****.**", "pass123", "Wilson", "Doe")
    user = auth_login("*****@*****.**", "pass123")
    display_users = users_all(user['token'])
    assert display_users == {
        'users': [{
            'u_id': 0,
            'email': '*****@*****.**',
            'name_first': 'Wilson',
            'name_last': 'Doe',
            'handle_str': 'wilsondoe',
            'profile_img_url': 'default.jpg'
        }]
    }
예제 #14
0
def test_valid_email():
    clear()
    result = auth_register("*****@*****.**", "password", "Angus", "Doe")
    token = token_hash(0)
    assert result == {
        'u_id': 0,
        'token': token,
    }
    # Testing same concatenation of first & last name to see if unique handle
    # can be generated.
    result = auth_register("*****@*****.**", "password", "Angus", "Doe")
    token = token_hash(1)
    assert result == {
        'u_id': 1,
        'token': token,
    }
예제 #15
0
def register_login():
    clear()
    
    # Create a user who is flockr owner and is creating the channel
    auth_register("*****@*****.**", "password", "Richard", "Shen")
    user = auth_login("*****@*****.**", "password")
    is_public = True
    channel_id = channels_create(user['token'], "Channel", is_public)
    '''
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user2 = auth_login("*****@*****.**", "password2")
    channel_join(user2['token'], channel_id['channel_id'])
    '''
    return {
        'token': user['token'],
        'channel_id': channel_id['channel_id'], 
    }
예제 #16
0
def register_2_users_channel():
    clear()

    # Create a dummy channel for coverage where code loops through channels
    owner = auth_register("*****@*****.**", "password", "Angus", "Doe")
    channels_create(owner['token'], "Dummy Channel", True)

    # Create a user who is flockr owner and is creating the channel
    c_id = channels_create(owner['token'], "Channel", True)

    member = auth_register("*****@*****.**", "password", "Bungus", "Two")
    channel_join(member['token'], c_id['channel_id'])

    return {
        'c_id': c_id['channel_id'],
        'owner': owner,
        'member': member,
    }
예제 #17
0
def test_password_reset_success():
    clear()
    # Register 2 users for coverage
    auth_register("*****@*****.**", "password", "Wilson", "Doe")['u_id']
    auth_register("*****@*****.**", "password", "Wilson", "Doe")['u_id']
    user = auth_login("*****@*****.**", "password")

    # Retrieve the reset code
    reset_code = encoded_resetcode("*****@*****.**")
    # Reset the password
    auth_passwordreset_reset(reset_code, "newpassword")
    # Assert that the new password is updated by checking if the hashed versions are the same

    auth_logout(user['token'])
    user = auth_login("*****@*****.**", "newpassword")
    assert user == {
        'u_id': 1,
        'token': user['token'],
    }
예제 #18
0
def channel_user_message():
    clear()
    flockr_owner = auth_register("*****@*****.**", "password", "John",
                                 "Doe")

    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    owner = auth_login("*****@*****.**", "password")

    public = True
    c_id = channels_create(owner['token'], "Channel", public)
    message = message_send(owner['token'], c_id['channel_id'],
                           "Test Message 1")

    return {
        'u_id': owner['u_id'],
        'token': owner['token'],
        'flockr_owner_token': flockr_owner['token'],
        'c_id': c_id['channel_id'],
        'message_id': message['message_id']
    }
예제 #19
0
def channel_with_2_owners():
    clear()

    # The first user is automatically an owner
    auth_register("*****@*****.**", "password", "First", "Last")
    token_1 = auth_login("*****@*****.**", "password")
    public = True

    # Create user and channel to be ignored but to pass authorised user
    auth_register("*****@*****.**", "password", "John", "Doe")
    ignore_me = auth_login("*****@*****.**", "password")
    channels_create(ignore_me['token'], "Ignore Me", public)

    c_id = channels_create(token_1['token'], "Channel", public)

    # The second user is made an owner for test purposes
    auth_register("*****@*****.**", "password2", "First2", "Last2")
    token_2 = auth_login("*****@*****.**", "password2")
    channel_join(token_2['token'], c_id['channel_id'])
    channel_addowner(token_1['token'], c_id['channel_id'], token_2['u_id'])

    return {'token_1': token_1, 'c_id': c_id, 'token_2': token_2}
예제 #20
0
def test_invalid_email_no_com():
    clear()
    with pytest.raises(InputError):
        auth_register("testemail@gmail", "password", "Angus", "Doe")
예제 #21
0
def register_login():
    clear()
    auth_register("*****@*****.**", "password", "John", "Doe")
    user = auth_login("*****@*****.**", "password")

    return user
예제 #22
0
def register_and_login_user():
    clear()
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    login = auth_login("*****@*****.**", "password")
    token = login['token']
    return token
예제 #23
0
def register_login():
    clear()
    auth_register("*****@*****.**", "password", "Richard", "Shen")
    token = auth_login("*****@*****.**", "password")
    return token
예제 #24
0
def test_email_exists():
    clear()
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    with pytest.raises(InputError):
        auth_register("*****@*****.**", "password", "Angus", "Doe 2nd")
예제 #25
0
def test_password_reset_invalid_code():
    clear()
    invalid_code = encoded_resetcode("*****@*****.**")
    # Fails as the reset code is not valid due to the email belonging to an unregistered user
    with pytest.raises(InputError):
        auth_passwordreset_reset(invalid_code, "newpassword")
예제 #26
0
def test_pw_under_six():
    clear()
    with pytest.raises(InputError):
        auth_register("*****@*****.**", "pw", "Angus", "Doe")
예제 #27
0
def test_invalid_firstname():
    clear()
    with pytest.raises(InputError):
        auth_register("*****@*****.**", "password", "", "Doe")
예제 #28
0
def test_invalid_lastname_long():
    clear()
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    with pytest.raises(InputError):
        auth_register("*****@*****.**", "password", "Angus",
                      "This is over 50 charactersThis is over 50characters")
예제 #29
0
def test_fail():
    clear()
    auth_register("*****@*****.**", "password", "Wilson", "Doe")
    auth_login("*****@*****.**", "password")
    with pytest.raises(AccessError):
        users_all(token_hash(1))
예제 #30
0
def register_new_user():
    clear()
    auth_register("*****@*****.**", "password", "Wilson", "Doe")
    user = auth_login("*****@*****.**", "password")
    return user