def test_channel_details(): ''' Testing cases of channel_details ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] channel_id_private = channel_create(token, 'privateChannel', 'false') third_token = auth_register('*****@*****.**', 'pass134124', 'lol', 'lmao')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') channel_id_private = channel_create(token, 'privateChannel', 'false') # END SETUP # Invalid token with pytest.raises(AccessError): channel_details('invalidToken', channel_id_public) # User is not part of target channel with pytest.raises(AccessError): channel_details(third_token, channel_id_private) # Working channel details channel_join(second_token, channel_id_public) channel_details(token, channel_id_public) channel_details(second_token, channel_id_public)
def test_remove_owner(): ''' Test remove as an owner of the channel ''' reset_data() # SETUP registered_user = auth_register("*****@*****.**", "123456", "John", "Smith") first_token = registered_user['token'] c_id = channel_create(first_token, "Channel1", 'true') # Add two messages message_send(first_token, c_id, "Hello world!") message_list = get_messages(c_id) # Login as a new user registered_user = auth_register("*****@*****.**", "1password", "Bob", "Smith") token = registered_user['token'] u_id = registered_user['u_id'] # Set new user as a channel owner channel_join(token, c_id) channel_addowner(first_token, c_id, u_id) # SETUP END msg1_id = get_message_id(message_list, "Hello world!") message_remove(token, msg1_id) message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") is None
def test_channel_addowner(): ''' The following test's various cases of channel_addowner ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] creator_id = token_to_user(token) channel_id_public = channel_create(token, 'newChannel', 'true') second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] second_user_id = token_to_user(second_token) third_token = auth_register('*****@*****.**', 'pass134124', 'lol', 'lmao')['token'] third_user_id = token_to_user(third_token) # END SETUP # Invalid token with pytest.raises(AccessError): channel_addowner('invalidToken', channel_id_public, second_user_id) # Invalid channel ID with pytest.raises(ValueError): channel_addowner(token, 666, second_user_id) # trying to add when user is not in the channel with pytest.raises(ValueError): channel_addowner(second_token, channel_id_public, third_user_id) # trying to add random channel with pytest.raises(ValueError): channel_addowner(second_token, 999, third_user_id) # User is already an owner second_channel_id = channel_create(third_token, 'anotherCHannel', 'true') with pytest.raises(ValueError): channel_addowner(token, second_channel_id, third_user_id) # When user is not an admin or owner channel_join(second_token, channel_id_public) channel_join(third_token, channel_id_public) with pytest.raises(AccessError): channel_addowner(second_token, channel_id_public, third_user_id) # Attempting to change permission of Slackr creator with pytest.raises(AccessError): channel_addowner(second_token, channel_id_public, creator_id) # Working addowner channel_addowner(token, channel_id_public, third_user_id)
def test_channel_join(): ''' The following tests channel_join add's a user to channel ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') channel_id_private = channel_create(token, 'privateChannel', 'false') # END SETUP # Invalid channel ID with pytest.raises(ValueError): channel_join(token, 666) # Invalid token with pytest.raises(AccessError): channel_join('invalidToken', channel_id_public) # Trys to join private channel with pytest.raises(AccessError): channel_join(token, channel_id_private) # Working channel_join channel_join(token, channel_id_public)
def test_channel_messages(): ''' Testing cases of channel_messages ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] third_token = auth_register('*****@*****.**', 'pass134124', 'lol', 'lmao')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') channel_id_private = channel_create(token, 'privateChannel', 'false') # END SETUP # Calling Channel messages when there are no messages with pytest.raises(ValueError): channel_messages(token, channel_id_public, 0) # Functioning channel messages base case message_send(token, channel_id_public, "Hello") channel_messages(token, channel_id_public, 0) # Calling Channel messages when current user is not in the target channel # and target channel is private message_send(token, channel_id_private, "Hi") with pytest.raises(AccessError): channel_messages(second_token, channel_id_private, 0) # Sending 123 messages and reacting message_react(token, 0, 1) channel_join(second_token, channel_id_public) message_react(second_token, 0, 1) channel_join(third_token, channel_id_public) message_send(third_token, channel_id_public, "Hey") counter = 2 while counter < 124: message_send(token, channel_id_public, "Hello") counter = counter + 1 # Testing case where end = -1 channel_messages(token, channel_id_public, 0) channel_messages(token, channel_id_public, 50) channel_messages(token, channel_id_public, 100)
def test_channel_removeowner(): ''' Testing cases of channel_removeowner ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] creator_id = token_to_user(token) channel_id_public = channel_create(token, 'newChannel', 'true') second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] second_user_id = token_to_user(second_token) third_token = auth_register('*****@*****.**', 'pass134124', 'lol', 'lmao')['token'] third_user_id = token_to_user(third_token) fourth_token = auth_register('*****@*****.**', 'pass13424', 'Troye', 'Bob')['token'] fourth_user_id = token_to_user(fourth_token) # END SETUP # Trying to remove someone not in the channel with pytest.raises(ValueError): channel_removeowner(token, channel_id_public, fourth_user_id) # Invalid token with pytest.raises(AccessError): channel_removeowner('invalidToken', channel_id_public, second_user_id) # Invalid channel ID with pytest.raises(ValueError): channel_removeowner(token, 666, third_user_id) # User already not an owner channel_join(fourth_token, channel_id_public) with pytest.raises(ValueError): channel_removeowner(token, channel_id_public, fourth_user_id) # User is not an admin or owner channel_join(second_token, channel_id_public) channel_join(third_token, channel_id_public) channel_addowner(token, channel_id_public, second_user_id) with pytest.raises(AccessError): channel_removeowner(third_token, channel_id_public, second_user_id) # Attempting to change permission of Slackr creator with pytest.raises(AccessError): channel_removeowner(second_token, channel_id_public, creator_id) # Working removeowner channel_join(third_token, channel_id_public) channel_addowner(token, channel_id_public, third_user_id) channel_removeowner(token, channel_id_public, third_user_id)
def test_channels_listall(): ''' Testing cases of channel_listall ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] channel_id_public = channel_create(token, 'Cool', 'true') channel_join(second_token, channel_id_public) # END SETUP # Invalid token with pytest.raises(AccessError): channels_listall('invalidToken') # Working chanels_list channels_listall(token) channels_listall(second_token)
def test_message_react_another(): ''' Test message_react as another member ''' reset_data() # SETUP START token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') msg_id = message_send(token, channel_id_public, "firstMessage") # SETUP END react_id = 1 # Working react message_react(token, msg_id, react_id) # React as another user channel_join(second_token, 0) message_react(second_token, msg_id, react_id)
def test_message_unpin(): ''' Test working message_unpin and all its errors ''' reset_data() # SETUP START token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') msg_id = message_send(token, channel_id_public, "firstMessage") # SETUP END # Invalid token with pytest.raises(AccessError): message_unpin('invalidToken', msg_id) # msg_id is invalid with pytest.raises(ValueError): message_unpin(token, 666) # User is not in the channel with pytest.raises(AccessError): message_unpin(second_token, msg_id) # User is not authorised channel_join(second_token, channel_id_public) with pytest.raises(ValueError): message_unpin(second_token, msg_id) # Working unpin message_pin(token, msg_id) message_unpin(token, msg_id) # Message not pinned with pytest.raises(ValueError): message_unpin(token, msg_id)
def test_edit_owner(): ''' Test edit as the owner of the channel ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') first_token = registered_user['token'] c_id = channel_create(first_token, "Channel1", 'true') # Add two messages message_send(first_token, c_id, "Hello world!") message_send(first_token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" # Login as a new user registered_user = auth_register("*****@*****.**", "1password", "Bob", "Smith") token = registered_user['token'] u_id = registered_user['u_id'] # Set new user as a channel owner channel_join(token, c_id) channel_addowner(first_token, c_id, u_id) msg1_id = get_message_id(message_list, "Hello world!") msg2_id = get_message_id(message_list, "another message") # SETUP END message_edit(token, msg1_id, "Updated message") message_list = get_messages(c_id) assert find_message(message_list, "Updated message") == "Updated message" message_edit(token, msg2_id, "Another update") message_list = get_messages(c_id) assert find_message(message_list, "Another update") == "Another update"
def test_channel_leave(): ''' The following test's various sections of channel_leave ''' reset_data() # START SETUP token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] token2 = auth_register('*****@*****.**', 'pass123', 'john2', 'apple2')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') # END SETUP # Invalid channel ID with pytest.raises(ValueError): channel_leave(token, 666) # Invalid token with pytest.raises(AccessError): channel_leave('invalidToken', channel_id_public) # Working channel leave channel_join(token2, channel_id_public) channel_leave(token2, channel_id_public)