コード例 #1
0
def test_invalid_token():
    """Raise an access error when the token passed in does not refer to a
    valid user
    """
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    assert admin_user_remove_v1(
        user_1["token"] + "bug",
        user_2["auth_user_id"]).status_code == ACCESS_ERROR
    assert admin_user_remove_v1(
        user_1["token"] + "yum",
        user_2["auth_user_id"]).status_code == ACCESS_ERROR
    assert admin_user_remove_v1(
        user_1["token"] + "discodisco",
        user_2["auth_user_id"]).status_code == ACCESS_ERROR
    assert admin_user_remove_v1(
        user_1["token"] + "34897",
        user_2["auth_user_id"]).status_code == ACCESS_ERROR
    assert admin_user_remove_v1(
        user_1["token"] + "t",
        user_2["auth_user_id"]).status_code == ACCESS_ERROR

    clear_v1()
コード例 #2
0
def test_mixed_basic():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    result2 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    auth_register_v2('*****@*****.**', 'password', 'comp', 'student')
    channels_create_v2(result1['token'], "The party channel 1", True)
    channels_create_v2(result1['token'], "The party channel 2", True)
    dm_create_v1(result1['token'], [result2['auth_user_id']])

    output = user_stats(result1['token']).json()

    dreams = users_stats(result1['token']).json()
    assert len(output['user_stats']) == 4
    assert output['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 2
    assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1
    assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 0
    assert output['user_stats']['involvement_rate'] == 1

    assert len(dreams['dreams_stats']) == 4
    assert dreams['dreams_stats']['channels_exist'][-1][
        'num_channels_exist'] == 2
    assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1
    assert dreams['dreams_stats']['messages_exist'][-1][
        'num_messages_exist'] == 0
    assert dreams['dreams_stats']['utilization_rate'] == 2 / 3
コード例 #3
0
def test_message_remove_stat():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    result2 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    result3 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    dm1 = dm_create_v1(
        result1['token'],
        [result2['auth_user_id'], result3['auth_user_id']]).json()
    message1 = message_senddm_v1(result1['token'], dm1['dm_id'],
                                 'Hello, how are you?').json()
    message_remove_v1(result1['token'], message1['message_id'])

    output = user_stats(result1['token']).json()

    dreams = users_stats(result1['token']).json()
    assert len(output['user_stats']) == 4
    assert output['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 0
    assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1
    assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1
    assert output['user_stats']['involvement_rate'] == 2

    assert len(dreams['dreams_stats']) == 4
    assert dreams['dreams_stats']['channels_exist'][-1][
        'num_channels_exist'] == 0
    assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1
    assert dreams['dreams_stats']['messages_exist'][-1][
        'num_messages_exist'] == 0
    assert dreams['dreams_stats']['utilization_rate'] == 1
def create_input():
    clear_v1()

    data_test_users = [
        auth_register_v2("*****@*****.**", "validpassword", "Josh",
                         "Hatton").json(),
        auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                         "Dong").json(),
        auth_register_v2("*****@*****.**", "password3", "Jordan",
                         "Milch").json(),
        auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                         "Zworestine").json(),
        auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                         "Zheng").json(),
    ]

    data_test_dms = [
        dm_create_v1(data_test_users[0]["token"], [
            data_test_users[1]["auth_user_id"],
            data_test_users[2]["auth_user_id"]
        ]).json(),
        dm_create_v1(data_test_users[1]["token"],
                     [data_test_users[3]["auth_user_id"]]).json(),
    ]

    return [data_test_users, data_test_dms]
コード例 #5
0
def create_input():
    clear_v1()

    data_test_users = [
        auth_register_v2("*****@*****.**", "validpassword", "Josh",
                         "Hatton").json(),
        auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                         "Dong").json(),
        auth_register_v2("*****@*****.**", "password3", "Jordan",
                         "Milch").json(),
        auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                         "Zworestine").json(),
        auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                         "Zheng").json(),
    ]

    data_test_channels = [
        channels_create_v2(data_test_users[0]["token"], "First Channel",
                           True).json(),
        channels_create_v2(data_test_users[1]["token"], "Second Channel",
                           True).json(),
        channels_create_v2(data_test_users[2]["token"], "Third Channel",
                           False).json(),
    ]

    channel_join_v2(data_test_users[1]["token"],
                    data_test_channels[0]["channel_id"])
    channel_join_v2(data_test_users[2]["token"],
                    data_test_channels[0]["channel_id"])

    return [data_test_users, data_test_channels]
