def test_message_react_invalid_msg_id():
    # Invalid message id raises InputError
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    channel = channels_create_v2(user['token'], 'channel example', True)
    message_send_v2(user["token"], channel['channel_id'], 'helo world')
    with pytest.raises(InputError):
        message_react_v1(user['token'], "invalid message id", 1)
def test_message_react_invalid_token():
    # Invalid token raises AccessError
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    channel = channels_create_v2(user['token'], 'channel example', True)
    msg = message_send_v2(user["token"], channel['channel_id'], 'helo world')
    with pytest.raises(AccessError):
        message_react_v1("invalid token", msg["message_id"], 1)
Пример #3
0
def test_assorted_notifications():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng")
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton")
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True)
    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)
    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)
    message_react_v1(user1['token'], msg2['message_id'], 1)

    assert notifications_get_v1(user1['token']) == {
        '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']) == {
        '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"
            },
        ]
    }
Пример #4
0
def message_react():
    parameters = request.get_json()
    token = parameters['token']
    message_id = parameters['message_id']
    react_id = parameters['react_id']
    output = message_react_v1(token, message_id, react_id)
    return dumps(output)
def test_already_react(reg_user, create_channel):
    clear_v2()

    # new user
    new_user = reg_user(0)
    user_token = new_user['token']
    # new channel
    channel_id = create_channel(user_token)['channel_id']
    # new message
    message = "Hello World !"
    message_id = message_send_v2(user_token, channel_id, message)['message_id']

    react_id = 1
    message_react_v1(user_token, message_id, react_id)
    with pytest.raises(InputError):
        message_react_v1(user_token, message_id, react_id)
def test_message_react_invalid_react_id():
    # Invalid react ID (!= 1) raises InputError
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    user2 = auth_register_v2("*****@*****.**", "password", "billy",
                             "williams")

    channel = channels_create_v2(user['token'], 'channel example', True)
    msg = message_send_v2(user["token"], channel['channel_id'], 'helo world')
    with pytest.raises(InputError):
        message_react_v1(user['token'], msg["message_id"], 12345)

    dm = dm_create_v1(user['token'], [user2["auth_user_id"]])
    msg = message_senddm_v1(user["token"], dm["dm_id"], "hi hi")
    with pytest.raises(InputError):
        message_react_v1(user['token'], msg["message_id"], "invalid_id")
Пример #7
0
def message_react():
    data = request.get_json()
    token = data['token']
    message_id = data['message_id']
    react_id = data['react_id']

    output = message_react_v1(token, message_id, react_id)

    return dumps(output)
Пример #8
0
def message_react():
    info = request.get_json()
    token = info["token"]
    message_id = info["message_id"]
    react_id = info["react_id"]

    message_react = message_react_v1(token, message_id, react_id)

    return dumps(message_react)
def test_message_react_user_not_member():
    # Authorised user is not a member of the channel or DM the message exists in
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    user2 = auth_register_v2("*****@*****.**", "password", "billy",
                             "williams")
    user3 = auth_register_v2("*****@*****.**", "password", "hilly",
                             "williams")

    channel = channels_create_v2(user['token'], 'channel example', True)
    msg = message_send_v2(user["token"], channel['channel_id'], 'helo world')
    with pytest.raises(AccessError):
        message_react_v1(user2['token'], msg["message_id"], 1)

    dm = dm_create_v1(user['token'], [user2["auth_user_id"]])
    msg = message_senddm_v1(user["token"], dm["dm_id"], "hi hi")
    with pytest.raises(AccessError):
        message_react_v1(user3["token"], msg["message_id"], 1)
def test_invaild_message_id_dm(reg_user):
    clear_v2()

    # new user
    new_user = reg_user(0)
    user_token = new_user['token']
    user_id = new_user['auth_user_id']
    # new dm
    new_dm = dm_create_v1(user_token, [user_id])
    dm_id = new_dm['dm_id']
    # new message
    message = "Hello World !"
    message_id = message_senddm_v1(user_token, dm_id, message)['message_id']

    react_id = 1

    with pytest.raises(InputError):
        message_react_v1(user_token, message_id + 1, react_id)
