Esempio n. 1
0
def test_passwordreset_request_invalid_email():
    clear()
    register_n_users(1)
    invalid_email = "12345"

    with pytest.raises(InputError):
        auth_passwordreset_request(invalid_email)
Esempio n. 2
0
def test_handle_too_long():
    clear()
    user = register_n_users(1)

    # set a long handle name
    with pytest.raises(InputError):
        user_profile_sethandle(user["token"], "Whymynamesolonghahahahhahahaha")
Esempio n. 3
0
def test_setemail_successful():
    clear()
    user_a = register_n_users(1)
    user_profile_setemail(user_a["token"], "*****@*****.**")
    user_a_profile = user_profile(user_a["token"], user_a["u_id"])["user"]

    assert user_a_profile["email"] == "*****@*****.**"
Esempio n. 4
0
def test_react_succesfully():
    clear()
    user_a, user_b = register_n_users(2)
    public_channel_id = channels_create(user_a["token"], "public_channel",
                                        True)["channel_id"]
    # user_b join the channel created by user_a
    channel_join(user_b["token"], public_channel_id)
    message_id = message_send(user_a["token"], public_channel_id,
                              "Nice to see you mate")["message_id"]

    # user_a react to his own message
    message_react(user_a["token"], message_id, 1)

    # Message from the perspective of user_a
    message_a = channel_messages(user_a["token"], public_channel_id,
                                 0)["messages"][0]
    # user_a reacted
    assert message_a["reacts"][0]["is_this_user_reacted"] == True
    assert user_a["u_id"] in message_a["reacts"][0]["u_ids"]

    # Message from the perspective of user_b
    message_b = channel_messages(user_b["token"], public_channel_id,
                                 0)["messages"][0]
    # user_b haven't reacted
    assert message_b["reacts"][0]["is_this_user_reacted"] == False
    # user_b react to the message
    message_react(user_b["token"], message_id, 1)
    message_b = channel_messages(user_b["token"], public_channel_id,
                                 0)["messages"][0]
    assert message_b["reacts"][0]["is_this_user_reacted"] == True
    assert user_b["u_id"] in message_b["reacts"][0]["u_ids"]
Esempio n. 5
0
def test_empty_name():
    clear()

    user = register_n_users(1)
    channel_id = channels_create(user["token"], "", is_public=True)["channel_id"]
    details = channel_details(user["token"], channel_id)
    assert details["name"] == "new_channel"
Esempio n. 6
0
def test_create_simple():
    clear()
    user = register_n_users(1)
    channel = channels_create(user["token"], "channel_name", is_public=True)

    details = channel_details(user["token"], channel["channel_id"])
    assert details["name"] == "channel_name"
Esempio n. 7
0
def test_handle_too_short():
    clear()
    user = register_n_users(1)

    # set a short handle name
    with pytest.raises(InputError):
        user_profile_sethandle(user["token"], "ha")
Esempio n. 8
0
def test_standup_start_invalid_channel_id():
    clear()
    user1 = register_n_users(1)

    invalid_channel_id = -1
    with pytest.raises(InputError):
        standup_start(user1["token"], invalid_channel_id, 1)
Esempio n. 9
0
def test_sendlater_invalid_token():
    clear()
    user = register_n_users(1)
    channel_id = channels_create(user["token"], "name",
                                 is_public=True)["channel_id"]
    with pytest.raises(AccessError):
        message_sendlater(-1, channel_id, "message", time.time() + 2)
Esempio n. 10
0
def test_join_channel_with_invalid_channel_id():
    clear()
    user = register_n_users(1)
    invalid_channel_id = 233

    with pytest.raises(InputError):
        channel_join(user["token"], invalid_channel_id)
Esempio n. 11
0
def test_passwordreset_reset_success_multiple_users():
    clear()
    user1, user2 = register_n_users(2)

    # User 1 Data
    user1_data = auth_get_user_data_from_id(user1["u_id"])
    u_id_1 = user1_data["id"]
    email_1 = user1_data["email"]

    # User 2 Data
    user2_data = auth_get_user_data_from_id(user2["u_id"])
    u_id_2 = user2_data["id"]
    email_2 = user2_data["email"]

    # Logout
    assert auth_logout(user1["token"])["is_success"] == True
    assert auth_logout(user2["token"])["is_success"] == True

    # Reset password
    auth_passwordreset_request(email_1)
    auth_passwordreset_request(email_2)
    reset_code_1 = get_reset_code_from_user_id(u_id_1)
    reset_code_2 = get_reset_code_from_user_id(u_id_2)
    new_password_1 = "NewPassword123"
    new_password_2 = "NewPassword124"
    auth_passwordreset_reset(reset_code_2, new_password_2)
    auth_passwordreset_reset(reset_code_1, new_password_1)

    # Assert user can login with new password
    assert auth_login(email_1, new_password_1)["token"]
    assert auth_login(email_2, new_password_2)["token"]
