def test_SynthesizeCommandTypes(self): json_api = { 'domains': [ { 'domain': 'domain', 'commands': [ { 'name': 'TestCommand', 'parameters': [ {'name': 'p1', 'type': 'number'}, {'name': 'p2', 'type': 'integer'}, {'name': 'p3', 'type': 'boolean'}, {'name': 'p4', 'type': 'string'}, {'name': 'p5', 'type': 'any'}, {'name': 'p6', 'type': 'object', '$ref': 'TestType'}, ], 'returns': [ {'name': 'r1', 'type': 'number'}, {'name': 'r2', 'type': 'integer'}, {'name': 'r3', 'type': 'boolean'}, {'name': 'r4', 'type': 'string'}, {'name': 'r5', 'type': 'any'}, {'name': 'r6', 'type': 'object', '$ref': 'TestType'}, ], }, ] }, ] } expected_types = [ { 'type': 'object', 'id': 'TestCommandParams', 'description': 'Parameters for the TestCommand command.', 'properties': [ {'type': 'number', 'name': 'p1'}, {'type': 'integer', 'name': 'p2'}, {'type': 'boolean', 'name': 'p3'}, {'type': 'string', 'name': 'p4'}, {'type': 'any', 'name': 'p5'}, {'type': 'object', 'name': 'p6', '$ref': 'TestType'} ], }, { 'type': 'object', 'id': 'TestCommandResult', 'description': 'Result for the TestCommand command.', 'properties': [ {'type': 'number', 'name': 'r1'}, {'type': 'integer', 'name': 'r2'}, {'type': 'boolean', 'name': 'r3'}, {'type': 'string', 'name': 'r4'}, {'type': 'any', 'name': 'r5'}, {'type': 'object', 'name': 'r6', '$ref': 'TestType'} ], } ] client_api_generator.SynthesizeCommandTypes(json_api) types = json_api['domains'][0]['types'] self.assertListEqual(types, expected_types)
def test_EnsureCommandsHaveParametersAndReturnTypes(self): json_api = { 'domains': [{ 'domain': 'domain', 'commands': [{ 'name': 'FooCommand', }], 'events': [{ 'name': 'BarEvent', }] }] } expected_types = [{ 'type': 'object', 'id': 'FooCommandParams', 'description': 'Parameters for the FooCommand command.', 'properties': [], }, { 'type': 'object', 'id': 'FooCommandResult', 'description': 'Result for the FooCommand command.', 'properties': [], }, { 'type': 'object', 'id': 'BarEventParams', 'description': 'Parameters for the BarEvent event.', 'properties': [], }] client_api_generator.EnsureCommandsHaveParametersAndReturnTypes( json_api) client_api_generator.SynthesizeCommandTypes(json_api) client_api_generator.SynthesizeEventTypes(json_api) types = json_api['domains'][0]['types'] self.assertListEqual(types, expected_types)
def test_PatchHiddenCommandsAndEvents(self): json_api = { 'domains': [{ 'domain': 'domain', 'commands': [{ 'name': 'FooCommand', 'hidden': True, }], 'events': [{ 'name': 'BarEvent', 'hidden': True, }] }] } expected_types = [{ 'type': 'object', 'id': 'FooCommandParams', 'description': 'Parameters for the FooCommand command.', 'properties': [], }, { 'type': 'object', 'id': 'FooCommandResult', 'description': 'Result for the FooCommand command.', 'properties': [], }, { 'type': 'object', 'id': 'BarEventParams', 'description': 'Parameters for the BarEvent event.', 'properties': [], }] client_api_generator.PatchHiddenCommandsAndEvents(json_api) client_api_generator.SynthesizeCommandTypes(json_api) client_api_generator.SynthesizeEventTypes(json_api) for command in json_api['domains'][0]['commands']: self.assertTrue(command['hidden']) for event in json_api['domains'][0]['events']: self.assertTrue(command['hidden']) types = json_api['domains'][0]['types'] self.assertListEqual(types, expected_types)