コード例 #6
0
def test_removed_dms():
    """Tests that sent dm messages are now 'Removed user' after the user is
    removed
    """
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    dm_1 = dm_create_v1(user_1["token"], [user_2["auth_user_id"]]).json()

    message_senddm_v1(user_1["token"], dm_1["dm_id"], "Hello user 2!")
    message_2 = message_senddm_v1(user_2["token"], dm_1["dm_id"],
                                  "Nice to meet you user 1").json()
    message_senddm_v1(user_2["token"], dm_1["dm_id"], "you are a donkey :)")

    assert admin_user_remove_v1(user_1["token"],
                                user_2["auth_user_id"]).status_code == SUCCESS

    dm_1_messages = dm_messages_v1(user_1["token"], dm_1["dm_id"], 0).json()
    for dm in dm_1_messages["messages"]:
        if dm["message_id"] == message_2["message_id"]:
            assert dm["message"] == "Removed user"

    clear_v1()
コード例 #7
0
def test_assorted_notifications():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng").json()
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton").json()
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True).json()
    channel_invite_v2(user1['token'], channel1['channel_id'],
                      user2['auth_user_id'])
    msg1str = "Welcome to the channel @joshhatton"
    msg1 = message_send_v2(user1['token'], channel1['channel_id'],
                           msg1str).json()
    message_react_v1(user2['token'], msg1['message_id'], 1)
    msg2str = "Thanks for having me @ericzheng"
    msg2 = message_send_v2(user2['token'], channel1['channel_id'],
                           msg2str).json()
    message_react_v1(user1['token'], msg2['message_id'], 1)

    assert notifications_get_v1(user1['token']).json() == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            f"joshhatton tagged you in Channel 1: {msg2str[0:20]}"
        }, {
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "joshhatton reacted to your message in Channel 1"
        }]
    }
    assert notifications_get_v1(user2['token']).json() == {
        'notifications': [
            {
                'channel_id':
                channel1['channel_id'],
                'dm_id':
                -1,
                'notification_message':
                "ericzheng reacted to your message in Channel 1"
            },
            {
                'channel_id':
                channel1['channel_id'],
                'dm_id':
                -1,
                'notification_message':
                f"ericzheng tagged you in Channel 1: {msg1str[0:20]}"
            },
            {
                'channel_id': channel1['channel_id'],
                'dm_id': -1,
                'notification_message': "ericzheng added you to Channel 1"
            },
        ]
    }
コード例 #8
0
def test_two_tags():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng").json()
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton").json()
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True).json()
    channel_join_v2(user2['token'], channel1['channel_id'])
    msg1str = "@ericzheng @joshhatton"
    message_send_v2(user1['token'], channel1['channel_id'], msg1str)

    assert notifications_get_v1(user1['token']).json() == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            f"ericzheng tagged you in Channel 1: {msg1str[0:20]}"
        }]
    }
    assert notifications_get_v1(user2['token']).json() == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            f"ericzheng tagged you in Channel 1: {msg1str[0:20]}"
        }]
    }
コード例 #9
0
def create_input():
    clear_v1()

    data_test_users = [
        auth_register_v2("*****@*****.**", "peterpiper", "Eric",
                         "Zheng").json(),
        auth_register_v2("*****@*****.**", "maryreider", "Josh",
                         "Hatton").json(),
        auth_register_v2("*****@*****.**", "globalempire4", "Bunny",
                         "Dong").json(),
        auth_register_v2("*****@*****.**", "runescape4lyfe", "Dean",
                         "Zworestine").json(),
        auth_register_v2("*****@*****.**", "iheartnewyork", "Jordan",
                         "Milch").json()
    ]

    data_test_channels = [
        channels_create_v2(data_test_users[0]['token'], "General",
                           True).json(),
        channels_create_v2(data_test_users[1]['token'], "Party", True).json(),
        channels_create_v2(data_test_users[2]['token'], "Private",
                           False).json()
    ]

    return [data_test_users, data_test_channels]
コード例 #10
0
def test_no_notifications():
    """ Assume that notifications_get_v1 returns an empty dictionary of list
        when there are no notifiactions to display
    """
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()
    user_3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                              "Dong").json()
    user_4 = auth_register_v2("*****@*****.**", "password3", "Jordan",
                              "Milch").json()
    user_5 = auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                              "Zworestine").json()

    assert notifications_get_v1(user_1['token']).json() == {
        'notifications': []
    }
    assert notifications_get_v1(user_2['token']).json() == {
        'notifications': []
    }
    assert notifications_get_v1(user_3['token']).json() == {
        'notifications': []
    }
    assert notifications_get_v1(user_4['token']).json() == {
        'notifications': []
    }
    assert notifications_get_v1(user_5['token']).json() == {
        'notifications': []
    }