def test_invalid_token(reg_user, create_channel):

    clear_v2()
    # new user
    new_user = reg_user(0)
    user_token = new_user['token']
    user_id = new_user['auth_user_id']
    # new dm
    new_dm = dm_create_v1(user_token, [user_id])
    dm_id = new_dm['dm_id']
    # new message
    message = "Hello World !"
    message_id = message_senddm_v1(user_token, dm_id, message)['message_id']

    react_id = 1

    with pytest.raises(AccessError):
        message_react_v1("invalid_token", message_id, react_id)
def test_no_channel(reg_user, create_channel):

    clear_v2()

    # new user
    new_user = reg_user(0)
    user_token = new_user['token']
    # new channel
    channel_id = create_channel(user_token)['channel_id']
    # new message
    message = "Hello World !"
    message_id = message_send_v2(user_token, channel_id, message)['message_id']

    # anthor user
    another_user = reg_user(1)
    another_token = another_user['token']

    react_id = 1

    with pytest.raises(AccessError):
        message_react_v1(another_token, message_id, react_id)
def test_message_unreact_simple_case_dm():
    # Message already reacted to by user raises InputError
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    user2 = auth_register_v2("*****@*****.**", "password", "billy",
                             "williams")
    dm = dm_create_v1(user['token'], [user2['auth_user_id']])
    message_senddm_v1(user["token"], dm['dm_id'],
                      'message to dilute the history')
    msg = message_senddm_v1(user["token"], dm['dm_id'], 'helo world')
    message_react_v1(user['token'], msg["message_id"], 1)
    message_react_v1(user2['token'], msg["message_id"], 1)

    message_unreact_v1(user['token'], msg["message_id"], 1)

    msg_list = dm_messages_v1(user2['token'], dm['dm_id'], 0)['messages']
    assert msg_list[0]['reacts'] == [{
        'react_id': 1,
        'u_ids': [user2['auth_user_id']],
        'is_this_user_reacted': True,
    }]
Пример #14
0
def test_dm_member(reg_user, crt_dm, send_dm):

    clear_v2()

    # new user
    new_user = reg_user(0)
    user_token = new_user['token']

    # anthor user
    another_user = reg_user(1)
    another_token = another_user['token']

    # new channel
    dm_id = crt_dm(user_token, [another_user['auth_user_id']])['dm_id']
    # new message
    message = "Hello World !"
    message_id = send_dm(user_token, dm_id, message)['message_id']
    
    react_id = 1
    message_react_v1(another_token, message_id, react_id)

    assert message_unreact_v1(another_token, message_id, react_id) == {}
Пример #15
0
def test_single_react_notification():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng")
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton")
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True)
    channel_join_v2(user2['token'], channel1['channel_id'])
    msg1 = message_send_v2(user1['token'], channel1['channel_id'],
                           "1 like = 1 prayer")
    message_react_v1(user2['token'], msg1['message_id'], 1)

    assert notifications_get_v1(user1['token']) == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "joshhatton reacted to your message in Channel 1"
        }]
    }
def test_no_dm(reg_user):

    clear_v2()

    # new user
    new_user = reg_user(0)
    user_token = new_user['token']
    another_user_id = reg_user(1)['auth_user_id']
    # new dm
    new_dm = dm_create_v1(user_token, [another_user_id])
    dm_id = new_dm['dm_id']
    # new message
    message = "Hello World !"
    message_id = message_senddm_v1(user_token, dm_id, message)['message_id']

    # anthor user
    other_user = reg_user(2)
    other_token = other_user['token']

    react_id = 1

    with pytest.raises(AccessError):
        message_react_v1(other_token, message_id, react_id)
