Example #1
0
def test_message_send_no_permission():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    channels.channels_create(owner['token'], "Test_channel", False)
    channel.channel_leave(owner['token'], 1)
    with pytest.raises(AccessError):
        message.message_send(owner['token'], 1, "Test message")
Example #2
0
def test_channels_listall_empty():
    reset_data()
    # Creating the user
    user_info = auth_register('*****@*****.**', 'sadsad', 'name', 'lastname')
    assert channels_listall(user_info['token']) == {
        'channels': [],
    }
Example #3
0
def test_message_edit_empty_message():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    channels.channels_create(owner['token'], "Test_channel", True)
    message.message_send(owner['token'], 1, "test")
    assert message.message_edit(owner['token'], 1, "") == \
        message.message_remove(owner['token'], 1)
Example #4
0
def test_standup_send_no_active_standup():
    reset_data()
    member = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    channels_create(member['token'], 'Channel', True)

    with pytest.raises(InputError):
        standup_send(member['token'], 1, 'a')
Example #5
0
def test_guess_word():
    reset_data()
    data = get_data()
    user = auth_register('*****@*****.**', 'ilovecse', 'Jiaqi', 'Zhu')
    test_channel = channels_create(user['token'], 'test channel 1', True)
    hangman_package = {
        'channel_id': test_channel['channel_id'],
        'is_active': True,
        'guessed': False,
        'word': 'hello',
        'letters_guessed': [],
        'tries': 10
    }
    data['hangman'].append(hangman_package)
    check_word(user['token'], 'a', 1)
    check_word(user['token'], 'b', 1)
    check_word(user['token'], 'c', 1)
    check_word(user['token'], 'e', 1)
    check_word(user['token'], 'd', 1)
    check_word(user['token'], 'o', 1)
    check_word(user['token'], 't', 1)
    check_word(user['token'], 'n', 1)
    check_word(user['token'], 'k', 1)
    check_word(user['token'], 'm', 1)
    check_word(user['token'], 'p', 1)
    assert check_word(user['token'], 'q', 1) == '\n_e__o\nYou have run out of guesses and you haven\'t guessed the word. :(\nThe word is hello.\n_ _ _ \n |' + ' ' + ' | \n  |  O \n  | /|\ \n  | / \ \n|_ \n'
Example #6
0
def test_standup_send_complex():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'a', 'A')
    member2 = auth_register('*****@*****.**', 'thisisfun', 'b', 'B')
    member3 = auth_register('*****@*****.**', 'iamrobbie', 'c', 'C')
    channel = channels_create(member1['token'], 'Hey Channel', True)
    channel_id = channel['channel_id']
    channel_join(member2['token'], channel_id)
    channel_join(member3['token'], channel_id)
    standup_start(member1['token'], channel_id, 1)
    assert standup_send(member1['token'], channel_id, '1\nSTOP') == {}
    assert standup_send(member2['token'], channel_id, '2\nSTOP') == {}
    assert standup_send(member3['token'], channel_id, '3\nSTOP') == {}
    sleep(1.1)
    tmp = channel_messages(member1['token'], channel_id, 0)
    message = tmp['messages'][0]
    timestamp = message['time_created']
    assert channel_messages(member1['token'], channel_id, 0) == {
        'messages': [
            {
                'message_id': 1,
                'u_id': 1,
                'message': 'aa: 1\nSTOP\nbb: 2\nSTOP\ncc: 3\nSTOP',
                'time_created': timestamp
            },
            ],
        'start': 0,
        'end': -1,
        }
Example #7
0
def test_search_excluded():
    reset_data()
    user1_info = auth_register('*****@*****.**', '123456', 'aName', 'aLastname')
    user2_info = auth_register('*****@*****.**', '654321', 'bName', 'bLastname')
    # Creating the channel
    channels_create(user1_info['token'], 'a', True)
    channels_create(user2_info['token'], 'a', True)
    # User 1 & 2 messaging their respective channels
    message_send(user1_info['token'], 1, "hello there my name is User1")
    message_send(user2_info['token'], 2, "hello User1 my name is User2")
    message_send(user1_info['token'], 1, "hello anyone there?")
    # Finding a timestamp
    tmp = channel_messages(user1_info['token'], 1, 0)
    message1 = tmp['messages'][1]
    timestamp1 = message1['time_created']
    message2 = tmp['messages'][0]
    timestamp2 = message2['time_created']
    # Giving all messages containing the query string
    assert search(user1_info['token'], "hello") == {
        'messages': [
            {
                'message_id': 3,
                'u_id': 1,
                'message': 'hello anyone there?',
                'time_created': timestamp2,
            },
            {
                'message_id': 1,
                'u_id': 1,
                'message': 'hello there my name is User1',
                'time_created': timestamp1,
            },
        ],
    }
