Example #1
0
def test_send_late_bad():
    data = generate_data()
    user_admin, user_owner, user_in_channel, user_notin_channel = getting_user(
        data)
    channel = getting_channel(data)

    message_long = ""
    for i in range(0, 1010):
        message_long += "a"

    time_valid = datetime.now().timestamp() + 10
    time_invalid = datetime.now().timestamp() - 10
    # Invalid input
    assert send_message(data, user_admin.token, channel.channel_id,
                        message_long, time_valid) == {
                            "ValueError":
                            "Message is more than 1000 characters"
                        }
    assert send_message(
        data, user_notin_channel.token, 1232, 'short_message', time_valid) == {
            'AccessError':
            'the authorised user has not joined the channel they \
are trying to post to'
        }

    assert send_message(data, user_admin.token, channel.channel_id,
                        'short_message', time_invalid) == {
                            'ValueError': 'Time sent is a time in the past'
                        }
Example #2
0
def getdata():
    data = Data()
    ch_owner = register(data, '*****@*****.**', 'testtest', 'test', 'test',
                        'http://127.0.0.1:5555/')
    ch_member = register(data, '*****@*****.**', 'test2test2', 'test2',
                         'test2', 'http://127.0.0.1:5555/')
    register(data, '*****@*****.**', 'tests2', 'not in channel', 'test',
             'http://127.0.0.1:5555/')
    channel1 = ch_create(data, ch_owner['token'], 'ch_test', True)
    ch_join_leave(data, ch_member['token'], channel1['channel_id'], 'join')
    # data, token, channel_id, message, time_create=datetime.now()
    send_message(data, ch_owner['token'], channel1['channel_id'], 'test')
    send_message(data, ch_member['token'], channel1['channel_id'], 'test2')
    return data
Example #3
0
def test_edit_good():
    data = generate_data()
    user_admin, user_owner, user_in_channel, user_notin_channel = getting_user(
        data)
    message_admin, message_owner, message_norm = getting_message(data)
    channel = getting_channel(data)

    # case 1
    output = message_operation(data, user_admin.token,
                               message_admin.message_id, "new_message")
    assert output == {}
    assert message_admin.message == "new_message"

    # case 2
    output = message_operation(data, user_owner.token, message_norm.message_id,
                               "owner_change")
    assert output == {}
    assert message_norm.message == "owner_change"

    # case 3
    new_message = send_message(data, user_in_channel.token, channel.channel_id,
                               "new")
    output = message_operation(data, user_in_channel.token,
                               new_message["message_id"], "norm user change")
    assert output == {}
    assert data.get_element(
        'messages_group', 'message_id',
        new_message['message_id']).message == "norm user change"
Example #4
0
def test_send_good():
    data = generate_data()
    user_admin = getting_user(data)[0]
    channel = getting_channel(data)

    output = send_message(data, user_admin.token, channel.channel_id,
                          'short_message')
    assert data.get_element('messages_group', 'message_id',
                            output['message_id']) is not None
Example #5
0
def message_send():
    global data

    message, token, channel_id = do_get(request.form,
                                        ['message', 'token', 'channel_id'])
    result = send_message(data, token, int(channel_id), message)

    catch_error_and_return(result)
    save()

    return dumps(result)
Example #6
0
def message_send_later():
    global data

    message, token, channel_id, time_sent = do_get(
        request.form, ['message', 'token', 'channel_id', 'time_sent'])
    result = send_message(data, token, int(channel_id), message,
                          float(time_sent))
    catch_error_and_return(result)
    save()

    return dumps(result)
Example #7
0
def standup_active(data, user, channel_id):

    channel = data.get_element('channels_group', 'channel_id', channel_id)
    time_now = datetime.now().timestamp()
    if channel.standup['time_finish'] < time_now:
        is_activate = False
    else:
        is_activate = True

    user_beginer = data.get_element('users_group', 'u_id',
                                    channel.standup['u_id'])
    if not is_activate and channel.standup_message != '':
        send_message(data, user_beginer.token, channel_id,
                     channel.standup_message)
        channel.standup_message = ''

    return {
        'is_activate': is_activate,
        'time_finish': channel.standup['time_finish']
    }
Example #8
0
def test_send_late_good():
    data = generate_data()
    user_admin = getting_user(data)[0]
    channel = getting_channel(data)

    time_valid = datetime.now().timestamp() + 10

    output = send_message(data, user_admin.token, channel.channel_id,
                          'short_message', time_valid)
    assert data.get_element('messages_group', 'message_id',
                            output['message_id']) is not None