Пример #17
0
def test_message_unreact_errors(user_setup, dm_setup, channel_setup,
                                message_setup):
    with pytest.raises(AccessError):
        message_unreact_v1(make_token(10000), 0, 1)

    # message_id is not a valid message within a channel or DM that the authorised user has joined
    with pytest.raises(InputError):
        message_unreact_v1(make_token(1), 100, 1)

    # react_id is not a valid React ID
    with pytest.raises(InputError):
        message_unreact_v1(make_token(2), 0, 5)

    # Message with ID message_id does not contain an active React with/
    #   ID react_id from the authorised user
    with pytest.raises(InputError):
        message_unreact_v1(make_token(2), 0, 1)

    # The authorised user is not a member of the channel or DM that the message is within
    message_send_v2(make_token(0), 2, "yuh")
    message_react_v1(make_token(0), 20, 1)
    with pytest.raises(AccessError):
        message_react_v1(make_token(1), 20, 1)
def test_message_unreact_simple_case_channel():
    # Message already reacted to by user raises InputError
    clear_v1()
    user = auth_register_v2("*****@*****.**", "password", "bob", "williams")
    user2 = auth_register_v2("*****@*****.**", "password", "billy",
                             "williams")
    channel = channels_create_v2(user['token'], 'channel example', True)
    channel_join_v2(user2['token'], channel['channel_id'])
    message_send_v2(user["token"], channel['channel_id'],
                    'message to dilute the history')
    msg = message_send_v2(user["token"], channel['channel_id'], 'helo world')
    message_react_v1(user['token'], msg["message_id"], 1)
    message_react_v1(user2['token'], msg["message_id"], 1)

    message_unreact_v1(user2['token'], msg["message_id"], 1)

    msg_list = channel_messages_v2(user2['token'], channel['channel_id'],
                                   0)['messages']
    assert msg_list[0]['reacts'] == [{
        'react_id': 1,
        'u_ids': [user['auth_user_id']],
        'is_this_user_reacted': False,
    }]
Пример #19
0
def test_multiple_react_notification():
    clear_v1()
    user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric",
                             "Zheng")
    user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh",
                             "Hatton")
    user3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny",
                             "Dong")
    user4 = auth_register_v2("*****@*****.**", "password3", "Jordan",
                             "Milch")
    user5 = auth_register_v2("*****@*****.**", "4thpassword", "Dean",
                             "Zworestine")
    channel1 = channels_create_v2(user1['token'], 'Channel 1', True)
    channel_join_v2(user2['token'], channel1['channel_id'])
    channel_join_v2(user3['token'], channel1['channel_id'])
    channel_join_v2(user4['token'], channel1['channel_id'])
    channel_join_v2(user5['token'], channel1['channel_id'])
    msg1 = message_send_v2(user1['token'], channel1['channel_id'],
                           "1 like = 1 prayer")
    message_react_v1(user1['token'], msg1['message_id'], 1)
    message_react_v1(user2['token'], msg1['message_id'], 1)
    message_react_v1(user3['token'], msg1['message_id'], 1)
    message_react_v1(user4['token'], msg1['message_id'], 1)
    message_react_v1(user5['token'], msg1['message_id'], 1)

    assert notifications_get_v1(user1['token']) == {
        'notifications': [{
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "deanzworestine reacted to your message in Channel 1"
        }, {
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "jordanmilch reacted to your message in Channel 1"
        }, {
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "bunnydong reacted to your message in Channel 1"
        }, {
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "joshhatton reacted to your message in Channel 1"
        }, {
            'channel_id':
            channel1['channel_id'],
            'dm_id':
            -1,
            'notification_message':
            "ericzheng reacted to your message in Channel 1"
        }]
    }
