def _extract_param_type(self, attrib, prefix, name): type_name = self._extract_attrib(attrib, "type") if type_name is None: raise ParseError( "Type is not specified for parameter '{}'".format(name)) if type_name == "Boolean": default_value = self._extract_attrib(attrib, "defvalue") if default_value is not None: default_value = self._get_bool_from_string(default_value) param_type = Boolean(default_value=default_value) elif type_name in ('Integer', 'Float', 'Double'): min_value = self._extract_optional_number_attrib( attrib, "minvalue", int if type_name == "Integer" else float) max_value = self._extract_optional_number_attrib( attrib, "maxvalue", int if type_name == "Integer" else float) default_value = self._extract_optional_number_attrib( attrib, "defvalue", int if type_name == "Integer" else float) param_type = (Integer if type_name == "Integer" else Float)( min_value=min_value, max_value=max_value, default_value=default_value) elif type_name == "String": min_length = self._extract_optional_number_attrib( attrib, "minlength") # if minlength is not defined default value is 1 if min_length is None: min_length = 1 max_length = self._extract_optional_number_attrib( attrib, "maxlength") default_value = self._extract_attrib(attrib, "defvalue") param_type = String(min_length=min_length, max_length=max_length, default_value=default_value) else: if type_name.count('.') == 1: custom_type_name = type_name.replace(".", "_") else: custom_type_name = prefix + type_name if custom_type_name in self._types: param_type = self._types[custom_type_name] default_value = self._extract_attrib(attrib, "defvalue") if default_value is not None: if default_value not in param_type.elements: raise ParseError( "Default value '{}' for parameter '{}' is not a member of {}" .format(default_value, name, type(param_type.__name__))) default_value = param_type.elements[default_value] else: raise ParseError("Unknown type '{}'".format(type_name)) if self._extract_optional_bool_attrib(attrib, "array", False): min_size = self._extract_optional_number_attrib(attrib, "minsize") max_size = self._extract_optional_number_attrib(attrib, "maxsize") param_type = Array(element_type=param_type, min_size=min_size, max_size=max_size) return param_type, default_value
def test_CreateInteractionChoiceSet(self): """ generator/transformers/common_producer.py 67% generator/transformers/functions_producer.py 63% """ params = OrderedDict() params['choiceSet'] = Param( name='choiceSet', param_type=Array(element_type=Struct(name='Choice'))) item = Function( name='CreateInteractionChoiceSet', function_id=EnumElement(name='CreateInteractionChoiceSetID'), message_type=EnumElement(name='request'), params=params) expected = OrderedDict() expected['origin'] = 'CreateInteractionChoiceSet' expected['name'] = 'SDLCreateInteractionChoiceSet' expected['extends_class'] = 'SDLRPCRequest' expected['imports'] = { '.m': {'SDLChoice'}, '.h': { 'struct': {'SDLChoice'}, 'enum': {'SDLRPCRequest'} } } expected['params'] = (self.producer.param_named( constructor_argument='choiceSet', constructor_argument_override=None, constructor_prefix='ChoiceSet', deprecated=False, description=[], for_name='objects', mandatory=True, method_suffix='ChoiceSet', modifier='strong', of_class='SDLChoice.class', origin='choiceSet', since=None, type_native='NSArray<SDLChoice *> *', type_sdl='NSArray<SDLChoice *> *'), ) argument = [ self.producer.argument_named(variable='choiceSet', deprecated=False, constructor_argument='choiceSet', origin='choiceSet') ] expected['constructors'] = (self.producer.constructor_named( all=argument, arguments=argument, deprecated=False, self=True, init='ChoiceSet:(NSArray<SDLChoice *> *)choiceSet'), ) actual = self.producer.transform(item) self.assertDictEqual(expected, actual)
def test_RegisterAppInterface(self): params = OrderedDict() params['syncMsgVersion'] = Param( name='syncMsgVersion', param_type=Struct(name='SyncMsgVersion')) params['ttsName'] = Param( name='ttsName', param_type=Array(element_type=Struct(name='TTSChunk'))) item = Function(name='RegisterAppInterface', function_id=None, message_type=EnumElement(name='request'), params=params) expected = self.expected_template.copy() expected['kind'] = 'request' expected['function_id'] = 'REGISTER_APP_INTERFACE' expected['class_name'] = 'RegisterAppInterface' expected['extends_class'] = 'RPCRequest' expected['history'] = None expected['imports'] = [ 'androidx.annotation.NonNull', '', 'com.smartdevicelink.protocol.enums.FunctionID', 'com.smartdevicelink.proxy.RPCRequest', '', 'java.util.Hashtable', 'java.util.List' ] expected['params'] = (self.producer.params(deprecated=None, key='KEY_SDL_MSG_VERSION', last='sdlMsgVersion', mandatory=True, SuppressWarnings=None, origin='syncMsgVersion', return_type='SdlMsgVersion', since=None, title='SdlMsgVersion', description=None, param_doc=None, name=None), self.producer.params( SuppressWarnings='unchecked', deprecated=None, key='KEY_TTS_NAME', last='ttsName', mandatory=True, origin='ttsName', description=None, return_type='List<TTSChunk>', since=None, title='TtsName', param_doc=None, name=None)) actual = self.producer.transform(item) self.comparison(expected, actual)
def test_CreateInteractionChoiceSetRequest(self): params = OrderedDict() params['choiceSet'] = Param( name='choiceSet', param_type=Array(element_type=Struct( name='Choice', description=['A choice is an option given to ' ]))) item = Function(name='CreateInteractionChoiceSet', function_id=Enum(name='CreateInteractionChoiceSetID'), description=['creates interaction'], message_type=EnumElement(name='request'), params=params) expected = OrderedDict() expected['file_name'] = 'CreateInteractionChoiceSet' expected['name'] = 'CreateInteractionChoiceSet' expected['imports'] = { self.producer.imports(what='Choice', wherefrom='../structs/Choice.js'), self.producer.imports(what='RpcRequest', wherefrom='../RpcRequest.js'), self.producer.imports(what='FunctionID', wherefrom='../enums/FunctionID.js') } expected['methods'] = (self.producer.methods( key='KEY_CHOICE_SET', method_title='ChoiceSet', external='Choice', description=['A choice is an option given to'], param_name='set', type='Choice[]', param_values={}, since=None, history=None, deprecated=None), ) expected['params'] = (self.producer.params(key='KEY_CHOICE_SET', value="'choiceSet'"), ) expected['description'] = ['creates interaction'] expected['since'] = None expected['history'] = None expected['deprecated'] = None expected['func'] = 'CreateInteractionChoiceSet' expected['extend'] = 'RpcRequest' result = self.producer.transform(item) self.assertDictEqual(expected, result)
def test_CloudAppProperties(self): item = Struct(name='CloudAppProperties', members={ 'nicknames': Param(name='nicknames', param_type=Array(element_type=String(max_length=100, min_length=0), max_size=100, min_size=0)), }) expected = { 'class_name': 'CloudAppProperties', 'extends_class': 'RPCStruct', 'package_name': 'com.smartdevicelink.proxy.rpc', 'imports': ['android.support.annotation.NonNull', '', 'com.smartdevicelink.proxy.RPCStruct', '', 'java.util.Hashtable', 'java.util.List'], 'deprecated': None, 'since': None, 'params': (self.producer.params(deprecated=None, key='KEY_NICKNAMES', last='nicknames', mandatory=True, origin='nicknames', return_type='List<String>', name=None, since=None, title='Nicknames', description=None, param_doc=None),), } actual = self.producer.transform(item) self.comparison(expected, actual)
def test_full_generation(self): """Test full generation using SDLPRC SmartSchema generator. Creates output files which is captured by the mock and compare them with sample files with correct code. This test requires valid test_expected_sdlrpc.h and test_expected_sdlrpc.cc in the same as this module. """ self.maxDiff = None expected_h_file_content = Path(__file__).parents[0].joinpath('test_expected_sdlrpc.h').read_text() expected_cc_file_content = Path(__file__).parents[0].joinpath('test_expected_sdlrpc.cc').read_text() generator = SmartFactorySDLRPC.CodeGenerator() message_type_elements = collections.OrderedDict() message_type_elements[u"request"] = EnumElement(name=u"request") message_type_elements[u"response"] = EnumElement( name=u"response") message_type_elements[u"notification"] = EnumElement( name=u"notification") message_type = Enum(name=u"messageType", elements=message_type_elements) elements1 = collections.OrderedDict() elements1[u"name1"] = EnumElement( name=u"name1", design_description=DESIGN_DESCRIPTION, todos=TODOS, value=u"1") elements1[u"name2"] = EnumElement( name="name2", description=DESCRIPTION, issues=ISSUES, internal_name=u"internal_name2") enum1 = Enum(name=u"Enum1", todos=TODOS, elements=elements1) elements2 = collections.OrderedDict() elements2[u"xxx"] = EnumElement(name=u"xxx", internal_name=u"val_1") elements2[u"yyy"] = EnumElement(name=u"yyy", internal_name=u"val_2", value=u"100") elements2[u"zzz"] = EnumElement(name=u"val_3") enum2 = Enum(name=u"E2", elements=elements2) elements3 = collections.OrderedDict() elements3["1"] = EnumElement(name="xxx", internal_name="_1") elements3["2"] = EnumElement(name="xxx", internal_name="_2") elements3["3"] = EnumElement(name="xxx", internal_name="_3") enum3 = Enum(name="Enum_new2", elements=elements3) elements4 = collections.OrderedDict() elements4["name1"] = EnumElement(name="xxx", internal_name="_11") elements4["name2"] = EnumElement(name="xxx", internal_name="_22") enum4 = Enum(name="Enum_new4", elements=elements4) enums = collections.OrderedDict() enums["Enum1"] = enum1 enums["Enum2"] = enum2 enums["Enum3"] = enum3 enums["Enum4"] = enum4 enums["messageType"] = message_type params1 = collections.OrderedDict() params1["1"] = Param( name="param1", design_description=DESIGN_DESCRIPTION, description=DESCRIPTION, issues=ISSUES, todos=TODOS, param_type=enum4, default_value=elements4["name1"]) params1["2"] = Param( name="param2", param_type=EnumSubset( name="sub1", enum=enum1, allowed_elements={"e1": elements1["name1"]}), default_value=elements1["name1"]) functions = collections.OrderedDict() functions["Function1"] = Function( name="Function1", function_id=elements1["name1"], message_type=message_type_elements["request"], params=params1) functions["Function2"] = Function( name="Function2", function_id=elements2["xxx"], message_type=message_type_elements["response"]) functions["Function3"] = Function( name="Function2", function_id=elements2["yyy"], message_type=message_type_elements["notification"]) members1 = collections.OrderedDict() members1["m1"] = Param(name="intParam", param_type=Integer(max_value=2)) members1["m11"] = Param(name="doubleParam", param_type=Float(min_value=0.333), is_mandatory=False) members1["m222"] = Param(name="boolParam", param_type=Boolean()) members1["m2"] = Param(name="structParam", param_type=Struct(name="Struct2")) members1["aaa"] = Param(name="enumParam", param_type=enum1) members1["bbb"] = Param(name="enumParam1", param_type=enum1) members1["xxx"] = Param( name="enumSubset1", param_type=EnumSubset( name="sub", enum=enum1, allowed_elements={"e1": elements1["name1"]}), is_mandatory=False) members1["1"] = Param( name="arrayOfInt", param_type=Array(min_size=0, max_size=20, element_type=Boolean()), is_mandatory=False) members1["2"] = Param( name="arrayOfEnum1", param_type=Array(min_size=0, max_size=20, element_type=enum1), is_mandatory=False) members1["3"] = Param( name="arrayOfEnum3", param_type=Array(min_size=10, max_size=40, element_type=enum3), is_mandatory=True) members1["4"] = Param( name="arrayOfEnum4", param_type=Array( min_size=10, max_size=41, element_type=EnumSubset( name="sub1", enum=enum1, allowed_elements={"e1": elements1["name1"]}))) members1["5"] = Param( name="arrayOfEnum5", param_type=Array( min_size=10, max_size=42, element_type=EnumSubset( name="sub2", enum=enum1, allowed_elements={"e1": elements1["name2"]}))) members1["6"] = Param( name="arrayOfEnum6", param_type=Array( min_size=10, max_size=43, element_type=EnumSubset( name="sub3", enum=enum4, allowed_elements={"e1": elements4["name2"]}))) structs = collections.OrderedDict() structs["Struct1"] = Struct( name="Struct1", design_description=DESIGN_DESCRIPTION, issues=ISSUES, members=members1) structs["Struct2"] = Struct(name="Struct2", issues=ISSUES) interface = Interface(enums=enums, structs=structs, functions=functions, params={"param1": "value1", "param2": "value2"}) os.path.exists = MagicMock(return_value=True) uuid.uuid1 = MagicMock( return_value=uuid.UUID("12345678123456781234567812345678")) codecs.open = MagicMock() generator.generate(interface=interface, filename="Test.xml", namespace="XXX::YYY::ZZZ", destination_dir="/some/test/dir") os.path.exists.assert_has_calls([call('/some/test/dir')]) open_result = codecs.open mock_calls = open_result.mock_calls self.assertEqual(mock_calls[0], call('/some/test/dir/Test.h', mode='w', encoding='utf-8'), "Invalid header file creation") self.assertEqual(mock_calls[4], call('/some/test/dir/Test_schema.h', mode='w', encoding='utf-8'), "Invalid source file creation") try: self.assertSequenceEqual(str(mock_calls[2])[27:-2].replace("\\n", "\n"), expected_h_file_content, "Invalid header file content") self.assertSequenceEqual(str(mock_calls[6])[27:-2].replace("\\n", "\n"), expected_cc_file_content, "Invalid source file content") except AssertionError as message: print(message)
def test_RegisterAppInterfaceResponse(self): """ generator/transformers/common_producer.py 82% generator/transformers/functions_producer.py 63% """ params = OrderedDict() params['success'] = Param(name='success', param_type=Boolean(), description=[' True if '], is_mandatory=False) params['language'] = Param( name='language', is_mandatory=False, param_type=Enum(name='Language', elements={ 'EN-US': EnumElement(name='EN-US', description=['English - US']) }), description=['The currently']) params['supportedDiagModes'] = Param( name='supportedDiagModes', is_mandatory=False, description=['\n Specifies the'], param_type=Array(element_type=Integer(max_value=255, min_value=0), max_size=100, min_size=1)) params['hmiZoneCapabilities'] = Param( name='hmiZoneCapabilities', is_mandatory=False, param_type=Array(element_type=Enum(name='HmiZoneCapabilities'), max_size=100, min_size=1)) item = Function(name='RegisterAppInterface', function_id=EnumElement(name='RegisterAppInterfaceID'), description=['The response '], message_type=EnumElement(name='response'), params=params) expected = OrderedDict() expected['origin'] = 'RegisterAppInterface' expected['name'] = 'SDLRegisterAppInterfaceResponse' expected['extends_class'] = 'SDLRPCResponse' expected['imports'] = { '.h': { 'enum': {'SDLRPCResponse', 'SDLLanguage'}, 'struct': set() }, '.m': {'SDLLanguage'} } expected['description'] = ['The response'] expected['params'] = ( self.producer.param_named(constructor_argument='language', constructor_argument_override=None, constructor_prefix='Language', deprecated=False, description=['The currently'], for_name='enum', mandatory=False, method_suffix='Language', modifier='strong', of_class='', origin='language', since=None, type_native='SDLLanguage ', type_sdl='SDLLanguage '), self.producer.param_named( constructor_argument='supportedDiagModes', constructor_argument_override=None, constructor_prefix='SupportedDiagModes', deprecated=False, description=['Specifies the'], for_name='objects', mandatory=False, method_suffix='SupportedDiagModes', modifier='strong', of_class='NSNumber.class', origin='supportedDiagModes', since=None, type_native='NSArray<NSNumber<SDLUInt> *> *', type_sdl='NSArray<NSNumber<SDLUInt> *> *'), self.producer.param_named( constructor_argument='hmiZoneCapabilities', constructor_argument_override=None, constructor_prefix='HmiZoneCapabilities', deprecated=False, description=[], for_name='enums', mandatory=False, method_suffix='HmiZoneCapabilities', modifier='strong', of_class='', origin='hmiZoneCapabilities', since=None, type_native='NSArray<SDLHmiZoneCapabilities> *', type_sdl='NSArray<SDLHmiZoneCapabilities> *')) arguments = [ self.producer.argument_named(variable='language', deprecated=False, origin='language', constructor_argument='language'), self.producer.argument_named( variable='supportedDiagModes', deprecated=False, origin='supportedDiagModes', constructor_argument='supportedDiagModes'), self.producer.argument_named( variable='hmiZoneCapabilities', deprecated=False, origin='hmiZoneCapabilities', constructor_argument='hmiZoneCapabilities') ] expected['constructors'] = (self.producer.constructor_named( all=arguments, arguments=arguments, deprecated=False, init= 'Language:(nullable SDLLanguage)language supportedDiagModes:(nullable NSArray<NSNumber<SDLUInt> *>' ' *)supportedDiagModes hmiZoneCapabilities:(nullable NSArray<SDLHmiZoneCapabilities> *)' 'hmiZoneCapabilities', self=''), ) actual = self.producer.transform(item) self.assertDictEqual(expected, actual)
def test_RegisterAppInterfaceRequest(self): """ generator/transformers/common_producer.py 85% generator/transformers/functions_producer.py 63% """ params = OrderedDict() params['syncMsgVersion'] = Param(name='syncMsgVersion', param_type=Struct( name='SyncMsgVersion', description=['Specifies the'], members={ 'majorVersion': Param(name='majorVersion', param_type=Integer()) }), description=['See SyncMsgVersion'], is_mandatory=True) params['fullAppID'] = Param(name='fullAppID', description=['ID used'], param_type=String(), is_mandatory=False) params['dayColorScheme'] = Param( name='dayColorScheme', param_type=Struct( name='TemplateColorScheme', description=[ '\n A color scheme for all display layout templates.\n ' ]), is_mandatory=False) params['ttsName'] = Param( name='ttsName', description=['\n TTS string for'], is_mandatory=False, param_type=Array(element_type=Struct(name='TTSChunk', description=['A TTS chunk']))) params['isMediaApplication'] = Param( name='isMediaApplication', param_type=Boolean(), description=[ '\n Indicates if the application is a media or a ' ], is_mandatory=True) item = Function( name='RegisterAppInterface', function_id=EnumElement(name='RegisterAppInterfaceID'), since='1.0.0', description=[ '\n Establishes an interface with a mobile application.\n ' 'Before registerAppInterface no other commands will be accepted/executed.\n ' ], message_type=EnumElement(name='request'), params=params) expected = OrderedDict() expected['origin'] = 'RegisterAppInterface' expected['name'] = 'SDLRegisterAppInterface' expected['extends_class'] = 'SDLRPCRequest' expected['imports'] = { '.h': { 'enum': {'SDLRPCRequest'}, 'struct': {'SDLTemplateColorScheme', 'SDLTTSChunk', 'SDLSdlMsgVersion'} }, '.m': {'SDLTemplateColorScheme', 'SDLTTSChunk', 'SDLSdlMsgVersion'} } expected['description'] = [ 'Establishes an interface with a mobile application. Before registerAppInterface no ' 'other commands will be', 'accepted/executed.' ] expected['since'] = '1.0.0' expected['params'] = ( self.producer.param_named(constructor_argument='sdlMsgVersion', constructor_argument_override=None, constructor_prefix='SdlMsgVersion', deprecated=False, description=['See SyncMsgVersion'], for_name='object', mandatory=True, method_suffix='SdlMsgVersion', modifier='strong', of_class='SDLSdlMsgVersion.class', origin='sdlMsgVersion', since=None, type_native='SDLSdlMsgVersion *', type_sdl='SDLSdlMsgVersion *'), self.producer.param_named( constructor_argument='fullAppID', constructor_argument_override=None, constructor_prefix='FullAppID', deprecated=False, description=[ 'ID used', '{"default_value": null, "max_length": null, "min_length": null}' ], for_name='object', mandatory=False, method_suffix='FullAppID', modifier='strong', of_class='NSString.class', origin='fullAppID', since=None, type_native='NSString *', type_sdl='NSString *'), self.producer.param_named(constructor_argument='dayColorScheme', constructor_argument_override=None, mandatory=False, constructor_prefix='DayColorScheme', deprecated=False, description=[], for_name='object', method_suffix='DayColorScheme', modifier='strong', of_class='SDLTemplateColorScheme.class', origin='dayColorScheme', since=None, type_native='SDLTemplateColorScheme *', type_sdl='SDLTemplateColorScheme *'), self.producer.param_named(constructor_argument='ttsName', constructor_argument_override=None, constructor_prefix='TtsName', deprecated=False, description=['TTS string for'], for_name='objects', mandatory=False, method_suffix='TtsName', modifier='strong', of_class='SDLTTSChunk.class', origin='ttsName', since=None, type_native='NSArray<SDLTTSChunk *> *', type_sdl='NSArray<SDLTTSChunk *> *'), self.producer.param_named( constructor_argument='isMediaApplication', constructor_argument_override=None, constructor_prefix='IsMediaApplication', deprecated=False, description=['Indicates if the application is a media or a'], for_name='object', mandatory=True, method_suffix='IsMediaApplication', modifier='strong', of_class='NSNumber.class', origin='isMediaApplication', since=None, type_native='BOOL', type_sdl='NSNumber<SDLBool> *')) mandatory_arguments = [ self.producer.argument_named(variable='sdlMsgVersion', deprecated=False, origin='sdlMsgVersion', constructor_argument='sdlMsgVersion'), self.producer.argument_named( variable='isMediaApplication', deprecated=False, origin='isMediaApplication', constructor_argument='@(isMediaApplication)') ] not_mandatory_arguments = [ self.producer.argument_named(variable='fullAppID', deprecated=False, origin='fullAppID', constructor_argument='fullAppID'), self.producer.argument_named( variable='dayColorScheme', deprecated=False, origin='dayColorScheme', constructor_argument='dayColorScheme'), self.producer.argument_named(variable='ttsName', deprecated=False, origin='ttsName', constructor_argument='ttsName') ] mandatory_init = 'SdlMsgVersion:(SDLSdlMsgVersion *)sdlMsgVersion ' \ 'isMediaApplication:(BOOL)isMediaApplication' expected['constructors'] = ( self.producer.constructor_named(all=mandatory_arguments, arguments=mandatory_arguments, deprecated=False, init=mandatory_init, self=True), self.producer.constructor_named( all=mandatory_arguments + not_mandatory_arguments, arguments=not_mandatory_arguments, deprecated=False, init=mandatory_init + ' fullAppID:(nullable NSString *)fullAppID dayColorScheme:(nullable ' 'SDLTemplateColorScheme *)dayColorScheme ttsName:(nullable NSArray<SDLTTSChunk ' '*> *)ttsName', self=re.sub(r'([\w\d]+:)\([\w\d\s<>*]*\)([\w\d]+\s*)', r'\1\2', mandatory_init))) actual = self.producer.transform(item) self.assertDictEqual(expected, actual)
def test_RegisterAppInterfaceRequest(self): params = OrderedDict() params['syncMsgVersion'] = Param(name='syncMsgVersion', param_type=Struct( name='SyncMsgVersion', description=['Specifies the'], members={ 'majorVersion': Param(name='majorVersion', param_type=Integer()) }), description=['See SyncMsgVersion']) params['fullAppID'] = Param(name='fullAppID', description=['ID used'], param_type=String()) params['dayColorScheme'] = Param( name='dayColorScheme', param_type=Struct( name='TemplateColorScheme', description=[ '\n A color scheme for all display layout templates.\n ' ])) params['ttsName'] = Param( name='ttsName', description=['\n TTS string for'], param_type=Array(element_type=Struct(name='TTSChunk', description=['A TTS chunk']))) item = Function(name='RegisterAppInterface', function_id=Enum(name='RegisterAppInterfaceID'), message_type=EnumElement(name='request'), params=params) expected = OrderedDict() expected['file_name'] = 'RegisterAppInterface' expected['name'] = 'RegisterAppInterface' expected['imports'] = { self.producer.imports(what='SdlMsgVersion', wherefrom='../structs/SdlMsgVersion.js'), self.producer.imports( what='TemplateColorScheme', wherefrom='../structs/TemplateColorScheme.js'), self.producer.imports(what='TTSChunk', wherefrom='../structs/TTSChunk.js'), self.producer.imports(what='RpcRequest', wherefrom='../RpcRequest.js'), self.producer.imports(what='FunctionID', wherefrom='../enums/FunctionID.js') } expected['methods'] = ( self.producer.methods(key='KEY_SDL_MSG_VERSION', method_title='SdlMsgVersion', external='SdlMsgVersion', description=['See SyncMsgVersion'], param_name='version', type='SdlMsgVersion', param_values={}, since=None, history=None, deprecated=None), self.producer.methods(key='KEY_FULL_APP_ID', method_title='FullAppID', external=None, description=['ID used'], param_name='id', type='String', param_values={}, since=None, history=None, deprecated=None), self.producer.methods( key='KEY_DAY_COLOR_SCHEME', param_name='scheme', method_title='DayColorScheme', external='TemplateColorScheme', description=[ 'A color scheme for all display layout templates.' ], type='TemplateColorScheme', param_values={}, since=None, history=None, deprecated=None), self.producer.methods(key='KEY_TTS_NAME', param_name='name', method_title='TtsName', external='TTSChunk', description=['TTS string for'], type='TTSChunk[]', param_values={}, since=None, history=None, deprecated=None)) expected['params'] = (self.producer.params(key='KEY_SDL_MSG_VERSION', value="'syncMsgVersion'"), self.producer.params(key='KEY_FULL_APP_ID', value="'fullAppID'"), self.producer.params(key='KEY_DAY_COLOR_SCHEME', value="'dayColorScheme'"), self.producer.params(key='KEY_TTS_NAME', value="'ttsName'"), self.producer.params(key='APP_ID_MAX_LENGTH', value=10)) expected['since'] = None expected['history'] = None expected['deprecated'] = None expected['func'] = 'RegisterAppInterface' expected['extend'] = 'RpcRequest' result = self.producer.transform(item) self.assertDictEqual(expected, result)
def test_RegisterAppInterfaceResponse(self): params = OrderedDict() params['success'] = Param(name='success', param_type=Boolean(), description=[' true if ']) params['language'] = Param( name='language', param_type=Enum(name='Language', elements={ 'EN-US': EnumElement(name='EN-US', description=['English - US']) }), description=['The currently']) params['supportedDiagModes'] = Param( name='supportedDiagModes', param_type=Array(element_type=Integer()), description=['\n Specifies the']) item = Function(name='RegisterAppInterface', function_id=Enum(name='RegisterAppInterfaceID'), description=['The response '], message_type=EnumElement(name='response'), params=params) expected = OrderedDict() expected['file_name'] = 'RegisterAppInterfaceResponse' expected['name'] = 'RegisterAppInterfaceResponse' expected['imports'] = { self.producer.imports(what='Language', wherefrom='../enums/Language.js'), self.producer.imports(what='RpcResponse', wherefrom='../RpcResponse.js'), self.producer.imports(what='FunctionID', wherefrom='../enums/FunctionID.js') } expected['methods'] = (self.producer.methods( key='KEY_LANGUAGE', method_title='Language', external='Language', description=['The currently'], param_name='language', type='Language', param_values={}, since=None, history=None, deprecated=None), self.producer.methods( key='KEY_SUPPORTED_DIAG_MODES', method_title='SupportedDiagModes', external=None, description=['Specifies the'], param_name='modes', type='Number[]', param_values={}, since=None, history=None, deprecated=None)) expected['params'] = (self.producer.params(key='KEY_LANGUAGE', value="'language'"), self.producer.params( key='KEY_SUPPORTED_DIAG_MODES', value="'supportedDiagModes'")) expected['description'] = ['The response'] expected['since'] = None expected['history'] = None expected['deprecated'] = None expected['func'] = 'RegisterAppInterface' expected['extend'] = 'RpcResponse' result = self.producer.transform(item) self.assertDictEqual(expected, result)