コード例 #11
0
def test_mixed_decrement():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    result2 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    channel1 = channels_create_v2(result1['token'], "The party channel 1",
                                  True).json()['channel_id']
    message1 = message_send_v2(result1['token'], channel1,
                               'hello how are you').json()['message_id']

    message_remove_v1(result1['token'], message1)
    channel_join_v2(result2['token'], channel1)
    channel_leave_v1(result2['token'], channel1)

    output = user_stats(result1['token']).json()
    assert output['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 1
    assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1
    output1 = user_stats(result2['token']).json()
    assert output1['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 0
    dreams = users_stats(result1['token']).json()
    assert dreams['dreams_stats']['channels_exist'][-1][
        'num_channels_exist'] == 1
    assert dreams['dreams_stats']['messages_exist'][-1][
        'num_messages_exist'] == 0
コード例 #12
0
def test_invalid_token():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    auth_register_v2('*****@*****.**', 'password', 'comp', 'student')
    channels_create_v2(result1['token'], "The party channel 1", True)
    channels_create_v2(result1['token'], "The party channel 2", True)
    user_stats('abcdef').status_code == ACCESS_ERROR
コード例 #13
0
def create_input():
    clear_v1()

    users = [
        auth_register_v2("*****@*****.**", "validpassword", "Josh",
                         "Hatton").json(),
        auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                         "Dong").json(),
        auth_register_v2("*****@*****.**", "password3", "Jordan",
                         "Milch").json(),
        auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                         "Zworestine").json(),
        auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                         "Zheng").json(),
    ]

    channels = [
        channels_create_v2(users[0]["token"], "First Channel",
                           True).json()['channel_id'],
        channels_create_v2(users[1]["token"], "Second Channel",
                           False).json()['channel_id']
    ]

    dms = [
        dm_create_v1(users[0]['token'],
                     [users[2]['auth_user_id']]).json()['dm_id'],
        dm_create_v1(users[1]['token'],
                     [users[3]['auth_user_id'], users[4]['auth_user_id']
                      ]).json()['dm_id']
    ]

    # Send 5 messages to First Channel
    channel_1_messages = []
    for i in range(0, 5):
        channel_1_messages.append(
            message_send_v2(
                users[0]["token"], channels[0],
                f"First channel message {i}.").json()['message_id'])

    # Send 5 messages to Second Channel
    for i in range(0, 5):
        message_send_v2(users[1]["token"], channels[1],
                        f"Second channel message {i}.")

    # Send 5 messages to First DM
    dm_1_messages = []
    for i in range(0, 5):
        dm_1_messages.append(
            message_senddm_v1(users[0]["token"], dms[0],
                              f"First dm message {i}.").json()['message_id'])

    # Send 5 messages to Second DM
    for i in range(0, 5):
        message_senddm_v1(users[1]["token"], dms[1], f"Second dm message {i}.")

    return [users, channels, dms, channel_1_messages, dm_1_messages]
コード例 #14
0
def test_remove_from_users_all():
    """ Tests that a user is removed from users_all list"""
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    admin_user_remove_v1(user_1["token"], user_2["auth_user_id"])
    users = users_all_v1(user_1["token"]).json()["users"]

    assert user_2["auth_user_id"] not in [u["u_id"] for u in users]
コード例 #15
0
def test_invalid_channel_id_exception():
    """ Tests when channel_id does not refer to a valid channel.
    """
    clear_v1()
    
    user_1 = auth_register_v2("*****@*****.**", "password34", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "password3", "Jordan",
                              "Milch").json()

    channel_invite_1 = channel_invite_v2(user_1['token'], 0, user_2['auth_user_id'])
    channel_invite_2 = channel_invite_v2(user_2['token'], 1, user_1['auth_user_id'])
    
    assert channel_invite_1.status_code == INPUT_ERROR
    assert channel_invite_2.status_code == INPUT_ERROR        