Example #8
0
def test_game_already_active():
    reset_data()
    user = auth_register('*****@*****.**', 'ilovecse', 'Jiaqi', 'Zhu')
    test_channel = channels_create(user['token'], 'test channel 1', True)
    start_game(user['token'], test_channel['channel_id'])
    with pytest.raises(AccessError):
        start_game(user['token'], test_channel['channel_id'])
Example #9
0
def test_search_multiple_channels():
    reset_data()
    user_info = auth_register('*****@*****.**', 'sadsad', 'name', 'lastname')
    # Creating the channel
    channels_create(user_info['token'], 'a', True)
    channels_create(user_info['token'], 'b', True)
    # Messaging the channel
    message_send(user_info['token'], 1, "hello there my name is John")
    message_send(user_info['token'], 2, "hello there my name is John")
    # Finding a timestamp
    tmp = channel_messages(user_info['token'], 1, 0)
    message1 = tmp['messages'][0]
    timestamp1 = message1['time_created']
    tmp2 = channel_messages(user_info['token'], 2, 0)
    message2 = tmp2['messages'][0]
    timestamp2 = message2['time_created']
    # Giving all messages containing the query string
    assert search(user_info['token'], "hello") == {
        'messages': [
            {
                'message_id': 2,
                'u_id': 1,
                'message': 'hello there my name is John',
                'time_created': timestamp2,
            },
            {
                'message_id': 1,
                'u_id': 1,
                'message': 'hello there my name is John',
                'time_created': timestamp1,
            },
        ],
    }
Example #10
0
def test_users_all_complex():
    reset_data()
    user1_info = auth_register('*****@*****.**', 'sadsad', 'aName', 'aLastname')
    auth_register('*****@*****.**', 'sadsad', 'bName', 'bLastname')
    auth_register('*****@*****.**', 'sadsad', 'cName', 'cLastname')
    # Giving all the users' profile details
    assert users_all(user1_info['token']) == {
        'users': [{
            'u_id': 1,
            'email': '*****@*****.**',
            'name_first': 'aName',
            'name_last': 'aLastname',
            'handle_str': 'anamealastname',
        }, {
            'u_id': 2,
            'email': '*****@*****.**',
            'name_first': 'bName',
            'name_last': 'bLastname',
            'handle_str': 'bnameblastname',
        }, {
            'u_id': 3,
            'email': '*****@*****.**',
            'name_first': 'cName',
            'name_last': 'cLastname',
            'handle_str': 'cnameclastname',
        }],
    }
Example #11
0
def test_search_empty():
    reset_data()
    user_info = auth_register('*****@*****.**', 'sadsad', 'name', 'lastname')
    # Giving all messages containing the query string
    assert search(user_info['token'], "search") == {
        'messages': [],
    }
Example #12
0
def test_users_all_logged_out():
    reset_data()
    user1_info = auth_register('*****@*****.**', 'sadsad', 'aName', 'aLastname')
    user2_info = auth_register('*****@*****.**', 'sadsad', 'bName', 'bLastname')
    # User2 logs out
    auth_logout(user2_info['token'])
    # Giving all the users' profile details
    assert users_all(user1_info['token']) == {
        'users': [
            {
                'u_id': 1,
                'email': '*****@*****.**',
                'name_first': 'aName',
                'name_last': 'aLastname',
                'handle_str': 'anamealastname',
            },
            {
                'u_id': 2,
                'email': '*****@*****.**',
                'name_first': 'bName',
                'name_last': 'bLastname',
                'handle_str': 'bnameblastname',
            },
        ],
    }
