本文整理汇总了Python中ooiservices.app.models.User.insert_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.insert_user方法的具体用法?Python User.insert_user怎么用?Python User.insert_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ooiservices.app.models.User
的用法示例。
在下文中一共展示了User.insert_user方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app('TESTING_CONFIG')
self.app_context = self.app.app_context()
self.app_context.push()
from sqlalchemy.orm.mapper import configure_mappers
configure_mappers()
db.create_all()
test_username = 'admin'
test_password = 'test'
Organization.insert_org()
User.insert_user(username=test_username, password=test_password, email='[email protected]')
OperatorEventType.insert_operator_event_types()
self.client = self.app.test_client(use_cookies=False)
UserScope.insert_scopes()
admin = User.query.filter_by(user_name='admin').first()
scope = UserScope.query.filter_by(scope_name='asset_manager').first()
admin.scopes.append(scope)
db.session.add(admin)
db.session.commit()
joe = User.insert_user(username='joe', password='joe', email='[email protected]')
bob = User.insert_user(username='bob', password='bob', email='[email protected]')
示例2: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app('TESTING_CONFIG')
self.app_context = self.app.app_context()
self.app_context.push()
self.client = self.app.test_client()
self.basedir = os.path.abspath(os.path.dirname(__file__))
db.create_all()
test_password = 'test'
Organization.insert_org()
UserScope.insert_scopes()
User.insert_user(password=test_password)
self.client = self.app.test_client(use_cookies=False)
# set the vars for the connection
self.cmisUrl = \
'https://alfresco.oceanobservatories.org/alfresco/s/api/cmis'
self.cmisUsername = 'ooinet'
self.cmisPassword = '75commonLIKEbrown76'
self.cmisId = 'c161bc66-4f7e-4a4f-b5f2-aac9fbf1d3cd'
# cmis is tested elsewhere
from cmislib.model import CmisClient
client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
repo = client.getRepository(self.cmisId)
示例3: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app('TESTING_CONFIG')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
self.client = self.app.test_client(use_cookies=False)
Organization.insert_org()
User.insert_user(username=test_username, password=test_password)
UserScope.insert_scopes()
示例4: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app("TESTING_CONFIG")
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
test_password = "test"
Organization.insert_org()
User.insert_user(password=test_password, email="[email protected]")
self.client = self.app.test_client(use_cookies=False)
示例5: add_admin_user
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def add_admin_user(username, password, first_name, last_name, email, org_name):
'''
Creates a 'user_admin' scoped user using the supplied username and password
:param username:
:param password:
:return:
'''
app.logger.info('Insert user_name: %s' % username)
User.insert_user(username=username, password=password, first_name=first_name, last_name=last_name, email=email, org_name=org_name)
admin = User.query.filter_by(user_name=username).first()
admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
db.session.add(admin)
db.session.commit()
示例6: oauth_callback
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def oauth_callback(provider):
# rand_pass will be a new password every time a user logs in
# with oauth.
temp_pass = str(uuid.uuid4())
# lets create the oauth object that will issue the request.
oauth = OAuthSignIn.get_provider(provider)
# assign the response
email, first_name, last_name = oauth.callback()
if email is None:
return unauthorized('Invalid credentials')
# see if this user already exists, and
# and give the user a brand new password.
user = User.query.filter_by(email=email).first()
if user:
user.password = temp_pass
# if there is no user, create a new one and setup
# it's defaults and give it a new password.
else:
user = User.insert_user(password=temp_pass,
username=email,
email=email,
first_name=first_name,
last_name=last_name)
return jsonify({'uuid': temp_pass, 'username': email})
示例7: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app('TESTING_CONFIG')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
test_username = 'admin'
test_password = 'test'
Organization.insert_org()
User.insert_user(username=test_username, password=test_password)
self.client = self.app.test_client(use_cookies=False)
UserScope.insert_scopes()
admin = User.query.filter_by(user_name='admin').first()
scope = UserScope.query.filter_by(scope_name='user_admin').first()
admin.scopes.append(scope)
db.session.add(admin)
db.session.commit()
示例8: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app('TESTING_CONFIG')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
test_password = 'test'
Organization.insert_org()
UserScope.insert_scopes()
User.insert_user(password=test_password)
self.client = self.app.test_client(use_cookies=False)
self.basedir = os.path.abspath(os.path.dirname(__file__))
with open(self.basedir + '/mock_data/event_post.json', 'r') as f:
doc = json.load(f)
self.event_json_in = doc
with open(self.basedir + '/mock_results/event_from.json', 'r') as f:
doc = json.load(f)
self.event_from_json = doc
示例9: setUp
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def setUp(self):
self.app = create_app("TESTING_CONFIG")
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
test_username = "admin"
test_password = "test"
Organization.insert_org()
User.insert_user(username=test_username, password=test_password)
self.client = self.app.test_client(use_cookies=False)
UserScope.insert_scopes()
admin = User.query.filter_by(user_name="admin").first()
scope = UserScope.query.filter_by(scope_name="user_admin").first()
cc_scope = UserScope.query.filter_by(scope_name="command_control").first()
admin.scopes.append(scope)
admin.scopes.append(cc_scope)
db.session.add(admin)
db.session.commit()
self.headers = self.get_api_headers("admin", "test")
示例10: deploy
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def deploy(password, bulkload):
from flask.ext.migrate import upgrade
from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization
from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
from sh import psql
#Create the local database
app.logger.info('Creating DEV and TEST Databases')
psql('-c', 'create database ooiuidev;', '-U', 'postgres')
psql('ooiuidev', '-c', 'create schema ooiui')
psql('ooiuidev', '-c', 'create extension postgis')
#Create the local test database
psql('-c', 'create database ooiuitest;', '-U', 'postgres')
psql('ooiuitest', '-c', 'create schema ooiui')
psql('ooiuitest', '-c', 'create extension postgis')
from sqlalchemy.orm.mapper import configure_mappers
configure_mappers()
db.create_all()
if bulkload:
with open('db/ooiui_schema_data.sql') as f:
psql('ooiuidev', _in=f)
app.logger.info('Bulk test data loaded.')
# migrate database to latest revision
#upgrade()
if not os.getenv('TRAVIS'):
Organization.insert_org()
UserScope.insert_scopes()
app.logger.info('Insert default user, name: admin')
User.insert_user(password=password)
admin = User.query.first()
admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
db.session.add(admin)
db.session.commit()
if bulkload:
with open('db/ooiui_schema_data_notifications.sql') as f:
psql('ooiuidev', _in=f)
app.logger.info('Bulk test data loaded for notifications.')
示例11: test_update_user_event_notification
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def test_update_user_event_notification(self):
verbose = False #self.verbose
root = self.root
if verbose: print '\n'
content_type = 'application/json'
headers = self.get_api_headers('admin', 'test')
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add a second user ('foo', password 'test')
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test_username = 'foo'
test_password = 'test'
test_email = '[email protected]'
Organization.insert_org()
User.insert_user(username=test_username, password=test_password, email=test_email)
self.client = self.app.test_client(use_cookies=False)
UserScope.insert_scopes()
foo = User.query.filter_by(user_name='foo').first()
scope = UserScope.query.filter_by(scope_name='user_admin').first()
foo.scopes.append(scope)
scope = UserScope.query.filter_by(scope_name='redmine').first() # added
foo.scopes.append(scope)
db.session.add(foo)
db.session.commit()
response = self.client.get(url_for('main.get_user',id=1), headers=headers)
self.assertTrue(response.status_code == 200)
response = self.client.get(url_for('main.get_user',id=2), headers=headers)
self.assertTrue(response.status_code == 200)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# # Create alert and an alarm
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ref_def = "CE01ISSP-XX099-01-CTDPFJ999"
# Create an alarm with user_event_notification - uses definition 1 and user_id 1
test_alarm = self.create_alert_alarm_definition(ref_def, event_type='alarm', uframe_id=2, severity=1)
# Create an alarm without user_event_notification - uses definition 1 and user_id 1
bad_alarm = self.create_alert_alarm_definition_wo_notification(ref_def, event_type='alarm',
uframe_filter_id=2, severity=1)
notification = self.create_user_event_notification(bad_alarm.id, 2)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# GET alarm definition by SystemEventDefinition id
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
response = self.client.get(url_for('main.get_alert_alarm_def', id=test_alarm.id), headers=headers)
self.assertEquals(response.status_code, 200)
alarm_definition = json.loads(response.data)
self.assertTrue(alarm_definition is not None)
response = self.client.get(url_for('main.get_alert_alarm_def', id=bad_alarm.id), headers=headers)
self.assertEquals(response.status_code, 200)
bad_alarm_definition = json.loads(response.data)
self.assertTrue(bad_alarm_definition is not None)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Get user_event_notifications (1)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
response = self.client.get(url_for('main.get_user_event_notifications'), headers=headers)
self.assertEquals(response.status_code, 200)
data = json.loads(response.data)
self.assertTrue(data is not None)
notifications = data['notifications']
self.assertTrue(notifications is not None)
self.assertEquals(len(notifications), 2)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Get user_event_notification by id=1
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
url = url_for('main.get_user_event_notification', id=1)
response = self.client.get(url, content_type=content_type, headers=headers)
self.assertEquals(response.status_code, 200)
notification = json.loads(response.data)
self.assertTrue(len(notification) > 0)
self.assertEquals(len(notification), 8)
"""
Error messages for the following tests:
1. bad_notification: {}
2. 'Invalid ID, user_event_notification record not found.'
3. 'Inconsistent ID, user_event_notification id provided in data does not match id provided.'
4. 'Inconsistent User ID, user_id provided in data does not match id.'
5. 'IntegrityError creating user_event_notification.'
6. (no error)
7. 'Insufficient data, or bad data format.'
"""
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (1) Get user_event_notification by id=5 (doesn't exist) response: {}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#.........这里部分代码省略.........
示例12: deploy
# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import insert_user [as 别名]
def deploy(password, production, psqluser):
from flask.ext.migrate import upgrade
from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization
from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
from sh import psql
if production:
app.logger.info('Creating PRODUCTION Database')
try:
psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER')
except:
pass
psql('-c', 'create database ooiuiprod;', '-U', psqluser)
psql('ooiuiprod', '-c', 'create schema ooiui', '-U', psqluser)
psql('ooiuiprod', '-c', 'create extension postgis', '-U', psqluser)
else:
try:
psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER')
except:
pass
#Create the local database
app.logger.info('Creating DEV and TEST Databases')
psql('-c', 'create database ooiuidev;', '-U', psqluser)
psql('ooiuidev', '-c', 'create schema ooiui', '-U', psqluser)
psql('ooiuidev', '-c', 'create extension postgis', '-U', psqluser)
#Create the local test database
psql('-c', 'create database ooiuitest;', '-U', psqluser)
psql('ooiuitest', '-c', 'create schema ooiui', '-U', psqluser)
psql('ooiuitest', '-c', 'create extension postgis', '-U', psqluser)
from sqlalchemy.orm.mapper import configure_mappers
configure_mappers()
db.create_all()
if production:
app.logger.info('Populating Production Database . . .')
with open('db/ooiui_schema_data.sql') as f:
psql('-U', psqluser, 'ooiuiprod', _in=f)
with open('db/ooiui_params_streams_data.sql') as h:
psql('-U', psqluser, 'ooiuiprod', _in=h)
# with open('db/ooiui_vocab.sql') as i:
# psql('-U', psqluser, 'ooiuiprod', _in=i)
app.logger.info('Production Database loaded.')
else:
app.logger.info('Populating Dev Database . . .')
with open('db/ooiui_schema_data.sql') as f:
psql('-U', psqluser, 'ooiuidev', _in=f)
with open('db/ooiui_params_streams_data.sql') as h:
psql('-U', psqluser, 'ooiuidev', _in=h)
# with open('db/ooiui_vocab.sql') as i:
# psql('-U', psqluser, 'ooiuidev', _in=i)
app.logger.info('Dev Database loaded.')
# migrate database to latest revision
#upgrade()
if not os.getenv('TRAVIS'):
UserScope.insert_scopes()
app.logger.info('Insert default user, name: admin')
User.insert_user(password=password)
admin = User.query.first()
admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
admin.scopes.append(UserScope.query.filter_by(scope_name='sys_admin').first())
admin.scopes.append(UserScope.query.filter_by(scope_name='data_manager').first())
admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
db.session.add(admin)
db.session.commit()