コード例 #16
0
def test_exception_priority():
    """ When there are multiple errors, an AccessError should be the first one
        raised for invalid token.
    """
    clear_v1()

    auth_register_v2("*****@*****.**", "Hihjile", "Eric", "Zheng")
    user_2 = auth_register_v2("*****@*****.**", "ccas1122", "Joshua",
                              "Hatton").json()
    user_3 = auth_register_v2("*****@*****.**", "bunnyyipyip", "Bunny",
                              "Dong").json()

    assert admin_userpermission_change_v1(user_3['token'] + 'bug',
                                          user_2['auth_user_id'] + 5,
                                          3).status_code == ACCESS_ERROR
コード例 #17
0
def test_removed_from_dm():
    """Tests that a user is removed from a dm"""
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    dm_1 = dm_create_v1(user_1["token"], []).json()
    dm_invite_v1(user_1["token"], dm_1["dm_id"], user_2["auth_user_id"])

    admin_user_remove_v1(user_1["token"], user_2["auth_user_id"])

    members = dm_details_v1(user_1["token"], dm_1["dm_id"]).json()["members"]

    assert user_2["auth_user_id"] not in [m["u_id"] for m in members]
コード例 #18
0
def test_message_edit_stat():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    channel1 = channels_create_v2(result1['token'], "The party channel 1",
                                  True).json()
    message1 = message_send_v2(result1['token'], channel1['channel_id'],
                               'Hello, how are you?').json()
    message2 = message_send_v2(result1['token'], channel1['channel_id'],
                               'Hello, how are you?').json()
    message_edit_v2(result1['token'], message1['message_id'], 'Hi Im user 1')
    message_edit_v2(result1['token'], message2['message_id'], '')
    #message_remove_v1(result1['token'], message2['message_id'])
    output = user_stats(result1['token']).json()

    dreams = users_stats(result1['token']).json()
    assert len(output['user_stats']) == 4
    assert output['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 1
    assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 0
    assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 2
    assert output['user_stats']['involvement_rate'] == 3 / 2

    assert len(dreams['dreams_stats']) == 4
    assert dreams['dreams_stats']['channels_exist'][-1][
        'num_channels_exist'] == 1
    assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 0
    assert dreams['dreams_stats']['messages_exist'][-1][
        'num_messages_exist'] == 1
    assert dreams['dreams_stats']['utilization_rate'] == 1
コード例 #19
0
def test_removed_from_channel():
    """Tests that a user is removed from a channel"""
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    channel_1 = channels_create_v2(user_1["token"], "Test", True).json()
    channel_join_v2(user_2["token"], channel_1["channel_id"])

    admin_user_remove_v1(user_1["token"], user_2["auth_user_id"])

    members = channel_details_v2(user_1["token"],
                                 channel_1["channel_id"]).json()["all_members"]

    assert user_2["auth_user_id"] not in [m["u_id"] for m in members]
コード例 #20
0
def test_auth_not_owner():
    """Raise an access error when the authorised user is not an owner"""
    clear_v1()

    # Register the Dreams owner first
    auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng")
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()
    user_3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                              "Dong").json()

    assert admin_user_remove_v1(
        user_2["token"], user_3["auth_user_id"]).status_code == ACCESS_ERROR
    assert admin_user_remove_v1(
        user_3["token"], user_2["auth_user_id"]).status_code == ACCESS_ERROR

    clear_v1()