Example #13
0
def test_message_remove_not_owner_but_sender():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    channels.channels_create(owner['token'], "Test_channel", True)
    message.message_send(owner['token'], 1, "test")
    channel.channel_removeowner(owner['token'], 1, 1)
    assert message.message_remove(owner['token'], 1) == {}
Example #14
0
def test_message_send():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    channels.channels_create(owner['token'], "Test_channel", True)
    assert message.message_send(owner['token'], 1, "test") == {
        'message_id': 1,
    }
Example #15
0
def test_start_game_success():
    reset_data()
    data = get_data()
    user = auth_register('*****@*****.**', 'ilovecse', 'Jiaqi', 'Zhu')
    test_channel = channels_create(user['token'], 'test channel 1', True)
    start_game(user['token'], test_channel['channel_id'])
    assert data['hangman'][0]['is_active'] is True
Example #16
0
def test_standup_start_complex():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'ARoy', 'Wallace')
    member2 = auth_register('*****@*****.**', 'helloworld', 'BRoy', 'Wallace')
    test_channel = channels_create(member1['token'], 'New Channel', True)
    channel_id = test_channel['channel_id']
    channel_join(member2['token'], channel_id)

    standup_start(member2['token'], channel_id, 1)
    standup_send(member1['token'], channel_id, 'Standup message1')
    standup_send(member2['token'], channel_id, 'Standup message2')
    sleep(1.1)
    tmp = channel_messages(member1['token'], channel_id, 0)
    message = tmp['messages'][0]
    timestamp = message['time_created']
    assert channel_messages(member2['token'], channel_id, 0) == {
        'messages': [
            {
                'message_id': 1,
                'u_id': 2,
                'message': 'aroywallace: Standup message1\nbroywallace: Standup message2',
                'time_created': timestamp
            },
            ],
        'start': 0,
        'end': -1,
        }
Example #17
0
def test_channels_create_multiple_users():
    reset_data()
    # Creating multiple users
    user_info1 = auth_register('*****@*****.**', 'sadsad', 'aName', 'aLastname')
    user_info2 = auth_register('*****@*****.**', 'sadsad', 'bName', 'bLastname')
    user_info3 = auth_register('*****@*****.**', 'sadsad', 'cName', 'cLastname')
    # Creating a channel for each user
    assert channels_create(user_info1['token'], 'a', True) == {'channel_id': 1}
    assert channels_create(user_info2['token'], 'b', True) == {'channel_id': 2}
    assert channels_create(user_info3['token'], 'c', True) == {'channel_id': 3}
    assert channels_listall(user_info1['token']) == {
        'channels': [
            {
                'channel_id': 1,
                'name': 'a',
            },
            {
                'channel_id': 2,
                'name': 'b',
            },
            {
                'channel_id': 3,
                'name': 'c',
            },
        ],
    }
Example #18
0
def test_success_get_messages():
    '''test for success'''
    reset_data()
    owner = auth_register("*****@*****.**", "avengers", "Natasha",
                          "Romanova")
    test_channel = channels.channels_create(owner['token'], "Basement", True)
    u_id = owner['u_id']
    channel_id = test_channel['channel_id']
    message_1 = message_send(owner['token'], channel_id, "Hello World")
    message_2 = message_send(owner['token'], channel_id, "Yes Please")
    data = get_data()
    time1 = data['messages'][message_1['message_id'] - 1]['time_created']
    time2 = data['messages'][message_2['message_id'] - 1]['time_created']
    assert channel.channel_messages(owner['token'], channel_id, 0) == {
        'messages': [{
            'message_id': message_2['message_id'],
            'u_id': u_id,
            'message': 'Yes Please',
            'time_created': time1
        }, {
            'message_id': message_1['message_id'],
            'u_id': u_id,
            'message': 'Hello World',
            'time_created': time2
        }],
        'start':
        0,
        'end':
        -1,
    }
