예제 #1
0
def test_get_me(env):
    user_1 = env['directory']['users']['user-1']['user']
    token = env['directory']['users']['user-1']['token']
    resp = util.get_request(config.GET_USER_ROUTE, util.make_headers(token))
    if resp['id'] != user_1['id']:
        raise ValueError('Wrong user id returned from: {}'.format(
            config.GET_USER_ROUTE))
예제 #2
0
def send_messages(channel, user_1, user_2):
    use_first_user = True
    URL = config.MESSAGE_ROUTE.format(channel['id'])
    for msg in config.MELIAN_DIALOGE:
        token = user_1['token'] if use_first_user else user_2['token']
        util.post_request(URL, util.make_headers(token), _make_chat_msg(msg))
        use_first_user = not use_first_user
예제 #3
0
def test_get_channels(channel, game_id, token):
    URL = config.GET_CHANNEL_ROUTE.format(game_id)
    recieved_channels = util.get_request(URL, util.make_headers(token))
    if len(recieved_channels) != 1:
        raise ValueError('Wrong number of channels: {}'.format(len(recieved_channels)))
    if recieved_channels[0]['id'] != channel['id']:
        raise ValueError('Wrong channel returned: {}'.format(channel['id']))
예제 #4
0
def create_users(users):
    """Creates directory users in chat db

    :param users: List of users to create.
    """
    tokens = [user['token'] for user in users]
    for token in tokens:
        util.post_request(config.CHAT_USER_ROUTE, util.make_headers(token))
예제 #5
0
def delete_users(users):
    """Deletes directory users by first creating them.

    :param users: List of users to create.
    """
    create_users(users)
    tokens = [user['token'] for user in users]
    for token in tokens:
        util.delete_request(config.CHAT_USER_ROUTE, util.make_headers(token))
예제 #6
0
def test_get_users(env):
    ids = [user['user']['id'] for user in env['directory']['users'].values()]
    get_users_route = '{}?{}'.format(config.GET_USERS_ROUTE,
                                     util.create_query('userId', ids))
    token = env['directory']['users']['user-1']['token']
    users = util.get_request(get_users_route, util.make_headers(token))
    found_ids = set([user['id'] for user in users])
    for id in ids:
        if not id in found_ids:
            raise ValueError(f'Id: {id} not found')
예제 #7
0
def test_get_messages(channel, token):
    URL = config.MESSAGE_ROUTE.format(channel['id'])
    messages = util.get_request(URL, util.make_headers(token))
    if len(messages) != len(config.MELIAN_DIALOGE):
        raise ValueError('Wrong number of messages recieved: {}'.format(len(messages)))
    for i in range(len(messages)):
        expected = config.MELIAN_DIALOGE[i]
        actual = messages[i]
        log.debug('Message Id: {}'.format(actual['id']))
        log.debug(actual['text'])
        if actual['text'] != expected:
            raise ValueError('Wrong message text for message: {}'.format(actual['id']))
예제 #8
0
파일: clean.py 프로젝트: nprapps/leso
#!/usr/bin/env python

import csv
import xlrd

from util import make_headers, clean_data

IMPORT_FILES = [
    'src/Alaska_Louisiana.xls', 'src/Massachussetts_Wyoming_Territories.xls'
]

if __name__ == "__main__":
    for i, filename in enumerate(IMPORT_FILES):
        workbook = xlrd.open_workbook(filename)
        datemode = workbook.datemode
        worksheets = workbook.sheet_names()

        if i == 0:
            headers = make_headers(workbook.sheet_by_name(worksheets[0]))
            headers['federal_supply_class'] = 'federal_supply_class'
            headers['federal_supply_category'] = 'federal_supply_category'
            f = open("src/leso.csv", "w")
            writer = csv.DictWriter(f, fieldnames=headers.values())
            writer.writeheader()

        for worksheet in worksheets:
            sheet = workbook.sheet_by_name(worksheet)
            clean_data(sheet, writer, headers, datemode)
예제 #9
0
def renew_token(token):
    resp = util.get_request(config.RENEW_TOKEN_ROUTE, util.make_headers(token))
    validate_token(resp['token'])
    return resp['token']
예제 #10
0
def login_user(user):
    resp = util.post_request(config.LOGIN_USER_ROUTE, util.make_headers(),
                             user)
    validate_token(resp['token'])
    return resp['token']
예제 #11
0
def create_user(user):
    resp = util.post_request(config.CREATE_USER_ROUTE, util.make_headers(),
                             user)
    validate_token(resp['token'])
    return resp
예제 #12
0
def subscribe_user_to_channel(channel, user):
    URL = config.CHANNEL_ROUTE.format(channel['id'])
    util.put_request(URL, util.make_headers(user['token']))
예제 #13
0
def create_channel(game_id, recievers):
    token = recievers[0]['token']
    channel_route = config.CREATE_CHANNEL_ROUTE.format(game_id)
    query = util.create_query('recieverId', [r['user']['id'] for r in recievers])
    channel = util.post_request(f'{channel_route}?{query}', util.make_headers(token))
    return channel
예제 #14
0
파일: clean.py 프로젝트: Data4America/leso
#!/usr/bin/env python

import csv
import xlrd

from util import make_headers, clean_data

IMPORT_FILES = ['src/Alaska_Louisiana.xls', 'src/Massachussetts_Wyoming_Territories.xls']

if __name__ == "__main__":
    for i, filename in enumerate(IMPORT_FILES):
        workbook = xlrd.open_workbook(filename)
        datemode = workbook.datemode
        worksheets = workbook.sheet_names()

        if i == 0:
            headers = make_headers(workbook.sheet_by_name(worksheets[0]))
            headers['federal_supply_class'] = 'federal_supply_class'
            headers['federal_supply_category'] = 'federal_supply_category'
            f = open("src/leso.csv", "w")
            writer = csv.DictWriter(f, fieldnames=headers.values())
            writer.writeheader()

        for worksheet in worksheets:
            sheet = workbook.sheet_by_name(worksheet)
            clean_data(sheet, writer, headers, datemode)