| 1 |
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 |
# may not use this file except in compliance with the License. A copy of |
| 5 |
# the License is located at |
| 6 |
# |
| 7 |
# https://aws.amazon.com/apache2.0/ |
| 8 |
# |
| 9 |
# or in the "license" file accompanying this file. This file is |
| 10 |
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 |
# ANY KIND, either express or implied. See the License for the specific |
| 12 |
# language governing permissions and limitations under the License. |
| 13 |
from boto3.docs.service import ServiceDocumenter |
| 14 |
from boto3.session import Session |
| 15 |
from tests.functional.docs import BaseDocsFunctionalTests |
| 16 |
|
| 17 |
|
| 18 |
class TestDynamoDBCustomizations(BaseDocsFunctionalTests): |
| 19 |
def setUp(self): |
| 20 |
super().setUp() |
| 21 |
self.documenter = ServiceDocumenter( |
| 22 |
'dynamodb', |
| 23 |
session=Session(region_name='us-east-1'), |
| 24 |
root_docs_path=self.root_services_path, |
| 25 |
) |
| 26 |
self.generated_contents = self.documenter.document_service() |
| 27 |
self.generated_contents = self.generated_contents.decode('utf-8') |
| 28 |
|
| 29 |
def test_batch_writer_is_documented(self): |
| 30 |
self.assert_contains_lines_in_order( |
| 31 |
[ |
| 32 |
'=========', |
| 33 |
'Resources', |
| 34 |
'=========', |
| 35 |
'The available resources are:', |
| 36 |
' dynamodb/table/index', |
| 37 |
], |
| 38 |
self.generated_contents, |
| 39 |
) |
| 40 |
self.assert_contains_lines_in_order( |
| 41 |
[ |
| 42 |
'.. py:class:: DynamoDB.Table(name)', |
| 43 |
' batch_writer', |
| 44 |
], |
| 45 |
self.get_nested_file_contents('dynamodb', 'table', 'index'), |
| 46 |
) |
| 47 |
self.assert_contains_lines_in_order( |
| 48 |
[ |
| 49 |
'************\nbatch_writer\n************', |
| 50 |
'.. py:method:: DynamoDB.Table.batch_writer(overwrite_by_pkeys=None)', |
| 51 |
], |
| 52 |
self.get_nested_file_contents('dynamodb', 'table', 'batch_writer'), |
| 53 |
) |
| 54 |
|
| 55 |
def test_document_interface_is_documented(self): |
| 56 |
put_item_content = self.get_nested_file_contents( |
| 57 |
'dynamodb', 'table', 'put_item' |
| 58 |
) |
| 59 |
self.assert_contains_lines_in_order( |
| 60 |
[ |
| 61 |
'********', |
| 62 |
'put_item', |
| 63 |
'********', |
| 64 |
'.. py:method:: DynamoDB.Table.put_item(**kwargs)', |
| 65 |
# Make sure the request syntax is as expected. |
| 66 |
'response = table.put_item(', |
| 67 |
'Item={', |
| 68 |
( |
| 69 |
'\'string\': \'string\'|123|Binary(b\'bytes\')' |
| 70 |
'|True|None|set([\'string\'])|set([123])|' |
| 71 |
'set([Binary(b\'bytes\')])|[]|{}' |
| 72 |
), |
| 73 |
'},', |
| 74 |
'Expected={', |
| 75 |
'\'string\': {', |
| 76 |
( |
| 77 |
'\'Value\': \'string\'|123' |
| 78 |
'|Binary(b\'bytes\')|True|None|set([\'string\'])' |
| 79 |
'|set([123])|set([Binary(b\'bytes\')])|[]|{},' |
| 80 |
), |
| 81 |
'\'AttributeValueList\': [', |
| 82 |
( |
| 83 |
'\'string\'|123|Binary(b\'bytes\')' |
| 84 |
'|True|None|set([\'string\'])|set([123])|' |
| 85 |
'set([Binary(b\'bytes\')])|[]|{},' |
| 86 |
), |
| 87 |
# Make sure the request parameter is documented correctly. |
| 88 |
':type Item: dict', |
| 89 |
':param Item: **[REQUIRED]**', |
| 90 |
'- *(string) --*', |
| 91 |
( |
| 92 |
'- *(valid DynamoDB type) -- *- The value of the ' |
| 93 |
'attribute. The valid value types are listed in the ' |
| 94 |
':ref:`DynamoDB Reference Guide<ref_valid_dynamodb_types>`.' |
| 95 |
), |
| 96 |
# Make sure the response syntax is as expected. |
| 97 |
'{', |
| 98 |
'\'Attributes\': {', |
| 99 |
( |
| 100 |
'\'string\': \'string\'|123|' |
| 101 |
'Binary(b\'bytes\')|True|None|set([\'string\'])|' |
| 102 |
'set([123])|set([Binary(b\'bytes\')])|[]|{}' |
| 103 |
), |
| 104 |
'},', |
| 105 |
# Make sure the response parameter is documented correctly. |
| 106 |
'- **Attributes** *(dict) --*', |
| 107 |
'- *(string) --*', |
| 108 |
( |
| 109 |
'- *(valid DynamoDB type) -- *- The value of ' |
| 110 |
'the attribute. The valid value types are listed in the ' |
| 111 |
':ref:`DynamoDB Reference Guide<ref_valid_dynamodb_types>`.' |
| 112 |
), |
| 113 |
], |
| 114 |
put_item_content, |
| 115 |
) |
| 116 |
|
| 117 |
def test_conditions_is_documented(self): |
| 118 |
query_contents = self.get_nested_file_contents( |
| 119 |
'dynamodb', 'table', 'query' |
| 120 |
) |
| 121 |
self.assert_contains_lines_in_order( |
| 122 |
[ |
| 123 |
# Make sure the request syntax is as expected. |
| 124 |
'response = table.query(', |
| 125 |
('FilterExpression=Attr(\'myattribute\').eq(\'myvalue\'),'), |
| 126 |
('KeyConditionExpression=Key(\'mykey\').eq(\'myvalue\'),'), |
| 127 |
# Make sure the request parameter is documented correctly. |
| 128 |
( |
| 129 |
':type FilterExpression: condition from ' |
| 130 |
':py:class:`boto3.dynamodb.conditions.Attr` method' |
| 131 |
), |
| 132 |
( |
| 133 |
':param FilterExpression: The condition(s) an ' |
| 134 |
'attribute(s) must meet. Valid conditions are listed in ' |
| 135 |
'the :ref:`DynamoDB Reference Guide<ref_dynamodb_conditions>`.' |
| 136 |
), |
| 137 |
( |
| 138 |
':type KeyConditionExpression: condition from ' |
| 139 |
':py:class:`boto3.dynamodb.conditions.Key` method' |
| 140 |
), |
| 141 |
( |
| 142 |
':param KeyConditionExpression: The condition(s) a ' |
| 143 |
'key(s) must meet. Valid conditions are listed in the ' |
| 144 |
':ref:`DynamoDB Reference Guide<ref_dynamodb_conditions>`.' |
| 145 |
), |
| 146 |
], |
| 147 |
query_contents, |
| 148 |
) |