Example #19
0
def test_show_details_member():
    '''test for member access'''
    reset_data()
    owner = auth_register("*****@*****.**", "hellocse", "jiaqi", "zhu")
    member = auth_register("*****@*****.**", "iamrobert", "Robert", "Cad")
    member2 = auth_register("*****@*****.**", "happycse", 'Sinha', "Sc")
    test_channel = channels.channels_create(owner['token'], "New Channel",
                                            True)
    channel_id = test_channel['channel_id']
    channel.channel_join(member['token'], channel_id)
    channel.channel_join(member2['token'], channel_id)

    assert channel.channel_details(member['token'], channel_id) == {
        'name':
        'New Channel',
        'owner_members': [{
            'u_id': owner['u_id'],
            'name_first': 'jiaqi',
            'name_last': 'zhu',
        }],
        'all_members': [{
            'u_id': owner['u_id'],
            'name_first': 'jiaqi',
            'name_last': 'zhu',
        }, {
            'u_id': member['u_id'],
            'name_first': 'Robert',
            'name_last': 'Cad',
        }, {
            'u_id': member2['u_id'],
            'name_first': 'Sinha',
            'name_last': 'Sc',
        }]
    }
Example #20
0
def test_invalid_channel_id_join():
    '''test for invalid channel id'''
    reset_data()
    member = auth_register("*****@*****.**", "helloworld", "Cool", "Man")

    with pytest.raises(InputError):
        channel.channel_join(member['token'], 839)
Example #21
0
def test_invalid_channel_id_messages():
    '''test for invalid channel id'''
    reset_data()
    owner = auth_register("*****@*****.**", "avengers", "Natasha",
                          "Romanova")

    with pytest.raises(InputError):
        channel.channel_messages(owner['token'], 8333, 0)
Example #22
0
def test_invalid_u_id():
    '''test for invalid u id'''
    reset_data()
    owner = auth_register("*****@*****.**", "hellocse", "jiaqi", "zhu")
    test_channel = channels.channels_create(owner['token'], "New Channel",
                                            True)
    with pytest.raises(InputError):
        channel.channel_invite(owner['token'], test_channel['channel_id'], -8)
Example #23
0
def test_token_incorrect():
    reset_data()
    login = auth.auth_register("*****@*****.**", "123456", "Hayden",
                               "Jacobs")
    token = login['token']

    with pytest.raises(AccessError):
        user.user_profile("".join((token, 'wrong')), "u_id")
Example #24
0
def test_message_remove_already_removed():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "123456", "Sinha", "Nawa")
    channels.channels_create(owner['token'], "Test_channel", True)
    message.message_send(owner['token'], 1, "test")
    message.message_remove(owner['token'], 1)
    with pytest.raises(InputError):
        message.message_remove(owner['token'], 1)
Example #25
0
def test_standup_send_long_message():
    reset_data()
    member = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    channel_id = channels_create(member['token'], 'Channel', True)
    standup_start(member['token'], channel_id['channel_id'], 3)

    with pytest.raises(InputError):
        standup_send(member['token'], 1, 'a'*1001)
Example #26
0
def test_sethandle_empty():
    reset_data()
    login = auth.auth_register("*****@*****.**", "123456", "Hayden",
                               "Jacobs")

    token = login['token']
    with pytest.raises(InputError):
        user.user_profile_sethandle(token, "")
Example #27
0
def test_standup_start_already_active():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    test_channel = channels_create(member1['token'], 'New Channel', True)
    standup_start(member1['token'], test_channel['channel_id'], 10)

    with pytest.raises(InputError):
        standup_start(member1['token'], test_channel['channel_id'], 6)
Example #28
0
def test_invalid_react_id():
    reset_data()
    owner = auth.auth_register("*****@*****.**", "hellocse1", "Sinha",
                               "Nawa")
    channels.channels_create(owner['token'], "New Channel", True)
    message.message_send(owner['token'], 1, "test")
    with pytest.raises(InputError):
        message.message_react(owner['token'], 1, 2)
Example #29
0
def test_standup_active_inactive():
    reset_data()
    member = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    channel_id = channels_create(member['token'], 'New Channel', True)['channel_id']

    assert standup_active(member['token'], channel_id) == {
        'is_active': False,
        'time_finish': None
    }
Example #30
0
def test_standup_send_user_not_in_channel():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'a', 'A')
    member2 = auth_register('*****@*****.**', 'helloworld', 'b', 'B')
    channel_id = channels_create(member1['token'], 'Channel', True)
    standup_start(member1['token'], channel_id['channel_id'], 3)

    with pytest.raises(AccessError):
        standup_send(member2['token'], 1, 'a')