Esempio n. 12
0
def test_channel_invite_member_already_in_channel():
    clear()
    usera, userb = register_n_users(2)
    channel_id = channels_create(userb["token"], "userb_channel",
                                 True)["channel_id"]

    usera_info = {
        "u_id":
        usera["u_id"],
        "name_first":
        auth_get_user_data_from_id(usera["u_id"])["first_name"],
        "name_last":
        auth_get_user_data_from_id(usera["u_id"])["last_name"],
        "profile_img_url":
        auth_get_user_data_from_id(usera["u_id"])["profile_img_url"],
    }

    channel_join(usera["token"], channel_id)
    channel_invite(userb["token"], channel_id, usera["u_id"])
    channel_members_info = channel_details(userb["token"],
                                           channel_id)["all_members"]

    usera_count = 0
    for user in channel_members_info:
        if user == usera_info:
            usera_count = usera_count + 1
    assert usera_count == 1
Esempio n. 13
0
def test_passwordreset_reset_request_twice():
    clear()
    user = register_n_users(1)

    # Logout, assert that user can login with old password, then logout again
    assert auth_logout(user["token"])["is_success"] == True

    user_data = auth_get_user_data_from_id(user["u_id"])
    u_id = user_data["id"]
    email = user_data["email"]
    old_password = "******"

    token = auth_login(email, old_password)["token"]
    assert auth_logout(token)["is_success"] == True

    # Ask for a reset code twice
    auth_passwordreset_request(email)
    reset_code_1 = get_reset_code_from_user_id(u_id)
    auth_passwordreset_request(email)
    reset_code_2 = get_reset_code_from_user_id(u_id)

    # The reset codes should be unique
    assert reset_code_1 != reset_code_2

    # Assert user cannot login with old reset code
    new_password = "******"
    with pytest.raises(InputError):
        assert auth_passwordreset_reset(reset_code_1, new_password)

    # Assert user can reset password with new reset code
    auth_passwordreset_reset(reset_code_2, new_password)

    # Assert user can login with new password
    token = auth_login(email, new_password)["token"]
    auth_logout(token)
Esempio n. 14
0
def test_passwordreset_request_success():
    clear()
    user = register_n_users(1)
    user = auth_get_user_data_from_id(user["u_id"])
    auth_passwordreset_request(user["email"])

    assert contains_reset_code(user) == True
Esempio n. 15
0
def test_channel_invite_simple():
    clear()
    usera, userb = register_n_users(2)
    channel_id = channels_create(userb["token"], "userb_channel",
                                 False)["channel_id"]

    usera_info = {
        "u_id":
        usera["u_id"],
        "name_first":
        auth_get_user_data_from_id(usera["u_id"])["first_name"],
        "name_last":
        auth_get_user_data_from_id(usera["u_id"])["last_name"],
        "profile_img_url":
        auth_get_user_data_from_id(usera["u_id"])["profile_img_url"],
    }

    channel_members_info = channel_details(userb["token"],
                                           channel_id)["all_members"]
    assert usera_info not in channel_members_info

    channel_invite(userb["token"], channel_id, usera["u_id"])
    updated_channel_members_info = channel_details(userb["token"],
                                                   channel_id)["all_members"]
    assert usera_info in updated_channel_members_info
Esempio n. 16
0
def test_passwordreset_reset_success():
    clear()
    user = register_n_users(1)

    # Logout, assert that user can login with old password, then logout again
    assert auth_logout(user["token"])["is_success"] == True

    user_data = auth_get_user_data_from_id(user["u_id"])
    u_id = user_data["id"]
    email = user_data["email"]
    old_password = "******"

    token = auth_login(email, old_password)["token"]
    assert auth_logout(token)["is_success"] == True

    # Reset password
    auth_passwordreset_request(email)
    reset_code = get_reset_code_from_user_id(u_id)
    new_password = "******"
    auth_passwordreset_reset(reset_code, new_password)

    # Assert user can login with new password
    token = auth_login(email, new_password)["token"]

    # Ensure user cannot login with old password
    auth_logout(token)
    with pytest.raises(InputError):
        assert auth_login(email, old_password)
