def test_standup_send_unauthorized_user(url, user_1, user_2, user_3, public_channel_1): """Testing when a user who is not part of the channel tries to send a standup to that channel """ standup_duration = 2 curr_time = int(datetime.now(tz=timezone.utc).timestamp()) information = request_standup_start(url, user_1['token'], public_channel_1['channel_id'], standup_duration).json() assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\ information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) information = request_standup_active( url, user_1['token'], public_channel_1['channel_id']).json() assert information['is_active'] assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\ information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) error = request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code requests.delete(f'{url}/clear')
def test_standup_send_more_than_1000_char(url, user_1, public_channel_1): """Testing when the message to send via standup send is over 1000 characters """ message_str_1 = ("Hello" * 250) message_str_2 = ("HI " * 500) message_str_3 = ("My name is blah" * 100) standup_duration = 2 curr_time = int(datetime.now(tz=timezone.utc).timestamp()) information = request_standup_start(url, user_1['token'], public_channel_1['channel_id'], standup_duration).json() assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\ information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], message_str_1) assert error.status_code == InputError.code error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], message_str_2) assert error.status_code == InputError.code error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], message_str_3) assert error.status_code == InputError.code requests.delete(f'{url}/clear')
def test_standup_send_invalid_channel(url, user_1, user_2): """Testing invalid channel_ids """ error = request_standup_send(url, user_1['token'], -1, 'Hey') assert error.status_code == InputError.code error = request_standup_send(url, user_1['token'], 0, 'Hey') assert error.status_code == InputError.code error = request_standup_send(url, user_2['token'], -10, 'Hey') assert error.status_code == InputError.code requests.delete(f'{url}/clear')
def test_standup_send_working_example(url, user_1, user_2, user_3, public_channel_1): """Testing when standup send is working, via message collation """ assert request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id']).json() == {} assert request_channel_invite(url, user_2['token'], public_channel_1['channel_id'], user_3['u_id']).json() == {} standup_duration = 2 curr_time = int(datetime.now(tz=timezone.utc).timestamp()) information = request_standup_start(url, user_1['token'], public_channel_1['channel_id'], standup_duration).json() assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\ information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) on_list = False user_one_handle = request_user_details( url, user_1['token'], user_1['u_id']).json()['user']['handle_str'] assert request_standup_send(url, user_1['token'], public_channel_1['channel_id'], 'Pizza!').json() == {} message_data = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json() for messages in message_data['messages']: if messages['message'] == f'{user_one_handle}: Pizza!': on_list = True assert not on_list assert request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Water!').json() == {} assert request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Melon!').json() == {} time.sleep(4) on_list = False user_two_handle = request_user_details( url, user_2['token'], user_2['u_id']).json()['user']['handle_str'] user_three_handle = request_user_details( url, user_3['token'], user_3['u_id']).json()['user']['handle_str'] message_data = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json() for messages in message_data['messages']: if messages[ 'message'] == f'{user_one_handle}: Pizza!\n{user_two_handle}: Water!\n{user_three_handle}: Melon!': on_list = True assert on_list requests.delete(f'{url}/clear')
def test_standup_send_invalid_token(url, user_1, user_2, user_3, user_4, public_channel_1): """Testing invalid token for users """ error = request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_4['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code requests.delete(f'{url}/clear')
def test_standup_send_empty_string(url, user_1, public_channel_1): """Testing when the message to send via standup send is empty string """ standup_duration = 2 curr_time = int(datetime.now(tz=timezone.utc).timestamp()) information = request_standup_start(url, user_1['token'], public_channel_1['channel_id'], standup_duration).json() assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\ information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], '') assert error.status_code == InputError.code error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], "") assert error.status_code == InputError.code requests.delete(f'{url}/clear')
def test_standup_send_no_standup(url, user_1, user_2, user_3, public_channel_1): """Testing when no standup is currently running in channel specified """ assert request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id']).json() == {} assert request_channel_invite(url, user_2['token'], public_channel_1['channel_id'], user_3['u_id']).json() == {} error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == InputError.code error = request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == InputError.code error = request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == InputError.code requests.delete(f'{url}/clear')
def test_standup_send_expired_token(url, user_1, user_2, user_3, user_4, public_channel_1): """Testing expired token for users which have logged out """ log_out = requests.post(f'{url}/auth/logout', json={ 'token': user_1['token'] }).json() assert log_out['is_success'] log_out = requests.post(f'{url}/auth/logout', json={ 'token': user_2['token'] }).json() assert log_out['is_success'] log_out = requests.post(f'{url}/auth/logout', json={ 'token': user_3['token'] }).json() assert log_out['is_success'] log_out = requests.post(f'{url}/auth/logout', json={ 'token': user_4['token'] }).json() assert log_out['is_success'] error = request_standup_send(url, user_1['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code error = request_standup_send(url, user_4['token'], public_channel_1['channel_id'], 'Hey') assert error.status_code == AccessError.code requests.delete(f'{url}/clear')
def test_standup_start_working_example(url, user_1, user_2, user_3, public_channel_1): """Testing when standup is working, via message collation """ assert request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id']).json() == {} assert request_channel_invite(url, user_2['token'], public_channel_1['channel_id'], user_3['u_id']).json() == {} standup_duration = 2 curr_time = int(datetime.now(tz=timezone.utc).timestamp()) information = request_standup_start(url, user_1['token'], public_channel_1['channel_id'], standup_duration).json() assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] assert information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY) payload = request_standup_active(url, user_1['token'], public_channel_1['channel_id']).json() assert payload['is_active'] == True on_list = False user_one_handle = request_user_details( url, user_1['token'], user_1['u_id']).json()['user']['handle_str'] assert request_standup_send(url, user_1['token'], public_channel_1['channel_id'], 'Hey guys!').json() == {} message_data = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json() for messages in message_data['messages']: if messages['message'] == f'{user_one_handle}: Hey guys!': on_list = True assert not on_list on_list = False user_two_handle = request_user_details( url, user_2['token'], user_2['u_id']).json()['user']['handle_str'] assert request_standup_send(url, user_2['token'], public_channel_1['channel_id'], 'Its working!').json() == {} message_data = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json() for messages in message_data['messages']: if messages[ 'message'] == f'{user_one_handle}: Hey guys!\n{user_two_handle}: Its working!': on_list = True assert not on_list assert request_standup_send(url, user_3['token'], public_channel_1['channel_id'], 'Wohoo!').json() == {} payload = request_standup_active(url, user_1['token'], public_channel_1['channel_id']).json() assert payload['is_active'] == True time.sleep(4) payload = request_standup_active(url, user_1['token'], public_channel_1['channel_id']).json() assert payload['is_active'] == False on_list = False user_three_handle = request_user_details( url, user_3['token'], user_3['u_id']).json()['user']['handle_str'] message_data = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json() for messages in message_data['messages']: if messages[ 'message'] == f'{user_one_handle}: Hey guys!\n{user_two_handle}: Its working!\n{user_three_handle}: Wohoo!': on_list = True assert on_list requests.delete(f'{url}/clear')