コード例 #1
0
def test_remove_user(new_user, new_user_2):
	glob_users = get_users()
	channel = channels_create(new_user['token'], "new_channel", False)
	channel_invite(new_user['token'], channel['channel_id'], new_user_2['u_id'])
	user_remove(new_user['token'], new_user_2['u_id'])
	assert not new_user_2 in get_channels()[channel['channel_id']]['members']
	with pytest.raises(InputError):
		auth_login(glob_users[new_user_2['u_id']]['email'], glob_users[new_user_2['u_id']]['password_hash'])
コード例 #2
0
ファイル: backup.py プロジェクト: Kevinwochan/Slackr
def backup_data():
    '''Pickles slackr data with a timestamp.'''
    slackr_data = {
        'timestamp': get_current_timestamp(),
        'global_users': get_users(),
        'global_channels': get_channels(),
        'global_num_messages': get_num_messages()
    }
    with open('slackr_data.p', 'wb') as FILE:  #pylint: disable=invalid-name
        dump(slackr_data, FILE)
コード例 #3
0
ファイル: channels.py プロジェクト: Kevinwochan/Slackr
def channels_list(token):
    '''
    Loops through CHANNELS and generates a list of only the channels which
    contain the user as a member or as an owner
    '''
    u_id = check_token(token)
    glob_channels = get_channels()

    return {
        'channels': [{
            'channel_id': channel_id,
            'name': glob_channels[channel_id]['name']
        } for channel_id in glob_channels
                     if is_user_a_member(channel_id, u_id)]
    }
コード例 #4
0
ファイル: other.py プロジェクト: Kevinwochan/Slackr
def search(token, query_str):
    ''' finds all messages containing the query str '''
    user_id = check_token(token)

    search_results = []
    channels = get_channels()
    for channel_id in channels:
        if not is_user_a_member(channel_id, user_id):
            continue
        for message in channels[channel_id]['messages']:
            if query_str in message['message']:
                search_results.append(message)
    sorted(search_results,
           key=lambda message: message['time_created'],
           reverse=True)
    set_reacted_messages(user_id, search_results)
    return {'messages': search_results}
コード例 #5
0
ファイル: utils_test.py プロジェクト: Kevinwochan/Slackr
def test_application_clean():
    '''
    Tests that all global variables have been emptied by the reset
    '''
    for new_user in range(100):
        user = auth_register("z55555" + str(new_user) + "@unsw.edu.au",
                             "f for hayden rip", "hydaen", "smith")
        channels_create(user['token'], "test channel" + str(new_user), True)
    workspace_reset()
    assert len(get_channels().keys()) == 0
    assert len(get_users().keys()) == 0
    assert len(get_users()) == 0
    assert len(get_slackr_owners()) == 0
    assert len(get_valid_tokens()) == 0
    original_image_folder = os.path.join(os.getcwd(), 'images/original')
    assert len(os.listdir(original_image_folder)) == 1
    cropped_image_folder = os.path.join(os.getcwd(), 'images/cropped')
    assert len(os.listdir(cropped_image_folder)) == 1
コード例 #6
0
ファイル: standup.py プロジェクト: Kevinwochan/Slackr
def standup_end(channel_id):
    '''
    replaces placeholder message_id with the next available message id,
    uses str.join() to turn the message list into a string separated by newlines
    appends this new message to the list of messages in the given channel, and removes that
    channel id from the list of active standups
    if there no messages were sent during the standup, the standup is not added to the list of
    messages, but is still removed from the list of active standups
    '''
    glob_channels = get_channels()
    glob_standups = get_standups()
    message_lst = glob_standups[channel_id]['message']
    if len(message_lst) > 0:
        glob_standups[channel_id]['message_id'] = get_message_id()
        glob_standups[channel_id]['message'] = '\n'.join(message_lst)
        glob_channels[channel_id]['messages'].insert(
            0, glob_standups.pop(channel_id))
    else:
        glob_standups.pop(channel_id)
コード例 #7
0
ファイル: hangman.py プロジェクト: Kevinwochan/Slackr
def guess(message, channel_id, user_id, time_created, message_id):
    '''
    this function is called everytime a user makes a guess
    the guessed letter is not counted if the letter is already in GUESSES
    and then calls on other funcitons to change the state of the game

    :param letter: str, assume len(str) == 1
    :rtype str
    '''
    message_split = message.split(' ')
    if len(message_split) != 2:
        message = "guess must be a single letter of the english alphabet e.g '/guess a'"

    if not has_hangman_started(channel_id):
        message = 'start a new hangman game with /hangman'

    elif data[channel_id]['state'] == STATES['WIN'] or data[channel_id][
            'state'] == STATES['LOSE']:
        message = 'start a new hangman game with /hangman'
    else:
        letter = message_split[1]
        if len(
                letter
        ) != 1 or letter in string.punctuation or letter == ' ' or letter.isdigit(
        ):
            message = "guess must be a single letter of the english alphabet e.g '/guess a'"

        elif letter in data[channel_id]['guesses']:
            message = 'you have already guessed this'
        else:
            data[channel_id]['guesses'].append(letter)
            if letter in data[channel_id]['answer']:
                correct_guess(channel_id)
            else:
                wrong_guess(channel_id)
            message = get_text(channel_id)
    channel = get_channels()[channel_id]
    print(data)
    channel['messages'].insert(
        0,
        src.message.create_message(user_id, message_id, time_created, message))
コード例 #8
0
def user_remove(token, u_id):
    '''
    Removes a user from a channel, only a slackr Owner can use this function
    '''
    host_user_id = check_token(token)

    if not is_valid_user(u_id):
        raise InputError

    if not host_user_id in get_slackr_owners():
        raise AccessError

    for channel_id in get_channels():
        if is_user_a_owner(channel_id, u_id):
            get_channel_owners(channel_id).remove(u_id)
        elif is_user_a_member(channel_id, u_id):
            get_channel_members(channel_id).remove(u_id)

    glob_users = get_users()
    glob_users[u_id]['disabled'] = True
    return {}
コード例 #9
0
ファイル: hangman.py プロジェクト: Kevinwochan/Slackr
def start_hangman(channel_id, user_id, time_created, message_id):
    ''' initalisise a hangman game on a channel and inserts the response in the channel'''
    channel = get_channels()[channel_id]
    if has_hangman_started(channel_id):
        channel['messages'].insert(
            0,
            src.message.create_message(
                user_id, message_id, time_created,
                'A game of hangman is already in progress'))
        return

    new_word = generate_random_answer()
    data[channel_id] = {
        'answer': new_word,
        'guesses': [],
        'state': STATES['PROGRESS_1']
    }
    print(data)
    channel['messages'].insert(
        0,
        src.message.create_message(
            user_id, message_id, time_created,
            'HANGMAN STARTED\nguess a letter with /guess'))