Esempio n. 17
0
def test_channel_join_multiple_channels():
    clear()
    usera, userb, userc = register_n_users(3)
    channel_id_a = channels_create(usera["token"], "channela",
                                   is_public=True)["channel_id"]
    channel_id_b = channels_create(userb["token"], "channelb",
                                   is_public=True)["channel_id"]
    channel_id_c = channels_create(userc["token"], "channelc",
                                   is_public=True)["channel_id"]

    channel_join(usera["token"], channel_id_b)
    channel_join(usera["token"], channel_id_c)
    channel_join(userb["token"], channel_id_c)

    # usera should be able to get all the details since the channels are public
    detailsa = channel_details(usera["token"], channel_id_a)
    detailsb = channel_details(usera["token"], channel_id_b)
    detailsc = channel_details(usera["token"], channel_id_c)

    # there should still be only one owner
    assert_contains_users_id(detailsa["owner_members"], [usera["u_id"]])
    assert_contains_users_id(detailsb["owner_members"], [userb["u_id"]])
    assert_contains_users_id(detailsc["owner_members"], [userc["u_id"]])

    assert_contains_users_id(detailsa["all_members"], [usera["u_id"]])
    assert_contains_users_id(detailsb["all_members"],
                             [usera["u_id"], userb["u_id"]])
    assert_contains_users_id(detailsc["all_members"],
                             [usera["u_id"], userb["u_id"], userc["u_id"]])
Esempio n. 18
0
def test_passwordreset_reset_success_twice():
    clear()
    user = register_n_users(1)

    # Logout, assert that user can login with old password, then logout again
    assert auth_logout(user["token"])["is_success"] == True

    user_data = auth_get_user_data_from_id(user["u_id"])
    u_id = user_data["id"]
    email = user_data["email"]
    old_password = "******"

    token = auth_login(email, old_password)["token"]
    assert auth_logout(token)["is_success"] == True

    # Reset password
    auth_passwordreset_request(email)
    reset_code_1 = get_reset_code_from_user_id(u_id)
    new_password = "******"
    auth_passwordreset_reset(reset_code_1, new_password)

    # Assert user can login with new password
    token = auth_login(email, new_password)["token"]
    auth_logout(token)

    # Reset password again and try to login with 2nd new password
    auth_passwordreset_request(email)
    reset_code_2 = get_reset_code_from_user_id(u_id)
    assert reset_code_1 != reset_code_2
    new_password_2 = "NewPassword124"
    auth_passwordreset_reset(reset_code_2, new_password_2)

    token = auth_login(email, new_password_2)["token"]
Esempio n. 19
0
def test_sendlater_single():
    clear()
    # setup
    user = register_n_users(1)
    channel_id = channels_create(user["token"], "name",
                                 is_public=True)["channel_id"]

    # send message with delay
    send_at = int(round(time.time() + 1 * DELAY_SCALE))
    message_sendlater(user["token"], channel_id, "message", send_at)

    # make sure there are now messages
    messages = channel_messages(user["token"], channel_id, start=0)
    assert int(round(time.time())) < send_at, ERR_TOO_SLOW
    assert len(messages["messages"]) == 0

    # wait for the message to be sent
    time.sleep(2)

    # check that the message is there
    messages = channel_messages(user["token"], channel_id, start=0)
    assert len(messages["messages"]) == 1
    assert messages["messages"][0]["message"] == "message"

    # if this fails, there has been a time difference of more than half a second
    # time.time() is a float, and floats shouldn't be compared with ==
    assert messages["messages"][0]["time_created"] - send_at <= 1
