本文整理汇总了Python中service_api.ServiceApi.update_resource方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceApi.update_resource方法的具体用法?Python ServiceApi.update_resource怎么用?Python ServiceApi.update_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service_api.ServiceApi
的用法示例。
在下文中一共展示了ServiceApi.update_resource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resource_type_edit
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_resource [as 别名]
def resource_type_edit(resource_type, resource_id):
if request.method == 'GET':
resource = ServiceApi.get_prepare(resource_type, resource_id, None, True)
return render_json_response(resource)
if request.method == 'PUT':
data = json.loads(request.data)
resource_obj = data['resource']
resource_assocs = data['assocs']
updated_resource = ServiceApi.update_resource(resource_type, resource_obj, resource_assocs)
return render_json_response(updated_resource)
示例2: page
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_resource [as 别名]
def page(resource_type, resource_id):
if request.is_xhr:
if request.method == 'PUT':
resource_obj = json.loads(request.data)
updated_resource = ServiceApi.update_resource(resource_type, resource_obj)
return render_json_response(updated_resource)
else:
return
else:
return render_app_template(request.path)
示例3: SignIntTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_resource [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)
示例4: DataProductIntTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_resource [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: InstrumentDeviceUnitTest
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_resource [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, [])
#.........这里部分代码省略.........