Example #9
0
def get_data():
    test_data = Data()
    user_chowner = register(test_data, '*****@*****.**', 'password',
                            'name_first1', 'name_last',
                            'http://127.0.0.1:5555/')
    user_inch = register(test_data, '*****@*****.**', 'password',
                         'name_first2', 'name_last', 'http://127.0.0.1:5555/')
    register(test_data, '*****@*****.**', 'password', 'name_first3',
             'name_last', 'http://127.0.0.1:5555/')
    channel = ch_create(test_data, user_chowner['token'], 'test_channel', True)
    ch_join_leave(test_data, user_inch['token'], channel['channel_id'], 'join')
    message_inch = send_message(test_data, user_inch['token'],
                                channel['channel_id'], 'test2')
    message_chowner = send_message(test_data, user_chowner['token'],
                                   channel['channel_id'], 'test')
    react_unreact(test_data, user_inch['token'], message_inch['message_id'], 1,
                  'react')
    react_unreact(test_data, user_inch['token'], message_chowner['message_id'],
                  1, 'react')
    ch_create(test_data, user_chowner['token'], 'test_channel2', True)
    return test_data
Example #10
0
def test_channel_messages_ok():
    data = getdata()
    user = data.users_group[0]
    channel = ch_create(data, user.token, '12345', True)
    send_message(data, user.token, channel['channel_id'], 'testing')
    message_channel = fun_message(data, user.token, channel['channel_id'], 0)
    channel1 = data.channels_group[0]
    message_channel1 = fun_message(data, user.token, channel1.channel_id, 0)
    # Checking the output
    assert message_channel['start'] == 0
    assert message_channel['end'] == -1
    messages = message_channel['messages']
    assert messages[0]['message'] == 'testing'
    assert messages[0]['u_id'] == user.u_id

    assert message_channel1['start'] == 0
    assert message_channel1['end'] == -1
    messages1 = message_channel1['messages']
    assert messages1[1]['message'] == 'test'
    assert messages1[1]['u_id'] == user.u_id
    standup_begin(data, user.token, channel['channel_id'], 10)
    for i in range(0, 25):
        send_message(data, user.token, channel['channel_id'], 'another test')
        send_message(data, user.token, channel['channel_id'], 'again')
        standup_message(data, user.token, channel['channel_id'], 'testing')
        i = i + 1
    message_channel2 = fun_message(data, user.token, channel['channel_id'], 0)
    assert message_channel2['start'] == 0
    assert message_channel2['end'] == 50
Example #11
0
def generate_data():
    test_data = Data()
    user_admin = register(test_data, '*****@*****.**', 'password',
                          'name_first1', 'name_last', 'http://127.0.0.1:5555/')
    user_channel_owner = register(test_data, '*****@*****.**', 'password',
                                  'name_first2', 'name_last',
                                  'http://127.0.0.1:5555/')
    user_in_channel = register(test_data, '*****@*****.**', 'password',
                               'name_first4', 'name_last',
                               'http://127.0.0.1:5555/')
    user_notin_channel = register(test_data, '*****@*****.**', 'password',
                                  'name_first3', 'name_last',
                                  'http://127.0.0.1:5555/')

    channel = ch_create(test_data, user_channel_owner['token'], 'test_channel',
                        True)
    ch_join_leave(test_data, user_admin['token'], channel['channel_id'],
                  'join')
    ch_join_leave(test_data, user_in_channel['token'], channel['channel_id'],
                  'join')

    send_message(test_data, user_in_channel['token'], channel['channel_id'],
                 'test3')
    send_message(test_data, user_channel_owner['token'], channel['channel_id'],
                 'test2')
    send_message(test_data, user_admin['token'], channel['channel_id'], 'test')

    return test_data
Example #12
0
def test_send_bad():
    data = generate_data()
    user_admin, user_owner, user_in_channel, user_notin_channel = getting_user(
        data)
    channel = getting_channel(data)

    message_long = ""
    for i in range(0, 1010):
        message_long += "a"

    assert send_message(data, user_admin.token, channel.channel_id,
                        message_long) == {
                            "ValueError":
                            "Message is more than 1000 characters"
                        }

    assert send_message(
        data, user_notin_channel.token, 2, 'short_message') == {
            'AccessError':
            'the authorised user has not joined the channel they\
 are trying to post to'
        }
Example #13
0
def test_channel_messages_bad():
    data = getdata()
    user = data.users_group[0]
    user1 = data.users_group[1]
    channel = ch_create(data, user.token, '12345', True)

    # ValueError
    long_message = ""
    for i in range(0, 1010):
        long_message += str(i)

    res1 = send_message(data, user.token, channel['channel_id'], long_message)
    assert res1 == {"ValueError": "Message is more than 1000 characters"}

    res2 = fun_message(data, user.token, channel['channel_id'] - 123, 0)
    assert res2 == {'ValueError': 'Channel ID is not a valid channel'}

    res3 = fun_message(data, user.token, channel['channel_id'], 999999999)
    assert res3 == {
        'ValueError':
        'start is greater than or equal to the total\
 number of messages in the channel'
    }

    # AccessError
    res4 = send_message(data, user.token, 10, 'testing')
    assert res4 == {
        'AccessError':
        'the authorised user has not joined the \
channel they are trying to post to'
    }

    res5 = fun_message(data, user1.token, channel['channel_id'], 0)
    assert res5 == {
        'AccessError':
        'when:  the authorised user has not joined \
the channel they are trying to post to'
    }