def test_simple_sendlater(): ''' Test sendlater with multiple messages in different channels ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END # Send message later time_sent = int(t.time() + 10) msg_id = message_sendlater(token, c_id, 'Hello world', time_sent) # Assert is stored for later assert check_later(msg_id) is msg_id # Sending message later in another channel c2_id = channel_create(token, 'Channel1', 'true') # Send message later time_sent = t.time() + 10 msg_id3 = message_sendlater(token, c2_id, 'Hello world', time_sent) # Assert message is in channel assert check_later(msg_id3) is msg_id3
def test_past(): ''' Test sending a message later when the time is in the past ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END time_sent = t.time() - 10 with pytest.raises(ValueError, match=r"*"): message_sendlater(token, c_id, 'Hello world', time_sent)
def test_sendlater_nomsg(): ''' Test sending a message later with no message ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END time_sent = t.time() + 10 with pytest.raises(ValueError, match=r"*"): message_sendlater(token, c_id, None, time_sent)
def test_nochannel_sendlater(): ''' Test sending a message later when the channel doesn't exist ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] # SETUP END time_sent = t.time() + 10 with pytest.raises(ValueError, match=r"*"): message_sendlater(token, '', 'Hello world', time_sent) message_sendlater(token, '123', 'Hello world', time_sent)
def test_sendlater_cap(): ''' Test sending a message later at the maximum character limit (1000) ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END # Send message later time_sent = t.time() + 10 message_sendlater(token, c_id, 'a' * 1000, time_sent) # Check message is in the channel message_list = server_data.messages_later print('messages', message_list) assert 'a' in message_list[0]['message']
def test_unauthorized_sendlater(): ''' Test sending a message later with an unauthorized token ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END # Login as new user not part of channel auth_logout(token) registered_user = auth_register('*****@*****.**', '123456', 'Bob', 'Smith') token = registered_user['token'] time_sent = t.time() + 10 with pytest.raises(AccessError, match=r"*"): message_sendlater(token, c_id, 'Hello world', time_sent) message_sendlater('', c_id, 'Hello world', time_sent)
def sendlater_message(): token = request.form.get('token') channel_id = request.form.get('channel_id') message = request.form.get('message') time = request.form.get('time_sent') try: output = message_sendlater(token, channel_id, message, time) except ValueError as e: return str(e) except AccessError as e: return dumps({ 'code': 400, 'name': 'AccessError', 'message': str(e) }), 400 save() return dumps({'message_id': output})