Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | import os |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 19 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 20 | import yaml |
| 21 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 22 | PROTO_EXPECTED_OUTPUT = """ |
| 23 | message VRouterPort { |
| 24 | option bases = "XOSBase"; |
| 25 | optional string name = 1 [ null = "True", max_length = "20", blank = "True", help_text = ""port friendly name"", modifier = "optional", db_index = "False" ]; |
| 26 | required string openflow_id = 2 [ null = "False", max_length = "21", blank = "False", help_text = ""port identifier in ONOS"", modifier = "required", db_index = "False" ]; |
| 27 | required int32 vrouter_device = 3 [ null = "False", blank = "False", model = "VRouterDevice", modifier = "required", type = "link", port = "ports", link_type = "manytoone", db_index = "True" ]; |
| 28 | required int32 vrouter_service = 4 [ null = "False", blank = "False", model = "VRouterService", modifier = "required", type = "link", port = "device_ports", link_type = "manytoone", db_index = "True" ]; |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 29 | } |
| 30 | """ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 31 | VROUTER_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/vrouterport.xproto") |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 32 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 33 | # Generate other formats from xproto |
| 34 | class XProtoTranslatorTest(unittest.TestCase): |
| 35 | def _test_proto_generator(self): |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 36 | args = XOSProcessorArgs() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 37 | args.files = [VROUTER_XPROTO] |
| 38 | args.target = 'proto.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 39 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 40 | self.assertEqual(output, PROTO_EXPECTED_OUTPUT) |
| 41 | |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 42 | def test_yaml_generator(self): |
| 43 | xproto = \ |
| 44 | """ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 45 | option app_label = "test"; |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 46 | |
| 47 | message Port (PlCoreBase,ParameterMixin){ |
| 48 | required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False]; |
| 49 | optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True]; |
| 50 | optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False]; |
| 51 | optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True]; |
| 52 | optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True]; |
| 53 | required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True]; |
| 54 | } |
| 55 | |
| 56 | message Instance (PlCoreBase){ |
| 57 | optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False]; |
| 58 | optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False]; |
| 59 | required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False]; |
| 60 | optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False]; |
| 61 | optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False]; |
| 62 | required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False]; |
| 63 | optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True]; |
| 64 | required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False]; |
| 65 | required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False]; |
| 66 | required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False]; |
| 67 | required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False]; |
| 68 | required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False]; |
| 69 | optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True]; |
| 70 | required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False]; |
| 71 | optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True]; |
| 72 | optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True]; |
| 73 | required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True]; |
| 74 | } |
| 75 | |
| 76 | message Network (PlCoreBase,ParameterMixin) { |
| 77 | required string name = 1 [db_index = False, max_length = 32, null = False, blank = False]; |
| 78 | required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False]; |
| 79 | required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True]; |
| 80 | required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True]; |
| 81 | required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True]; |
| 82 | optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True]; |
| 83 | optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True]; |
| 84 | required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False]; |
| 85 | required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False]; |
| 86 | required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True]; |
| 87 | optional string topology_parameters = 11 [db_index = False, null = True, blank = True]; |
| 88 | optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True]; |
| 89 | optional string controller_parameters = 13 [db_index = False, null = True, blank = True]; |
| 90 | optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True]; |
| 91 | optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True]; |
| 92 | optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True]; |
| 93 | required bool autoconnect = 17 [help_text = "This network can be autoconnected to the slice that owns it", default = True, null = False, db_index = False, blank = True]; |
| 94 | required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True]; |
| 95 | required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True]; |
| 96 | required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True]; |
| 97 | } |
| 98 | |
| 99 | message Slice (PlCoreBase){ |
| 100 | required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False]; |
| 101 | required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True]; |
| 102 | required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True]; |
| 103 | required string description = 4 [help_text = "High level description of the slice and expected activities", max_length = 1024, null = False, db_index = False, blank = True]; |
| 104 | required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True]; |
| 105 | required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False]; |
| 106 | required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False]; |
| 107 | optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True]; |
| 108 | optional string network = 9 [blank = True, max_length = 256, null = True, db_index = False, choices = "((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks'))"]; |
| 109 | optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True]; |
| 110 | optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True]; |
| 111 | optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True]; |
| 112 | optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True]; |
| 113 | optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True]; |
| 114 | optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True]; |
| 115 | optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False]; |
| 116 | required string default_isolation = 17 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False]; |
| 117 | required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True]; |
| 118 | } |
| 119 | """ |
| 120 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 121 | args = XOSProcessorArgs() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 122 | args.inputs = xproto |
| 123 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 124 | output = XOSProcessor.process(args) |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 125 | |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 126 | yaml_ir = yaml.load(output) |
| 127 | self.assertEqual(len(yaml_ir['items']), 4) |
| 128 | |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 129 | def test_gui_hidden_models(self): |
| 130 | xproto = \ |
| 131 | """ |
| 132 | option app_label = "test"; |
| 133 | |
| 134 | message Foo { |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 135 | option gui_hidden = True; |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 136 | required string name = 1 [ null = "False", blank="False"]; |
| 137 | } |
| 138 | |
| 139 | message Bar { |
| 140 | option gui_hidden = "False"; |
| 141 | required string name = 1 [ null = "False", blank="False"]; |
| 142 | } |
| 143 | """ |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 144 | args = XOSProcessorArgs() |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 145 | args.inputs = xproto |
| 146 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 147 | output = XOSProcessor.process(args) |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 148 | yaml_ir = yaml.load(output) |
| 149 | self.assertEqual(len(yaml_ir['items']), 1) |
| 150 | self.assertIn('Bar', output) |
| 151 | self.assertNotIn('Foo', output) |
| 152 | |
| 153 | def test_gui_hidden_model_fields(self): |
| 154 | xproto = \ |
| 155 | """ |
| 156 | option app_label = "test"; |
| 157 | |
| 158 | message Foo { |
| 159 | required string name = 1 [ null = "False", blank="False"]; |
| 160 | required string secret = 1 [ null = "False", blank="False", gui_hidden = "True"]; |
| 161 | } |
| 162 | """ |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 163 | args = XOSProcessorArgs() |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 164 | args.inputs = xproto |
| 165 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 166 | output = XOSProcessor.process(args) |
Matteo Scandolo | 5341859 | 2017-07-26 15:51:29 -0700 | [diff] [blame] | 167 | yaml_ir = yaml.load(output) |
| 168 | self.assertEqual(len(yaml_ir['items']), 1) |
| 169 | self.assertIn('name', output) |
| 170 | self.assertNotIn('secret', output) |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 171 | |
| 172 | def test_static_options(self): |
| 173 | xproto = \ |
| 174 | """ |
| 175 | option app_label = "test"; |
| 176 | |
| 177 | message Foo { |
| 178 | required string name = 1 [ null = "False", blank="False"]; |
| 179 | required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False]; |
| 180 | } |
| 181 | """ |
| 182 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 183 | args = XOSProcessorArgs() |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 184 | args.inputs = xproto |
| 185 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 186 | output = XOSProcessor.process(args) |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 187 | self.assertIn("options:", output) |
| 188 | self.assertIn(" {'id': 'container_vm', 'label': 'Container In VM'}", output) |
| 189 | |
| 190 | def test_not_static_options(self): |
| 191 | xproto = \ |
| 192 | """ |
| 193 | option app_label = "test"; |
| 194 | |
| 195 | message Foo { |
| 196 | required string name = 1 [ null = "False", blank="False"]; |
| 197 | } |
| 198 | """ |
| 199 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 200 | args = XOSProcessorArgs() |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 201 | args.inputs = xproto |
| 202 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 203 | output = XOSProcessor.process(args) |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 204 | self.assertNotIn("options:", output) |
| 205 | |
| 206 | def test_default_value_in_modeldef(self): |
| 207 | xproto = \ |
| 208 | """ |
| 209 | option app_label = "test"; |
| 210 | |
| 211 | message Foo { |
| 212 | required string name = 1 [ null = "False", blank="False", default = "bar"]; |
| 213 | required string falsetrue = 1 [ null = "False", blank="False", default = False]; |
| 214 | required string truefalse = 1 [ null = "False", blank="False", default = True]; |
| 215 | required string some = 1 [ null = "False", blank="False", default = None]; |
| 216 | required string zero = 1 [ null = "False", blank="False", default = 0]; |
| 217 | } |
| 218 | """ |
| 219 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 220 | args = XOSProcessorArgs() |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 221 | args.inputs = xproto |
| 222 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 223 | output = XOSProcessor.process(args) |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 224 | self.assertIn('default: "bar"', output) |
| 225 | self.assertIn('default: "false"', output) |
| 226 | self.assertIn('default: "true"', output) |
| 227 | self.assertIn('default: "null"', output) |
| 228 | self.assertIn('default: "0"', output) |
| 229 | |
| 230 | def test_not_default_value_in_modeldef(self): |
| 231 | xproto = \ |
| 232 | """ |
| 233 | option app_label = "test"; |
| 234 | |
| 235 | message Foo { |
| 236 | required string name = 1 [ null = "False", blank="False"]; |
| 237 | } |
| 238 | """ |
| 239 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 240 | args = XOSProcessorArgs() |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 241 | args.inputs = xproto |
| 242 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 243 | output = XOSProcessor.process(args) |
Matteo Scandolo | 292cc2a | 2017-07-31 19:02:12 -0700 | [diff] [blame] | 244 | self.assertNotIn('default:', output) |
| 245 | |
Matteo Scandolo | 1f826a4 | 2017-08-02 12:02:02 -0700 | [diff] [blame] | 246 | def test_one_to_many_in_modeldef(self): |
| 247 | xproto = \ |
| 248 | """ |
| 249 | option app_label = "test"; |
| 250 | |
| 251 | message ServiceDependency { |
| 252 | required manytoone provider_service->Service:provided_dependencies = 1; |
| 253 | required manytoone subscriber_service->Service:subscribed_dependencies = 2; |
| 254 | } |
| 255 | |
| 256 | message Service { |
| 257 | required string name = 1; |
| 258 | } |
| 259 | """ |
| 260 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 261 | args = XOSProcessorArgs() |
Matteo Scandolo | 1f826a4 | 2017-08-02 12:02:02 -0700 | [diff] [blame] | 262 | args.inputs = xproto |
| 263 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 264 | output = XOSProcessor.process(args) |
Matteo Scandolo | 1f826a4 | 2017-08-02 12:02:02 -0700 | [diff] [blame] | 265 | # Service deps model |
| 266 | self.assertIn('{model: Service, type: manytoone, on_field: provider_service}', output) |
| 267 | self.assertIn('{model: Service, type: manytoone, on_field: provider_service}', output) |
| 268 | |
| 269 | # Service model |
| 270 | self.assertIn('{model: ServiceDependency, type: onetomany, on_field: provider_service}', output) |
| 271 | self.assertIn('{model: ServiceDependency, type: onetomany, on_field: provider_service}', output) |
| 272 | |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 273 | def test_model_description(self): |
| 274 | xproto = \ |
| 275 | """ |
| 276 | option app_label = "test"; |
| 277 | |
| 278 | message Foo { |
| 279 | option description="This is the Foo model"; |
| 280 | required string name = 1 [ null = "False", blank="False"]; |
| 281 | required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False]; |
| 282 | } |
| 283 | |
| 284 | message Bar { |
| 285 | required string name = 1; |
| 286 | } |
| 287 | """ |
| 288 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 289 | args = XOSProcessorArgs() |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 290 | args.inputs = xproto |
| 291 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 292 | output = XOSProcessor.process(args) |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 293 | self.assertIn('description: "This is the Foo model"', output) |
| 294 | |
| 295 | def test_model_verbose_name(self): |
| 296 | xproto = \ |
| 297 | """ |
| 298 | option app_label = "test"; |
| 299 | |
| 300 | message Foo { |
| 301 | option verbose_name="Verbose Foo Name"; |
| 302 | required string name = 1 [ null = "False", blank="False"]; |
| 303 | required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False]; |
| 304 | } |
| 305 | |
| 306 | message Bar { |
| 307 | required string name = 1; |
| 308 | } |
| 309 | """ |
| 310 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 311 | args = XOSProcessorArgs() |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 312 | args.inputs = xproto |
| 313 | args.target = 'modeldefs.xtarget' |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 314 | output = XOSProcessor.process(args) |
Matteo Scandolo | e425f9d | 2017-08-15 15:56:19 -0700 | [diff] [blame] | 315 | self.assertIn('verbose_name: "Verbose Foo Name"', output) |
| 316 | |
Matteo Scandolo | 23cf15f | 2018-03-06 18:12:36 -0800 | [diff] [blame] | 317 | def test_feedback_field(self): |
| 318 | xproto = \ |
| 319 | """ |
| 320 | option app_label = "test"; |
| 321 | |
| 322 | message ParentFoo { |
| 323 | required string parent_name = 1 [null = False, blank = False, feedback_state = True]; |
| 324 | } |
| 325 | |
| 326 | message Foo (ParentFoo) { |
| 327 | required string name = 1 [null = False, blank = False, feedback_state = True]; |
| 328 | } |
| 329 | """ |
| 330 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 331 | args = XOSProcessorArgs() |
Matteo Scandolo | 23cf15f | 2018-03-06 18:12:36 -0800 | [diff] [blame] | 332 | args.inputs = xproto |
| 333 | args.target = 'modeldefs.xtarget' |
| 334 | output = XOSProcessor.process(args) |
| 335 | |
| 336 | read_only = filter(lambda s: 'read_only: True' in s, output.splitlines()) |
| 337 | self.assertEqual(len(read_only), 3) # readonly is 1 for ParentFoo and 2 for Foo |
| 338 | |
Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 339 | if __name__ == '__main__': |
| 340 | unittest.main() |
| 341 | |
| 342 | |