def test_standup_active_not_active(url, user_1, user_2, user_3,
                                   public_channel_1):
    """Testing when standup is not active
    """
    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)
    time.sleep(4)

    information = request_standup_active(
        url, user_1['token'], public_channel_1['channel_id']).json()
    assert not information['is_active']
    assert information['time_finish'] == None

    information = request_standup_active(
        url, user_2['token'], public_channel_1['channel_id']).json()
    assert not information['is_active']
    assert information['time_finish'] == None

    information = request_standup_active(
        url, user_3['token'], public_channel_1['channel_id']).json()
    assert not information['is_active']
    assert information['time_finish'] == None
    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_react_output_another_user_thumbs_down(url, user_1, user_2, public_channel_1, default_message):
    """Test if another user can react a message created by another user (thumbs down).
    """
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id'])
    request_message_react(url, user_2['token'], default_message['message_id'], THUMBS_DOWN)
    channel_details = request_channel_messages(url, user_2['token'], public_channel_1['channel_id'], 0).json()
    message_details = channel_details['messages'][0]
    assert message_details['reacts'][1]['react_id'] == THUMBS_DOWN
    assert message_details['reacts'][1]['u_ids'] == [user_2['u_id']]
    assert message_details['reacts'][1]['is_this_user_reacted'] == True
    assert message_details['reacts'][0]['u_ids'] == []
def test_react_output_is_this_user_reacted_false_thumbs_down(url, user_1, user_2, public_channel_1, default_message):
    """Test is_this_user_reacted field is false for another user that has not
    reacted to a message that has been reacted by another user (thumbs down).
    """
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id'])
    request_message_react(url, user_2['token'], default_message['message_id'], THUMBS_DOWN)
    channel_details = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json()
    message_details = channel_details['messages'][0]
    assert message_details['reacts'][1]['react_id'] == THUMBS_DOWN
    assert message_details['reacts'][1]['u_ids'] == [user_2['u_id']]
    assert message_details['reacts'][1]['is_this_user_reacted'] == False
    assert message_details['reacts'][0]['u_ids'] == []
def test_react_output_user_leaves_state_thumbs_down(url, user_1, user_2, public_channel_1, thumbs_down_default_message):
    """(Assumption testigng): Test when a user leaves that all the messages that
    they reacted previously persist in the channel details. (thumbs down)
    """
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id'])
    request_channel_leave(url, user_1['token'], public_channel_1['channel_id'])
    channel_details = request_channel_messages(url, user_2['token'], public_channel_1['channel_id'], 0).json()
    message_details = channel_details['messages'][0]
    assert message_details['reacts'][0]['react_id'] == THUMBS_UP
    assert message_details['reacts'][0]['u_ids'] == []
    assert message_details['reacts'][0]['is_this_user_reacted'] == False

    assert message_details['reacts'][1]['u_ids'] == [user_1['u_id']]
    assert message_details['reacts'][1]['is_this_user_reacted'] == False
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_react_output_multiple_users_react(url, user_1, user_2, user_3, user_4, public_channel_1, default_message):
    """Testing process where multiple users likes and dislike a message
    """
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_2['u_id'])
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_3['u_id'])
    request_channel_invite(url, user_1['token'], public_channel_1['channel_id'], user_4['u_id'])

    request_message_react(url, user_1['token'], default_message['message_id'], THUMBS_UP)
    request_message_react(url, user_2['token'], default_message['message_id'], THUMBS_UP)
    request_message_react(url, user_3['token'], default_message['message_id'], THUMBS_DOWN)
    request_message_react(url, user_4['token'], default_message['message_id'], THUMBS_UP)

    channel_details = request_channel_messages(url, user_1['token'], public_channel_1['channel_id'], 0).json()
    message_details = channel_details['messages'][0]
    assert message_details['reacts'][0]['react_id'] == THUMBS_UP
    assert sorted(message_details['reacts'][0]['u_ids']) == sorted([user_1['u_id'], user_2['u_id'], user_4['u_id']])
    assert message_details['reacts'][0]['is_this_user_reacted'] == True

    assert message_details['reacts'][1]['react_id'] == THUMBS_DOWN
    assert sorted(message_details['reacts'][1]['u_ids']) == [user_3['u_id']]
    assert message_details['reacts'][1]['is_this_user_reacted'] == False
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')