def _add_global_test_data(session): global_passwords['contributor'] = 'super pass' global_passwords['moderator'] = 'even better pass' contributor = User( username='******', email='*****@*****.**', password='******') moderator = User( username='******', email='*****@*****.**', moderator=True, password='******') users = [moderator, contributor] session.add_all(users) session.flush() key = settings['jwtauth.master_secret'] algorithm = 'HS256' now = datetime.datetime.utcnow() exp = now + datetime.timedelta(weeks=10) for user in [moderator, contributor]: claims = create_claims(user, exp) token = jwt.encode(claims, key=key, algorithm=algorithm) add_or_retrieve_token(token, exp, user.id) global_userids[user.username] = user.id global_tokens[user.username] = token
def _add_global_test_data(session): global_passwords['contributor'] = 'super pass' global_passwords['contributor2'] = 'better pass' global_passwords['moderator'] = 'even better pass' contributor_profile = UserProfile( categories=['amateur'], locales=[ DocumentLocale(title='', description='Me', lang='en'), DocumentLocale(title='', description='Moi', lang='fr')], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) contributor = User( name='Contributor', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor_profile) contributor2_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor2 = User( name='Contributor 2', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor2_profile) moderator_profile = UserProfile( categories=['mountain_guide'], locales=[DocumentLocale(title='', lang='en')]) moderator = User( name='Moderator', username='******', email='*****@*****.**', forum_username='******', moderator=True, password='******', email_validated=True, profile=moderator_profile) users = [moderator, contributor, contributor2] session.add_all(users) session.flush() key = settings['jwtauth.master_secret'] algorithm = 'HS256' now = datetime.datetime.utcnow() exp = now + datetime.timedelta(weeks=10) for user in [moderator, contributor, contributor2]: claims = create_claims(user, exp) token = jwt.encode(claims, key=key, algorithm=algorithm). \ decode('utf-8') add_or_retrieve_token(token, exp, user.id) global_userids[user.username] = user.id global_tokens[user.username] = token
def _add_global_test_data(session): global_passwords['contributor'] = 'super pass' global_passwords['contributor2'] = 'better pass' global_passwords['moderator'] = 'even better pass' global_passwords['robot'] = 'bombproof pass' contributor_profile = UserProfile( categories=['amateur'], locales=[ DocumentLocale(title='', description='Me', lang='en'), DocumentLocale(title='', description='Moi', lang='fr')], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) contributor = User( name='Contributor', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor_profile) contributor2_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor2 = User( name='Contributor 2', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor2_profile) contributor3_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor3 = User( name='Contributor 3', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor3_profile) moderator_profile = UserProfile( categories=['mountain_guide'], locales=[DocumentLocale(title='', lang='en')]) moderator = User( name='Moderator', username='******', email='*****@*****.**', forum_username='******', moderator=True, password='******', email_validated=True, profile=moderator_profile) robot_profile = UserProfile( locales=[DocumentLocale(title='', lang='en')]) robot = User( name='Robot', username='******', email='*****@*****.**', forum_username='******', robot=True, password='******', email_validated=True, profile=robot_profile) users = [robot, moderator, contributor, contributor2, contributor3] session.add_all(users) session.flush() domain = 'www.somewhere.com' sso_key = SsoKey( domain=domain, key=domain ) session.add(sso_key) sso_external_id = SsoExternalId( domain=domain, external_id='1', user=contributor, token='token', expire=utc.localize(datetime.datetime.utcnow()), ) session.add(sso_external_id) session.flush() key = settings['jwtauth.master_secret'] algorithm = 'HS256' now = datetime.datetime.utcnow() exp = now + datetime.timedelta(weeks=10) for user in [robot, moderator, contributor, contributor2, contributor3]: claims = create_claims(user, exp) token = jwt.encode(claims, key=key, algorithm=algorithm). \ decode('utf-8') add_or_retrieve_token(token, exp, user.id) global_userids[user.username] = user.id global_tokens[user.username] = token