本文整理汇总了Python中service_api.ServiceApi.signon_user_testmode方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceApi.signon_user_testmode方法的具体用法?Python ServiceApi.signon_user_testmode怎么用?Python ServiceApi.signon_user_testmode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service_api.ServiceApi
的用法示例。
在下文中一共展示了ServiceApi.signon_user_testmode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signon
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
def signon():
def nav():
if 'login_redir' in session:
return redirect(session.pop('login_redir'))
return redirect('/')
user_name = request.args.get('user')
if user_name:
if not PRODUCTION:
ServiceApi.signon_user_testmode(user_name)
return nav()
# carriage returns were removed on the cilogon portal side,
# restore them before processing
raw_cert = request.args.get('cert')
if not raw_cert:
return nav()
certificate = base64.b64decode(raw_cert)
# call backend to signon user
# will stash user id, expiry, is_registered and roles in session
ServiceApi.signon_user(certificate)
return nav()
示例2: SignIntTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
class SignIntTest(unittest.TestCase):
def setUp(self):
self.user = "Beta Operator User"
self.app_client = main.app.test_client()
self.app_context = main.app.test_request_context()
self.sa = ServiceApi()
def tearDown(self):
pass
def test_user_info(self,user="Beta Operator User"):
with self.app_context:
# Make sure the user is signed in
self.sa.signon_user_testmode(self.user)
user_id = flask.session.get('user_id')
actor_id = flask.session.get('actor_id')
username = flask.session.get('name')
is_registered = flask.session.get('is_registered')
self.assertIsNot(user_id, None)
self.assertIsNot(actor_id, None)
self.assertEqual(username, self.user)
self.assertIs(is_registered, True)
self.assertIs(is_it_id(user_id), True)
self.assertTrue(is_it_id(actor_id), 32)
# Get User info
resource_type = 'UserInfo'
resource = self.sa.get_prepare(resource_type, user_id, None, True)
self.assertTrue(resource)
resource_obj = resource.get('resource')
self.assertIsNotNone(resource_obj)
resource_assocs = resource.get('associations')
self.assertIsNotNone(resource_assocs)
contact = resource_obj.get('contact')
city = contact.get('city')
self.assertIsNotNone(city)
# Update city
new_city = 'La Jolla ' + str(int(random.random() * 1000))
resource_obj['contact']['city'] = new_city
updated_resource = self.sa.update_resource(resource_type, resource_obj, resource_assocs)
# Get user info again verify the new city name
resource_temp = self.sa.get_prepare(resource_type, user_id, None, True)
resource_obj_temp = resource_temp.get('resource')
self.assertEqual(resource_obj_temp.get('contact').get('city'), new_city)
示例3: signon
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
def signon():
user_name = request.args.get('user')
if user_name:
ServiceApi.signon_user_testmode(user_name)
return redirect('/')
# carriage returns were removed on the cilogon portal side,
# restore them before processing
raw_cert = request.args.get('cert')
if not raw_cert:
return redirect('/')
certificate = base64.b64decode(raw_cert)
# call backend to signon user
# will stash user id, expiry, is_registered and roles in session
ServiceApi.signon_user(certificate)
if session['is_registered'] == False:
# redirect to registration screen
return redirect('/userprofile')
else:
return redirect('/')
示例4: DataProductIntTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
class DataProductIntTest(unittest.TestCase):
def setUp(self):
self.org_name = "CI Bench Test Facility"
self.user = "Beta Operator User"
self.app_client = main.app.test_client()
self.app_context = main.app.test_request_context()
self.sa = ServiceApi()
def tearDown(self):
pass
def create_new_data_product(self, resource_type, org_id, resource_name=None):
with self.app_context:
# Create a new resource
self.sa.signon_user_testmode(self.user)
instrument_device_id, org_has_resource_instrument_id = self.sa.create_resource(resource_type=resource_type, org_id=org_id, resource_name=resource_name)
self.assertIsNotNone(instrument_device_id)
self.assertIs(is_it_id(instrument_device_id), True)
self.assertIsNotNone(org_has_resource_instrument_id)
self.assertIs(is_it_id(org_has_resource_instrument_id), True)
# Get the data from service gateway and verify
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
resource_association = resource.get('associations')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), resource_name)
# Verify the resource can be updated
new_name = " Unit Test New Instrument Name " + str(int(random.random() * 1000))
resource_obj['name'] = new_name
response = self.sa.update_resource(resource_type, resource_obj, [])
# Verify the name has been updated
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), new_name)
# Put back the name
resource_obj['name'] = resource_name
response = self.sa.update_resource(resource_type, resource_obj, [])
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), resource_name)
# Logout by clearing the session
flask.session.clear()
# Try to update the instrument data as a guest
response = self.sa.update_resource(resource_type, resource_obj, [])
self.assertTrue(len(response) > 0, "Service Gateway is supposed to return unauthorized error for updating a resource as a guest")
error = response[0].get('GatewayError')
self.assertIsNotNone(error, "Service Gateway is supposed to return unauthorized error for updating a resource as a guest")
error = error.get('Exception')
self.assertEqual(error.lower(), "unauthorized", "Service Gateway is supposed to return unauthorized error for updating a resource as a guest")
def test_create_data_product(self):
instrument_name = "Unit Test Data Product " + str(int(random.random() * 1000))
resource_type = 'DataProduct'
org_id = get_org_id(org_name=self.org_name)
self.assertIsNotNone(org_id)
self.assertTrue(is_it_id(org_id))
self.create_new_data_product(resource_type=resource_type, org_id=org_id, resource_name=instrument_name)
示例5: EnrollmentUnitTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
class EnrollmentUnitTest(unittest.TestCase):
def setUp(self):
self.user = "Owen Ownerrep"
self.org_name = "RSN Facility"
self.app_client = main.app.test_client()
self.app_context = main.app.test_request_context()
self.sa = ServiceApi()
self.org_id = get_org_id(org_name=self.org_name)
self.assertIsNotNone(self.org_id)
self.assertTrue(is_it_id(self.org_id), "Org id is set to non id value")
def tearDown(self):
pass
def test_enrollment_accept(self):
negotiation_open = 1
negotiation_accepted = 2
negotiation_rejected = 3
reject = 'reject'
accept = 'accept'
negotiation_type_request = 1
# Request access to RSN Facility
with self.app_context:
self.sa.signon_user_testmode(self.user)
actor_id = flask.session.get('actor_id') if flask.session.has_key('actor_id') else None
resp = ServiceApi.enroll_request(self.org_id, actor_id)
error = resp.get('GatewayError')
self.assertIsNone(error, "Request for enrollment failed. Error: " + str(error))
negotiation_id = resp.get('negotiation_id')
self.assertIsNotNone(negotiation_id, "Request for enrollment failed ")
with self.app_context:
# Verify negotiation is open
self.sa.signon_user_testmode("Tim Ampe")
resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
resource_obj = resource.get('resource')
negotiation_status = resource_obj.get('negotiation_status')
negotiation_type = resource_obj.get('negotiation_type')
self.assertEqual(negotiation_status, negotiation_open)
self.assertEqual(negotiation_type, negotiation_type_request)
# Accept negotiation
rsp = self.sa.accept_reject_negotiation(negotiation_id, accept, 'provider', 'Different roads sometimes lead to the same castle.')
resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
resource_obj = resource.get('resource')
negotiation_status = resource_obj.get('negotiation_status')
negotiation_type = resource_obj.get('negotiation_type')
self.assertEqual(negotiation_status, negotiation_accepted)
#todo remove the enrollment
def test_enrollment_reject(self):
negotiation_open = 1
negotiation_accepted = 2
negotiation_rejected = 3
reject = 'reject'
accept = 'accept'
negotiation_type_request = 1
# Request access to RSN Facility
with self.app_context:
self.sa.signon_user_testmode(self.user)
actor_id = flask.session.get('actor_id') if flask.session.has_key('actor_id') else None
resp = ServiceApi.enroll_request(self.org_id, actor_id)
error = resp.get('GatewayError')
self.assertIsNone(error, "Request for enrollment failed. Error: " + str(error))
negotiation_id = resp.get('negotiation_id')
self.assertIsNotNone(negotiation_id, "Request for enrollment failed ")
with self.app_context:
# Verify negotiation is open
self.sa.signon_user_testmode("Tim Ampe")
resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
resource_obj = resource.get('resource')
negotiation_status = resource_obj.get('negotiation_status')
negotiation_type = resource_obj.get('negotiation_type')
self.assertEqual(negotiation_status, negotiation_open)
self.assertEqual(negotiation_type, negotiation_type_request)
# Reject negotiation
rsp = self.sa.accept_reject_negotiation(negotiation_id, reject, 'provider', 'Different roads sometimes lead to the same castle.')
resource = self.sa.get_prepare("OrgUserNegotiationRequest", negotiation_id, None, True)
resource_obj = resource.get('resource')
negotiation_status = resource_obj.get('negotiation_status')
negotiation_type = resource_obj.get('negotiation_type')
self.assertEqual(negotiation_status, negotiation_rejected)
示例6: InstrumentDeviceUnitTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import signon_user_testmode [as 别名]
class InstrumentDeviceUnitTest(unittest.TestCase):
def setUp(self):
self.user = "Beta Operator User"
self.app_client = main.app.test_client()
self.app_context = main.app.test_request_context()
self.sa = ServiceApi()
def tearDown(self):
pass
def get_instrument_model_id_from_resources(self, model_name, resources):
for resource in resources:
if resource.get('name') == model_name:
return resource.get('_id')
return None
def attachment(self, instrument_id):
'''
with self.app_client as c:
r =c.get('/signon/?user='+self.user)
user_id = flask.session.get('user_id')
self.assertIsNot(user_id, None)
r = c.post('/attachment/', data={
'file': (StringIO('That rug really tied the room together.'), 'unittest.txt'),
'resource_id': instrument_id,
'description': 'This is just a test',
'keywords': 'testing 123',
'created_by': 'the dude',
'modified_by': 'Walter Sobchak',
})
r = r
'''
pass
def create_new_instrument(self, resource_type, org_id, resource_name=None):
with self.app_context:
self.sa.signon_user_testmode(self.user)
instrument_device_id, org_has_resource_instrument_id = self.sa.create_resource(resource_type=resource_type, org_id=org_id, resource_name=resource_name)
self.assertIsNotNone(instrument_device_id)
self.assertIs(is_it_id(instrument_device_id), True)
self.assertIsNotNone(org_has_resource_instrument_id)
self.assertIs(is_it_id(org_has_resource_instrument_id), True)
# get the data from service gateway and verify
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
resource_association = resource.get('associations')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), resource_name)
associate_resource = resource_association.get('InstrumentModel').get('associated_resources')
self.assertEqual(len(associate_resource), 0) # Verify there is no association
# set instrument model
available_resources = resource_association.get('InstrumentModel').get('resources')
instrument_model_name = 'SBE 37-SMP MicroCAT CTD Demo'
instrument_model_id = self.get_instrument_model_id_from_resources(instrument_model_name, available_resources)
self.assertIsNotNone(instrument_model_id, "Could not find " + instrument_model_name + " id from available resources")
instrument_model_obj = self.sa.get_prepare("InstrumentModel", instrument_model_id, None, True)
response = self.sa.update_resource(resource_type, resource_obj, {'InstrumentModel': instrument_model_id})
error = response[0]
self.assertIsNone(error)
# Verify the instrument model association is set correctly
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_association = resource.get('associations')
associated_resource = resource_association.get('InstrumentModel').get('associated_resources')
self.assertEqual(len(associated_resource), 1)
self.assertTrue(instrument_model_id in associated_resource[0].values())
# Update the instrument name
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
new_name = " Unit Test New Instrument Name " + str(int(random.random() * 1000))
resource_obj['name'] = new_name
response = self.sa.update_resource(resource_type, resource_obj, [])
error = response[0]
self.assertIsNone(error, error)
# Verify the name has been updated
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), new_name)
# Put back the name
resource_obj['name'] = resource_name
response = self.sa.update_resource(resource_type, resource_obj, [])
resource = self.sa.get_prepare(resource_type, instrument_device_id, None, True)
resource_obj = resource.get('resource')
self.assertIsNotNone(resource_obj)
self.assertEqual(resource_obj.get('name'), resource_name)
# Logout by clearing the session
flask.session.clear()
# Try to update the instrument data as a guest and verify it fails
response = self.sa.update_resource(resource_type, resource_obj, [])
#.........这里部分代码省略.........