def test_send_too_long(): """ Test if an error is raised if message is too long """ channel_creater = auth.auth_register("*****@*****.**", "password", "Quick", "Shadow") test_channel_id1 = channels.channels_create(channel_creater["token"], "test1", True) standup.standup_start(channel_creater["token"], test_channel_id1["channel_id"], 1) message_exp = ( "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula " "eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient " "montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, " "pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, " "aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis " "vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras " "dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo " "ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus " "in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. " "Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper " "ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum " "rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum...12345" ) with pytest.raises(InputError): standup.standup_send(channel_creater["token"], test_channel_id1["channel_id"], message_exp) other.clear()
def test_standup_whole(): time.sleep(5) _, wenyao_dict, _, channel_team1, _ = initialise_data() # start standup standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5) # check if standup is active is_active = standup_active(wenyao_dict['token'], channel_team1['channel_id'])['is_active'] assert is_active == True standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hi") time.sleep(1) standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hello") # sleep for 5s time.sleep(5) # check if standup is active is_active = standup_active(wenyao_dict['token'], channel_team1['channel_id'])['is_active'] assert is_active == False # get handle wenyao_profile = user_profile(wenyao_dict['token'], wenyao_dict['u_id']) handle = wenyao_profile['user']['handle_str'] # check the return value for channel_message message_dict = channel_messages(wenyao_dict['token'], channel_team1['channel_id'], 0) msg = handle + ': ' + "Hi" + '\n' + handle + ': ' + "Hello" assert message_dict['messages'][0]['message'] == msg
def stand_send(): data = request.get_json() token = str(data["token"]) channel_id = int(data["channel_id"]) message = str(data["message"]) standup_send(token, channel_id, message) return dumps({})
def test_standup_start_simple(): clear() user1, user2 = register_n_users(2) # Create channel and join channel = channels_create(user1["token"], "channel1", is_public=True) channel_join(user2["token"], channel["channel_id"]) # Start the standup period standup = standup_start(user1["token"], channel["channel_id"], 1) assert standup["time_finish"] == round(time() + 1) # Send two standup message standup_send(user1["token"], channel["channel_id"], "test1") standup_send(user2["token"], channel["channel_id"], "test2") # Assert the messages are empty messages = channel_messages(user1["token"], channel["channel_id"], 0)["messages"] assert len(messages) == 0 # Assert the two message has been sent when the standup period finishes sleep(2) messages = channel_messages(user1["token"], channel["channel_id"], 0)["messages"] assert len(messages) == 1 user1_profile = user_profile(user1["token"], user1["u_id"])["user"] user1_handle = user1_profile["handle_str"] user2_handle = user_profile(user2["token"], user2["u_id"])["user"]["handle_str"] assert messages[0][ "message"] == f"{user1_handle}: test1\n{user2_handle}: test2" assert messages[0]["u_id"] == user1_profile["u_id"]
def test_standup_send_during_standup(): ''' Test that messages sent during the standup period are not actually sent untill after, and then, all as one message ''' clear() user = auth_register("*****@*****.**", "password", "Firstname", "Lastname") channel = channels_create(user['token'], "Channel", True) standup_start(user['token'], channel['channel_id'], 1) standup_send(user['token'], channel['channel_id'], "message1") check = search(user['token'], "message1") assert len(check['messages']) == 0 standup_send(user['token'], channel['channel_id'], "message2") check = search(user['token'], "message2") assert len(check['messages']) == 0 time.sleep(4) check = search(user['token'], "message") assert len(check['messages']) == 1 name = user_profile(user['token'], user['u_id'])['user']['handle_str'] assert check['messages'][0][ 'message'] == name + ": message1" + '\n' + name + ": message2"
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')
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, }
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, }
def test_standup_send_handle(): """ Tests if standup_start and standup_send works. """ clear() user1 = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins") channel_dict = channels.channels_create(user1['token'], "test_channel", True) user.user_profile_sethandle(user1['token'], 'handle') standup.standup_start(user1['token'], channel_dict['channel_id'], 3) standup.standup_send(user1['token'], channel_dict['channel_id'], "message1") time.sleep(5) standup.standup_active(user1['token'], channel_dict['channel_id']) message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0) assert message_dict['messages'][0]['message'] == ("handle: message1") user.user_profile_sethandle(user1['token'], 'eren') standup.standup_start(user1['token'], channel_dict['channel_id'], 3) standup.standup_send(user1['token'], channel_dict['channel_id'], "message1") time.sleep(5) standup.standup_active(user1['token'], channel_dict['channel_id']) message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0) assert message_dict['messages'][0]['message'] == ("eren: message1")
def test_standup_send_functionality(create_owner_with_channel_and_user): ''' Checks that standup_send actually works correctly and sends through a message in the correct format ''' owner = create_owner_with_channel_and_user['owner'] channel_1 = create_owner_with_channel_and_user['channel_1'] user = create_owner_with_channel_and_user['user'] standup.standup_start(owner['token'], channel_1['channel_id'], 2) standup.standup_send(owner['token'], channel_1['channel_id'], "Message 1 sent") standup.standup_send(user['token'], channel_1['channel_id'], "Message 2 sent") expected_message = '''homersimpson: Message 1 sent\nbartsimpson: Message 2 sent''' time.sleep(2) message_list = channel.channel_messages(owner['token'], channel_1['channel_id'], 0) standup_message = message_list['messages'][0] assert standup_message['message_id'] == 1 assert standup_message['u_id'] == owner['u_id'] assert standup_message['message'] == expected_message
def test_standup_send_valid(): ''' Test validly sending messages to get buffered in the standup queue ''' clear() # Set up users and channel f_owner = auth_register('*****@*****.**', 'password', 'Flockr', 'Owner') f_user = auth_register('*****@*****.**', 'password', 'Random', 'User') f_channel = channels_create(f_owner['token'], 'Test Channel', True) channel_join(f_user['token'], f_channel['channel_id']) # Start standup for 5 seconds standup_start(f_owner['token'], f_channel['channel_id'], 5) # Users send messages during the standup message1 = 'F' * 1000 message2 = 'X' * 1000 for _ in range(0, 3): standup_send(f_owner['token'], f_channel['channel_id'], message1) standup_send(f_user['token'], f_channel['channel_id'], message2) # Check only one message (containing all the standup messages) is sent after the standup ends time.sleep(6) messages = channel_messages(f_owner['token'], f_channel['channel_id'], 0) assert len(messages['messages']) == 1
def test_send_multiple(): """ Test if the standup_send can combine multiple message from send message """ channel_creater = auth.auth_register("*****@*****.**", "password", "Quick", "Shadow") test_user1 = auth.auth_register("*****@*****.**", "password", "Optimus", "Prime") test_channel_id1 = channels.channels_create(channel_creater["token"], "test1", True) channel.channel_join(test_user1["token"], test_channel_id1["channel_id"]) standup.standup_start(channel_creater["token"], test_channel_id1["channel_id"], 1) creater_profile = user.user_profile(channel_creater["token"], channel_creater["u_id"]) test_user_profile = user.user_profile(test_user1["token"], test_user1["u_id"]) new_message = "Know the new message" new_message2 = "Second message" standup.standup_send(channel_creater["token"], test_channel_id1["channel_id"], new_message) standup.standup_send(test_user1["token"], test_channel_id1["channel_id"], new_message2) inserted_message = creater_profile["user"][ "handle_str"] + ": " + new_message + "\n" inserted_message += test_user_profile["user"][ "handle_str"] + ": " + new_message2 + "\n" time.sleep(2) message_from_channel = channel.channel_messages( channel_creater["token"], test_channel_id1["channel_id"], 0) assert inserted_message == message_from_channel["messages"][0]["message"] assert channel_creater["u_id"] == message_from_channel["messages"][0][ "u_id"] other.clear()
def test_standup_send_invalid_channel(): """Tests standup_send when given Channel ID is not a valid channel""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") with pytest.raises(InputError): standup_send(valid_user["token"], 12341235, "stand the f*** up!")
def test_standup_send_inactive(): """ Tests if standup_send raises an InputError if no standup is active. """ user = auth.auth_register("*****@*****.**", "password", "Purple", "TellyTubby") channel_dict = channels.channels_create(user['token'], "test_channel", False) with pytest.raises(error.InputError): standup.standup_send(user['token'], channel_dict['channel_id'], "message")
def test_standup_send_no_active_standup(): clear() user1 = register_n_users(1) channel = channels_create(user1["token"], "channel1", is_public=True) with pytest.raises(InputError): standup_send(user1["token"], channel["channel_id"], "Test")
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)
def test_send_error_invalid_msg(initial_data): ''' error test when msg is too long (1000 characters) user1 calls start in channel1 and send a too long msg ''' standup_start(users[0]['token'], channels[0]['channel_id'], 1) with pytest.raises(InputError): standup_send(users[0]['token'], channels[0]['channel_id'], 'm' * 1001)
def test_send_error_invalid_channel(initial_data): ''' error test when given channel_id is invalid channel_id does not exist ''' # non-existing channel with id 0 with pytest.raises(InputError): standup_send(users[0]['token'], 0, 'msg')
def standup_send(): """ Function standup send route """ message_info = request.get_json() standup.standup_send(message_info['token'], int(message_info['channel_id']), message_info['message']) return dumps({})
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')
def test_send_error_not_member(initial_data): ''' error test when standup_send to wrong channel user 1 calls start in channel1 user 3 calls standup_send to channel1 ''' standup_start(users[0]['token'], channels[0]['channel_id'], 1) with pytest.raises(AccessError): standup_send(users[2]['token'], channels[0]['channel_id'], 'msg')
def test_send_error_not_active(initial_data): ''' error test when standup is not active in given channel user 1 calls start in channel 1 user 3 calls send in chanenl 2 ''' standup_start(users[0]['token'], channels[0]['channel_id'], 1) with pytest.raises(InputError): standup_send(users[2]['token'], channels[1]['channel_id'], 'msg')
def test_standup_send_none_active(): """Tests sending a standup message on a channel that currently has no standup running""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "new_channel", False) with pytest.raises(InputError): standup_send(valid_user["token"], new_channel["channel_id"], "stand the f*** up!")
def test_standup_send_invalid_token(): """Tests passing an invalid token to standup_send""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "invalid_channel", False) standup_start(valid_user["token"], new_channel["channel_id"], 3) with pytest.raises(AccessError): standup_send(90000, new_channel["channel_id"], "Waow iteration3")
def test_standup_send_invalid_user(): """Tests passing a token of a non-existent user to standup_send""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "invalid_channel", False) standup_start(valid_user["token"], new_channel["channel_id"], 5) with pytest.raises(AccessError): standup_send("9001", new_channel["channel_id"], "HECK YEAH")
def test_time_standup(): """ Tests if standup_start and standup_send works. """ clear() user = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins") channel = channels.channels_create(user['token'], "name", True) standup.standup_start(user['token'], channel['channel_id'], 2) with pytest.raises(error.InputError): standup.standup_send(user['token'], channel['channel_id'], "a"*1001)
def test_standupsend_name_invalid(): ''' Invalid channel_id ''' clear() user = auth.auth_register("*****@*****.**", "password", "First", "Last") channel = channels.channels_create(user['token'], "name", True) standup.standup_start(user['token'], channel["channel_id"], 1) with pytest.raises(error.InputError): standup.standup_send(user['token'], channel["channel_id"], "a"*1001) time.sleep(2)
def test_notactive_standupsend(): ''' If standup is not active and try to send ''' clear() user = auth.auth_register("*****@*****.**", "password", "First", "Last") channel = channels.channels_create(user['token'], "name", True) with pytest.raises(error.InputError): standup.standup_send(user['token'], channel['channel_id'], "Jin")
def test_standup_send_message_too_long(): """Tests standup_send when given Message is more than 1000 characters""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "new_channel", False) letters_and_digits = string.ascii_letters + string.digits long_str = (random.choice(letters_and_digits) for c in range(1001)) with pytest.raises(InputError): standup_send(valid_user["token"], new_channel["channel_id"], "".join(long_str))
def test_standup_send_standup_not_active(): ''' Test that standup_send raises an InputError if called while a standup is not currently active ''' clear() user = auth_register("*****@*****.**", "password", "Firstname", "Lastname") channel = channels_create(user['token'], "Channel", True) with pytest.raises(InputError): standup_send(user['token'], channel['channel_id'], "message")