def get_data_definition(self): # Get a cover all data definitions data_defs = [ VoidDefinition(), IntegerDefinition(), DoubleDefinition(), StringDefinition(), SecretDefinition(), BooleanDefinition(), BlobDefinition(), OpaqueDefinition(), OptionalDefinition(IntegerDefinition()), ListDefinition(IntegerDefinition()), StructDefinition('struct', [ ('int', IntegerDefinition()), ('str', StringDefinition()), ('struct', StructDefinition('struct1', [('double', DoubleDefinition()), ('secret', SecretDefinition())])), ('list', ListDefinition(StructDefinition('struct1', [('double', DoubleDefinition()), ('secret', SecretDefinition())]))), ('optional', ListDefinition(StructDefinition('struct1', [('double', DoubleDefinition()), ('secret', SecretDefinition())]))) ]), ErrorDefinition('error', [ ('int', IntegerDefinition()), ('str', StringDefinition()) ]), ] return data_defs
def visit_void(self, typ): """ Visit a void value (i.e. None) :type typ: :class:`VoidType` :param typ: Binding type of the value """ self._out_value = VoidDefinition()
def get_method_definition(self, method_id): name = method_id.get_name() if name == mock_method_name: input_ = mock_input_def else: input_ = input_def output = VoidDefinition() errors = [not_found_error_def] return MethodDefinition(method_id, input_, output, errors)
def test_get_error_definition(self): method_def = MethodDefinition( MethodIdentifier(InterfaceIdentifier('interface'), 'method1'), StructDefinition('method1_input', []), VoidDefinition(), [self.error_def1, self.error_def2, self.error_def3]) self.assertEquals(self.error_def1, method_def.get_error_definition(self.ERROR1_NAME)) self.assertEquals(self.error_def2, method_def.get_error_definition(self.ERROR2_NAME)) self.assertEquals(self.error_def3, method_def.get_error_definition(self.ERROR3_NAME)) self.assertEquals( None, method_def.get_error_definition(self.BOGUS_ERROR_NAME))
def get_method_definition(self, method_id): name = method_id.get_name() if name == 'bogus_method': return None if name == missing_input_definition: input_ = None elif name == invalid_input_definition: input_ = 'not a StructDefinition' elif name == mock_definition: input_ = StructDefinition(OPERATION_INPUT, []) else: input_ = StructDefinition(OPERATION_INPUT, [(param_name, IntegerDefinition())]) if name == missing_output_definition: output = None elif name == invalid_input_definition: output = 'not a DataDefinition' else: output = VoidDefinition() errors = [] if name == report_declared_error: errors.append(not_found_error_def) return MethodDefinition(method_id, input_, output, errors)
field_def = data_def.get_field(field_name) field_instance = build_adhoc_data_value(field_def) instance.set_field(field_name, field_instance) elif data_def.type == Type.LIST: # TODO: Randomize list len? instance.add_all([build_adhoc_data_value(data_def.element_type) for val in range(1,7)]) elif data_def.type == Type.OPTIONAL: # TODO: Randomize optional set or not set? instance = data_def.new_value(build_adhoc_data_value(data_def.element_type)) return instance fake_iface_id = 'vmware.test.fake.iface' null_method_id = 'Null' null_method_def = MethodDefinition(MethodIdentifier( InterfaceIdentifier(fake_iface_id), null_method_id), VoidDefinition(), VoidDefinition(), [make_std_error_def('error1'), make_std_error_def('error2')] ) echo_method_id = 'Echo' echo_method_def = MethodDefinition(MethodIdentifier( InterfaceIdentifier(fake_iface_id), echo_method_id), StructDefinition('struct', [('int', IntegerDefinition()), ('str', StringDefinition())] ), StructDefinition('struct', [('int', IntegerDefinition()), ('str', StringDefinition())] ),
from vmware.vapi.security.oauth import OAUTH_SCHEME_ID, ACCESS_TOKEN from vmware.vapi.security.session import SESSION_SCHEME_ID, SESSION_ID from vmware.vapi.security.sso import SAML_SCHEME_ID, SAML_BEARER_SCHEME_ID, SAML_TOKEN, PRIVATE_KEY from vmware.vapi.security.user_identity import UserIdentity from vmware.vapi.lib.constants import SCHEME_ID from vmware.vapi.settings.config import ProviderConfig from vmware.vapi.provider.local import LocalProvider DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') mock_interface_id = InterfaceIdentifier('mock') mock_method_id = MethodIdentifier(mock_interface_id, 'mock') mock_interface_def = InterfaceDefinition(mock_interface_id, [mock_method_id]) mock_method_def = MethodDefinition( mock_method_id, StructDefinition('input', [('input', VoidDefinition())]), IntegerDefinition(), []) errors = [ 'com.vmware.vapi.std.errors.internal_server_error', 'com.vmware.vapi.std.errors.invalid_argument', 'com.vmware.vapi.std.errors.operation_not_found', 'com.vmware.vapi.std.errors.unauthenticated', ] error_defs = [make_std_error_def(error) for error in errors] error_values = ListValue( [convert_data_def_to_data_value(error_def) for error_def in error_defs]) logging.basicConfig(level=logging.INFO) class MockupApiInterface(ApiInterface):
def test_void_type(self): void_type = VoidType() self.assertNotEqual(void_type, None) self.assertEqual(void_type.definition, VoidDefinition())