コード例 #21
0
def test_mixed_harder():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    result2 = auth_register_v2('*****@*****.**', 'password', 'comp',
                               'student').json()
    channel1 = channels_create_v2(result1['token'], "The party channel 1",
                                  True).json()['channel_id']
    message_send_v2(result1['token'], channel1, 'hello how are you')
    dm_create_v1(result1['token'], [result2['auth_user_id']])
    output = user_stats(result1['token']).json()
    assert len(output['user_stats']) == 4
    assert output['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 1
    assert output['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1
    assert output['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1
    assert output['user_stats']['involvement_rate'] == 1
    channels_create_v2(result1['token'], "The party channel 2", True)
    channel3 = channels_create_v2(result2['token'], "The party channel 3",
                                  True).json()['channel_id']
    channel_addowner_v1(result2['token'], channel3, result1['auth_user_id'])
    message_send_v2(result2['token'], channel3, 'hello how are you')
    output1 = user_stats(result1['token']).json()
    output2 = user_stats(result2['token']).json()
    assert len(output1['user_stats']) == 4
    assert output1['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 3
    assert output1['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1
    assert output1['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1
    assert output1['user_stats']['involvement_rate'] == 5 / 6
    assert len(output2['user_stats']) == 4
    assert output2['user_stats']['channels_joined'][-1][
        'num_channels_joined'] == 1
    assert output2['user_stats']['dms_joined'][-1]['num_dms_joined'] == 1
    assert output2['user_stats']['messages_sent'][-1]['num_messages_sent'] == 1
    assert output2['user_stats']['involvement_rate'] == 3 / 6

    dreams = users_stats(result1['token']).json()
    assert len(dreams['dreams_stats']) == 4
    assert dreams['dreams_stats']['channels_exist'][-1][
        'num_channels_exist'] == 3
    assert dreams['dreams_stats']['dms_exist'][-1]['num_dms_exist'] == 1
    assert dreams['dreams_stats']['messages_exist'][-1][
        'num_messages_exist'] == 2
    assert dreams['dreams_stats']['utilization_rate'] == 1
コード例 #22
0
def create_input():
    clear_v1()
    
    data_test_users = [
        auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng").json(),
        auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton").json(),
        auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong").json(),
        auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch").json(),
        auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine").json(),
    ]

    data_test_channels = [
        channels_create_v2(data_test_users[0]['token'], "General", True).json(),
        channels_create_v2(data_test_users[1]['token'], "Party", True).json(),
        channels_create_v2(data_test_users[2]['token'], "Private", False).json(),
    ]

    return [data_test_users, data_test_channels]
コード例 #23
0
def create_input():
    clear_v1()

    data_test_users = [
        auth_register_v2("*****@*****.**", "validpassword", "Josh",
                         "Hatton").json(),
        auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                         "Dong").json(),
        auth_register_v2("*****@*****.**", "password3", "Jordan",
                         "Milch").json(),
        auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                         "Zworestine").json(),
        auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                         "Zheng").json(),
    ]

    data_test_channels = [
        channels_create_v2(data_test_users[0]["token"], "First Channel",
                           True).json(),
        channels_create_v2(data_test_users[1]["token"], "Second Channel",
                           True).json(),
        channels_create_v2(data_test_users[2]["token"], "Third Channel",
                           False).json(),
    ]

    # Send 10 messages to First Channel
    for i in range(0, 10):
        message_send_v2(data_test_users[0]["token"],
                        data_test_channels[0]["channel_id"],
                        f"First channel message {i}.")

    # Send 55 messages to Second Channel
    for i in range(0, 55):
        message_send_v2(data_test_users[1]["token"],
                        data_test_channels[1]["channel_id"],
                        f"Second channel message {i}.")

    # Send 120 messages to Third Channel
    for i in range(0, 120):
        message_send_v2(data_test_users[2]["token"],
                        data_test_channels[2]["channel_id"],
                        f"Third channel message {i}.")

    return [data_test_users, data_test_channels]
コード例 #24
0
def test_only_owner():
    """Raise an input error when the user is currently the only owner"""
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()

    assert admin_user_remove_v1(
        user_1["token"], user_1["auth_user_id"]).status_code == INPUT_ERROR

    clear_v1()
コード例 #25
0
def test_invalid_u_id():
    """Raise an input error when u_id does not refer to a valid user id"""
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    assert admin_user_remove_v1(user_1["token"], user_1["auth_user_id"] +
                                5).status_code == INPUT_ERROR
    assert admin_user_remove_v1(user_1["token"], user_1["auth_user_id"] +
                                50).status_code == INPUT_ERROR
    assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] +
                                1).status_code == INPUT_ERROR
    assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] +
                                50).status_code == INPUT_ERROR
    assert admin_user_remove_v1(user_1["token"], user_2["auth_user_id"] +
                                500).status_code == INPUT_ERROR

    clear_v1()
コード例 #26
0
def test_invalid_token():
    """ Tests return of expected output when given a token that doesn't exist,
        or if the user is not in the channel/dm.
    """
    clear_v1()
    # Token doesnt exist
    user_1 = auth_register_v2('*****@*****.**', 'happydays1', 'Eric',
                              'Zheng').json()

    assert notifications_get_v1(user_1['token'] +
                                'bug').status_code == ACCESS_ERROR

    # User not in channel
    user_2 = auth_register_v2('*****@*****.**', 'happydays2', 'Josh',
                              'Hatton').json()
    channel_1 = channels_create_v2(user_1['token'], 'Channel 1', True).json()

    user_2_handle = user_profile_v2(user_1['token'],
                                    user_2['auth_user_id']).json()

    message_send_v2(user_1['token'], channel_1['channel_id'],
                    f"Hi @{user_2_handle['user']['handle_str']}")

    assert notifications_get_v1(user_2['token']).json() == {
        'notifications': []
    }

    # User not in dm
    dm_1 = dm_create_v1(user_1['token'], [user_2['auth_user_id']]).json()
    user_3 = auth_register_v2('*****@*****.**', 'hihihi!!!', 'Bunny',
                              'Dong').json()
    user_3_handle = user_profile_v2(user_1['token'],
                                    user_3['auth_user_id']).json()

    message_senddm_v1(user_1['token'], dm_1['dm_id'],
                      f"Hello @{user_3_handle['user']['handle_str']}")

    assert notifications_get_v1(user_3['token']).json() == {
        'notifications': []
    }
