Example #1
0
def test_invalid_c_id(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user

    invalid_c_id = -1
    with pytest.raises(InputError):
        standup_send(sender['token'], invalid_c_id, "Invalid Channel ID")
Example #2
0
def test_inactive_standup(channel_with_user):
    sender = channel_with_user

    standup = standup_active(sender['token'], sender['c_id'])
    assert not standup['is_active']

    with pytest.raises(InputError):
        standup_send(sender['token'], sender['c_id'], "Test Message")
Example #3
0
def test_invalid_message_1001(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user

    invalid_message = "*" * 1001
    assert len(invalid_message) == 1001

    with pytest.raises(InputError):
        standup_send(sender['token'], sender['c_id'], invalid_message)
Example #4
0
def test_external_user(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user

    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    member = auth_login("*****@*****.**", "password")
    
    sender_channel = channel_details(sender['token'], sender['c_id'])
    assert member['u_id'] not in sender_channel['all_members']

    with pytest.raises(AccessError):
        standup_send(member['token'], sender['c_id'], "Test Message")
Example #5
0
def test_standup_send_1000(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user
    valid_message = "*" * 1000

    standup_send(sender['token'], sender['c_id'], valid_message)

    until_standup_finishes = 2 # seconds
    sleep(until_standup_finishes)

    messages = channel_messages(sender['token'], sender['c_id'], 0)['messages']
    handle_str = user_profile(sender['token'], sender['u_id'])['user']['handle_str']

    assert messages[0]['message'] == f"{handle_str}: {valid_message}"
Example #6
0
def test_standup_send_multiple(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user

    standup_send(sender['token'], sender['c_id'], "Test Message 1")
    standup_send(sender['token'], sender['c_id'], "Test Message 2")

    until_standup_finishes = 2 # seconds
    sleep(until_standup_finishes)

    messages = channel_messages(sender['token'], sender['c_id'], 0)['messages']
    handle_str = user_profile(sender['token'], sender['u_id'])['user']['handle_str']
    standup_messages = f"{handle_str}: Test Message 1\n" + f"{handle_str}: Test Message 2"

    assert messages[0]['message'] == standup_messages
Example #7
0
def standup_send_flask():
    payload = request.get_json()

    token = payload['token']
    channel_id = payload['channel_id']
    message = payload['message']

    return dumps(s.standup_send(token, channel_id, message))
Example #8
0
def test_standup_send_member(channel_with_user, standup):
    assert standup['is_active']
    owner = channel_with_user
    
    # Login and register another user who will send the message
    auth_register('*****@*****.**', 'password', 'name_first', 'name_last')
    member = auth_login('*****@*****.**', 'password')
    channel_join(member['token'], owner['c_id'])

    standup_send(member['token'], owner['c_id'], "Member Message")

    until_standup_finishes = 2 # seconds
    sleep(until_standup_finishes)

    messages = channel_messages(member['token'], owner['c_id'], 0)['messages']
    handle_str = user_profile(member['token'], member['u_id'])['user']['handle_str']

    assert messages[0]['message'] == f"{handle_str}: Member Message"
Example #9
0
def test_invalid_token(channel_with_user, standup):
    sender = channel_with_user
    assert standup['is_active']
    invalid_token = token_hash(-1)
    with pytest.raises(AccessError):
        standup_send(invalid_token, sender['c_id'], "Invalid Token")