Пример #20
0
def test_react_and_unreact_v1(user_setup, dm_setup, channel_setup):
    # react to the message in the channel
    message_send_v2(make_token(2), 0, "0")
    assert message_react_v1(make_token(2), 0, 1) == {}
    # react to the message in the dm

    message_senddm_v1(make_token(2), 0, "1")
    assert message_react_v1(make_token(2), 1, 1) == {}
    assert channel_messages_v2(make_token(2), 0, 0) == {
        "messages": [
            {
                "message_id":
                0,
                "u_id":
                2,
                "message":
                "0",
                "time_created":
                create_timestamp(),
                "channel_id":
                0,
                "dm_id":
                -1,
                'reacts': [{
                    'react_id': 1,
                    'u_ids': [2],
                    'is_this_user_reacted': True
                }],
                'is_pinned':
                False
            },
        ],
        "start":
        0,
        "end":
        -1,
    }
    assert dm_messages_v1(make_token(2), 0, 0) == {
        "messages": [
            {
                "message_id":
                1,
                "u_id":
                2,
                "message":
                "1",
                "time_created":
                create_timestamp(),
                "channel_id":
                -1,
                "dm_id":
                0,
                'reacts': [{
                    'react_id': 1,
                    'u_ids': [2],
                    'is_this_user_reacted': True
                }],
                'is_pinned':
                False
            },
        ],
        "start":
        0,
        "end":
        -1,
    }

    # remove all the reacts
    assert message_unreact_v1(make_token(2), 0, 1) == {}
    assert message_unreact_v1(make_token(2), 1, 1) == {}
    assert channel_messages_v2(make_token(2), 0, 0) == {
        "messages": [
            {
                "message_id":
                0,
                "u_id":
                2,
                "message":
                "0",
                "time_created":
                create_timestamp(),
                "channel_id":
                0,
                "dm_id":
                -1,
                'reacts': [{
                    'react_id': 1,
                    'u_ids': [],
                    'is_this_user_reacted': False
                }],
                'is_pinned':
                False
            },
        ],
        "start":
        0,
        "end":
        -1,
    }
def test_react(test_data):
    a_data, b_data, c_data, a_ch_id = test_data

    channel_join_v2(b_data["token"], a_ch_id)
    channel_join_v2(c_data["token"], a_ch_id)

    a_msg_id = message_send_v2(a_data["token"], a_ch_id,
                               "React to me!")["message_id"]
    message_react_v1(b_data["token"], a_msg_id, 1)

    notifs = notifications_get_v1(a_data["token"])["notifications"]
    assert len(notifs) == 1
    assert notifs[0] == {
        "channel_id": a_ch_id,
        "dm_id": -1,
        "notification_message":
        "bobbobinson reacted to your message in Channel 1"
    }
    sleep(1)

    message_react_v1(c_data["token"], a_msg_id, 1)

    notifs = notifications_get_v1(a_data["token"])["notifications"]
    assert len(notifs) == 2
    assert notifs[0] == {
        "channel_id": a_ch_id,
        "dm_id": -1,
        "notification_message": "chriscon reacted to your message in Channel 1"
    }
    assert notifs[1] == {
        "channel_id": a_ch_id,
        "dm_id": -1,
        "notification_message":
        "bobbobinson reacted to your message in Channel 1"
    }
    sleep(1)

    b_dm_id = dm_create_v1(
        b_data["token"],
        [a_data["auth_user_id"], c_data["auth_user_id"]])["dm_id"]

    a1_msg_id = message_senddm_v1(a_data["token"], b_dm_id,
                                  "React to me again!")["message_id"]
    message_react_v1(b_data["token"], a1_msg_id, 1)

    notifs = notifications_get_v1(a_data["token"])["notifications"]
    assert len(notifs) == 3
    assert notifs[0] == {
        "channel_id":
        -1,
        "dm_id":
        b_dm_id,
        "notification_message":
        "bobbobinson reacted to your message in andyanderson, bobbobinson, chriscon"
    }
    assert notifs[1] == {
        "channel_id": a_ch_id,
        "dm_id": -1,
        "notification_message": "chriscon reacted to your message in Channel 1"
    }
    assert notifs[2] == {
        "channel_id": a_ch_id,
        "dm_id": -1,
        "notification_message":
        "bobbobinson reacted to your message in Channel 1"
    }