Esempio n. 20
0
def test_standup_start_simple():
    clear()
    user1, user2 = register_n_users(2)

    # Create channel and join
    channel = channels_create(user1["token"], "channel1", is_public=True)
    channel_join(user2["token"], channel["channel_id"])

    # Start the standup period
    standup = standup_start(user1["token"], channel["channel_id"], 1)
    assert standup["time_finish"] == round(time() + 1)

    # Send two standup message
    standup_send(user1["token"], channel["channel_id"], "test1")
    standup_send(user2["token"], channel["channel_id"], "test2")

    # Assert the messages are empty
    messages = channel_messages(user1["token"], channel["channel_id"],
                                0)["messages"]
    assert len(messages) == 0

    # Assert the two message has been sent when the standup period finishes
    sleep(2)
    messages = channel_messages(user1["token"], channel["channel_id"],
                                0)["messages"]
    assert len(messages) == 1

    user1_profile = user_profile(user1["token"], user1["u_id"])["user"]
    user1_handle = user1_profile["handle_str"]
    user2_handle = user_profile(user2["token"],
                                user2["u_id"])["user"]["handle_str"]
    assert messages[0][
        "message"] == f"{user1_handle}: test1\n{user2_handle}: test2"
    assert messages[0]["u_id"] == user1_profile["u_id"]
Esempio n. 21
0
def test_channel_invite_invalid_id():
    clear()
    user = register_n_users(1)
    channel_id = channels_create(user["token"], "ch",
                                 is_public=False)["channel_id"]

    with pytest.raises(InputError):
        channel_invite(user["token"], channel_id, u_id=-1)
def test_admin_userpermission_change_successful():
    clear()
    admin, usera, userb = register_n_users(3, include_admin=True)

    admin_userpermission_change(admin["token"], usera["u_id"], 1)

    # usera should now be able to change other people's permission
    admin_userpermission_change(usera["token"], userb["u_id"], 2)
Esempio n. 23
0
def create_channel():
    clear()
    user = register_n_users(1)
    # Create a channel and send a message
    channel = channels_create(user["token"], "channel_01", is_public=True)
    message = message_send(user["token"], channel["channel_id"], "test")

    return [user, channel, message]
Esempio n. 24
0
def test_sethandle_successful():
    clear()
    user_a = register_n_users(1)

    # Set a new handle name as JOJOKING
    user_profile_sethandle(user_a["token"], "JOJOKING")
    user_a_profile = user_profile(user_a["token"], user_a["u_id"])["user"]
    assert user_a_profile["handle_str"] == "JOJOKING"
Esempio n. 25
0
def test_channel_invite_from_unauthorised_user():
    clear()
    usera, userb = register_n_users(2)
    channel_id = channels_create(userb["token"], "userb_channel",
                                 False)["channel_id"]

    with pytest.raises(AccessError):
        assert channel_invite(usera["token"], channel_id, userb["u_id"])
Esempio n. 26
0
def test_leave_channel_id_invalid():
    clear()
    user = register_n_users(1)
    channel_id = channels_create(user["token"], "channel_A", True)["channel_id"]
    invalid_channel_id = channel_id + 1

    with pytest.raises(InputError):
        channel_leave(user["token"], invalid_channel_id)
Esempio n. 27
0
def test_standup_send_no_active_standup():
    clear()
    user1 = register_n_users(1)

    channel = channels_create(user1["token"], "channel1", is_public=True)

    with pytest.raises(InputError):
        standup_send(user1["token"], channel["channel_id"], "Test")
Esempio n. 28
0
def test_join_channel_without_authority():
    clear()
    user_A, user_B = register_n_users(2)
    channel = channels_create(user_A["token"], "Private_channel",
                              False)  # Create a new private channel

    with pytest.raises(AccessError):
        channel_join(user_B["token"], channel["channel_id"])
Esempio n. 29
0
def test_messages_start_overflow():
    clear()
    user = register_n_users(1)
    channel = channels_create(user["token"], "channel_01", is_public=True)
    channel_join(user["token"], channel["channel_id"])
    message_send(user["token"], channel["channel_id"], "Hello World!")
    with pytest.raises(InputError):
        assert channel_messages(user["token"], channel["channel_id"], 100)
Esempio n. 30
0
def test_add_owner_with_invalid_channel_id():
    clear()
    user_A, user_B = register_n_users(2)
    public_channel = channels_create(user_A["token"], "public_channel", True)
    channel_join(user_B["token"], public_channel["channel_id"])
    with pytest.raises(InputError):
        invalid_channel_id = 233
        channel_addowner(user_A["token"], invalid_channel_id, user_B["u_id"])