|
13 | 13 | import json
|
14 | 14 |
|
15 | 15 | from botocore.model import ShapeResolver, StructureShape, StringShape, \
|
16 |
| - ListShape, MapShape, Shape |
| 16 | + ListShape, MapShape, Shape, DenormalizedStructureBuilder |
17 | 17 |
|
18 | 18 | from awscli.testutils import mock, unittest, FileCreator
|
19 | 19 | from awscli.clidocs import OperationDocumentEventHandler, \
|
@@ -150,6 +150,15 @@ def create_help_command(self):
|
150 | 150 | help_command.obj = operation_model
|
151 | 151 | return help_command
|
152 | 152 |
|
| 153 | + def create_tagged_union_shape(self): |
| 154 | + shape_model = { |
| 155 | + 'type': 'structure', |
| 156 | + 'union': True, |
| 157 | + 'members': {} |
| 158 | + } |
| 159 | + tagged_union = StructureShape('tagged_union', shape_model) |
| 160 | + return tagged_union |
| 161 | + |
153 | 162 | def get_help_docs_for_argument(self, shape):
|
154 | 163 | arg_table = {'arg-name': mock.Mock(argument_model=shape)}
|
155 | 164 | help_command = mock.Mock()
|
@@ -391,6 +400,50 @@ def test_streaming_blob_comes_after_docstring(self):
|
391 | 400 | rendered = help_command.doc.getvalue().decode('utf-8')
|
392 | 401 | self.assertRegex(rendered, r'FooBar[\s\S]*streaming blob')
|
393 | 402 |
|
| 403 | + def test_includes_tagged_union_options(self): |
| 404 | + help_command = self.create_help_command() |
| 405 | + tagged_union = self.create_tagged_union_shape() |
| 406 | + arg = CustomArgument(name='tagged_union', |
| 407 | + argument_model=tagged_union) |
| 408 | + help_command.arg_table = {'tagged_union': arg} |
| 409 | + operation_handler = OperationDocumentEventHandler(help_command) |
| 410 | + operation_handler.doc_option(arg_name='tagged_union', |
| 411 | + help_command=help_command) |
| 412 | + rendered = help_command.doc.getvalue().decode('utf-8') |
| 413 | + self.assertIn('(tagged union structure)', rendered) |
| 414 | + |
| 415 | + def test_tagged_union_comes_after_docstring_options(self): |
| 416 | + help_command = self.create_help_command() |
| 417 | + tagged_union = self.create_tagged_union_shape() |
| 418 | + arg = CustomArgument(name='tagged_union', |
| 419 | + argument_model=tagged_union, |
| 420 | + help_text='FooBar') |
| 421 | + help_command.arg_table = {'tagged_union': arg} |
| 422 | + operation_handler = OperationDocumentEventHandler(help_command) |
| 423 | + operation_handler.doc_option(arg_name='tagged_union', |
| 424 | + help_command=help_command) |
| 425 | + rendered = help_command.doc.getvalue().decode('utf-8') |
| 426 | + self.assertRegex(rendered, r'FooBar[\s\S]*Tagged Union') |
| 427 | + |
| 428 | + def test_tagged_union_comes_after_docstring_output(self): |
| 429 | + help_command = self.create_help_command() |
| 430 | + tagged_union = self.create_tagged_union_shape() |
| 431 | + tagged_union.documentation = "FooBar" |
| 432 | + shape = DenormalizedStructureBuilder().with_members({ |
| 433 | + 'foo': { |
| 434 | + 'type': 'structure', |
| 435 | + 'union': True, |
| 436 | + 'documentation': 'FooBar', |
| 437 | + 'members': {} |
| 438 | + } |
| 439 | + }).build_model() |
| 440 | + help_command.obj.output_shape = shape |
| 441 | + operation_handler = OperationDocumentEventHandler(help_command) |
| 442 | + operation_handler.doc_output(help_command=help_command, |
| 443 | + event_name='foobar') |
| 444 | + rendered = help_command.doc.getvalue().decode('utf-8') |
| 445 | + self.assertRegex(rendered, r'FooBar[\s\S]*Tagged Union') |
| 446 | + |
394 | 447 |
|
395 | 448 | class TestTopicDocumentEventHandlerBase(unittest.TestCase):
|
396 | 449 | def setUp(self):
|
|
0 commit comments