コード例 #27
0
def test_single_react_notification():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng").json()
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton").json()
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True).json()
    channel_join_v2(user2['token'], channel1['channel_id'])
    msg1 = message_send_v2(user1['token'], channel1['channel_id'],
                           "1 like = 1 prayer").json()
    message_react_v1(user2['token'], msg1['message_id'], 1)

    assert notifications_get_v1(user1['token']).json() == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "joshhatton reacted to your message in Channel 1"
        }]
    }
コード例 #28
0
def test_order_of_exceptions():
    """ Tests that the function raises exceptions in the order as assumed. The order
    should be:
        1. AccessError from invalid token
        2. InputError from invalid channel id
        3. InputError from invalid user id
        4. AccessError when any of the authorised user is not already part of a 
            channel
    """
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "f244332fsd", "Tom",
                              "Cruise").json()
    user_2 = auth_register_v2("*****@*****.**", "password09123", "Dummy",
                              "Dog").json()
    channel = channels_create_v2(user_1['token'], "General", True).json()
    user_test = auth_register_v2("*****@*****.**", "watermelon", "Max", 
                                    "Rex").json()

    # Pass in invalid user_id, invalid auth_user_id, invalid channel_id,
    # auth_user not part of the channel. This should raise an access error.
    assert channel_invite_v2(user_2['token'] + 'bug', channel['channel_id'] + 5,
                            user_test['auth_user_id'] + 5).status_code == ACCESS_ERROR
    
    # Pass in invalid user_id, valid token, invalid channel_id,
    # auth_user not part of the channel. This should raise an access error.
    assert channel_invite_v2(user_2['token'], channel['channel_id'] + 5,
                            user_test['auth_user_id'] + 5).status_code == INPUT_ERROR

    # Pass in valid user_id, valid token, valid channel_id,
    # auth_user not part of the channel. This should raise an input error.                          
    assert channel_invite_v2(user_2['token'], channel['channel_id'],
                            user_test['auth_user_id'] + 5).status_code == INPUT_ERROR
        

    # Pass in valid user_id, valid token, valid channel_id,
    # auth_user not part of the channel. This should raise an access error.                          
    assert channel_invite_v2(user_2['token'], channel['channel_id'],
                            user_test['auth_user_id']).status_code == ACCESS_ERROR
コード例 #29
0
def test_invalid_token_id():
    """ Raises an AccessError when the token passed in does not refer to a valid
        user.
    """
    clear_v1()

    user_1 = auth_register_v2("*****@*****.**", "Helalfs432", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "ccas1122", "Joshua",
                              "Hatton").json()

    assert admin_userpermission_change_v1(user_1['token'] + 'bug',
                                          user_2['auth_user_id'],
                                          1).status_code == ACCESS_ERROR
    assert admin_userpermission_change_v1(user_1['token'] + 'sadf',
                                          user_2['auth_user_id'],
                                          2).status_code == ACCESS_ERROR
    assert admin_userpermission_change_v1(user_1['token'] + '1',
                                          user_2['auth_user_id'],
                                          2).status_code == ACCESS_ERROR
    assert admin_userpermission_change_v1(user_1['token'] + '7455',
                                          user_2['auth_user_id'],
                                          1).status_code == ACCESS_ERROR
コード例 #30
0
def test_simple_tag():
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                              "Zheng").json()
    user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                              "Hatton").json()

    message_1 = "@ericzheng, how are you doing today?"

    channel_1 = channels_create_v2(user_1['token'], 'Channel 1', True).json()
    channel_join_v2(user_2['token'], channel_1['channel_id'])
    message_send_v2(user_2['token'], channel_1['channel_id'], message_1)

    assert notifications_get_v1(user_1['token']).json() == {
        'notifications': [{
            'channel_id':
            channel_1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            f"joshhatton tagged you in Channel 1: {message_1[0:20]}"
        }]
    }