def test_fetch_user_type(): config = ( ('itforge', 'group'), ('madspectator', 'user'), ('PimenTechnical', 'channel'), ) for username, type_ in config: ret = fetch_user_type(username) print(username, ret) assert ret == type_
def process_user_type(db, username): username = username.lower() logging.debug('Querying %s type from db' % username) user = db.user.find_one({'username': username}) if user: logging.debug('Record found, type is: %s' % user['type']) return user['type'] else: logging.debug('Doing network request for type of %s' % username) user_type = fetch_user_type(username) logging.debug('Result is: %s' % user_type) if user_type: db.user.find_one_and_update({'username': username}, { '$set': { 'username': username, 'type': user_type, 'added': datetime.utcnow(), } }, upsert=True) return user_type