|
| 1 | +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +from test.integ.encrypted.test_resource import INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME |
| 4 | + |
| 5 | + |
| 6 | +def basic_put_item_response(item): |
| 7 | + """Get a put_item response in resource (ddb) format for any item.""" |
| 8 | + return {"Attributes": item} |
| 9 | + |
| 10 | + |
| 11 | +def exhaustive_put_item_response(item): |
| 12 | + """ |
| 13 | + Get a put_item response in resource (ddb) format for any item. |
| 14 | + This is not intended to be a real response that DynamoDB would return, |
| 15 | + but the response should contain additional attributes that DynamoDB could return. |
| 16 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 17 | + """ |
| 18 | + base = basic_put_item_response(item) |
| 19 | + additional_keys = { |
| 20 | + "ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}, |
| 21 | + "ItemCollectionMetrics": { |
| 22 | + "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME, |
| 23 | + "ItemCollectionKey": {"partition_key": item["partition_key"]}, |
| 24 | + }, |
| 25 | + "SequenceNumber": "1234567890", |
| 26 | + "SizeEstimateRangeGB": [0.5, 1.0], |
| 27 | + } |
| 28 | + return {**base, **additional_keys} |
| 29 | + |
| 30 | + |
| 31 | +def basic_get_item_response(item): |
| 32 | + """Get a get_item response in resource (ddb) format for any item.""" |
| 33 | + return {"Item": item} |
| 34 | + |
| 35 | + |
| 36 | +def exhaustive_get_item_response(item): |
| 37 | + """ |
| 38 | + Get a get_item response in resource (ddb) format for any item. |
| 39 | + This is not intended to be a real response that DynamoDB would return, |
| 40 | + but the response should contain additional attributes that DynamoDB could return. |
| 41 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 42 | + """ |
| 43 | + base = basic_get_item_response(item) |
| 44 | + additional_keys = { |
| 45 | + "ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}, |
| 46 | + } |
| 47 | + return {**base, **additional_keys} |
| 48 | + |
| 49 | + |
| 50 | +def basic_query_response(items): |
| 51 | + """Get a query response in resource (ddb) format for any items.""" |
| 52 | + return { |
| 53 | + "Items": items, |
| 54 | + "Count": len(items), |
| 55 | + "ScannedCount": len(items), |
| 56 | + "ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}, |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | +def exhaustive_query_response(items): |
| 61 | + """ |
| 62 | + Get a query response in resource (ddb) format for any items. |
| 63 | + This is not intended to be a real response that DynamoDB would return, |
| 64 | + but the response should contain additional attributes that DynamoDB could return. |
| 65 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 66 | + """ |
| 67 | + base = basic_query_response(items) |
| 68 | + additional_keys = { |
| 69 | + "LastEvaluatedKey": {"partition_key": items[-1]["partition_key"]}, |
| 70 | + } |
| 71 | + return {**base, **additional_keys} |
| 72 | + |
| 73 | + |
| 74 | +def basic_scan_response(items, keys): |
| 75 | + """Get a scan response in resource (ddb) format for any items.""" |
| 76 | + return { |
| 77 | + "Items": items, |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | +def exhaustive_scan_response(items, keys): |
| 82 | + """ |
| 83 | + Get a scan response in resource (ddb) format for any items. |
| 84 | + This is not intended to be a real response that DynamoDB would return, |
| 85 | + but the response should contain additional attributes that DynamoDB could return. |
| 86 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 87 | + """ |
| 88 | + base = basic_scan_response(items, keys) |
| 89 | + additional_keys = { |
| 90 | + "ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}, |
| 91 | + "Count": len(items), |
| 92 | + "ScannedCount": len(items), |
| 93 | + "LastEvaluatedKey": keys[-1], |
| 94 | + } |
| 95 | + return {**base, **additional_keys} |
| 96 | + |
| 97 | + |
| 98 | +def basic_batch_get_item_response(items): |
| 99 | + """Get a batch_get_item response in resource (ddb) format for any items.""" |
| 100 | + return {"Responses": {INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: items}} |
| 101 | + |
| 102 | + |
| 103 | +def exhaustive_batch_get_item_response(items): |
| 104 | + """ |
| 105 | + Get a batch_get_item response in resource (ddb) format for any items. |
| 106 | + This is not intended to be a real response that DynamoDB would return, |
| 107 | + but the response should contain additional attributes that DynamoDB could return. |
| 108 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 109 | + """ |
| 110 | + base = basic_batch_get_item_response(items) |
| 111 | + additional_keys = { |
| 112 | + "UnprocessedKeys": { |
| 113 | + INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: { |
| 114 | + "Keys": [{"partition_key": item["partition_key"]} for item in items] |
| 115 | + } |
| 116 | + }, |
| 117 | + } |
| 118 | + return {**base, **additional_keys} |
| 119 | + |
| 120 | + |
| 121 | +def basic_batch_write_item_put_response(items): |
| 122 | + """Get a batch_write_item response in resource (ddb) format for any items.""" |
| 123 | + return { |
| 124 | + "UnprocessedItems": {INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: [{"PutRequest": {"Item": item}} for item in items]} |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | +def exhaustive_batch_write_item_put_response(items): |
| 129 | + """ |
| 130 | + Get a batch_write_item response in resource (ddb) format for any items. |
| 131 | + This is not intended to be a real response that DynamoDB would return, |
| 132 | + but the response should contain additional attributes that DynamoDB could return. |
| 133 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 134 | + """ |
| 135 | + base = basic_batch_write_item_put_response(items) |
| 136 | + additional_keys = { |
| 137 | + "ItemCollectionMetrics": { |
| 138 | + INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: [ |
| 139 | + {"ItemCollectionKey": {"partition_key": items[-1]["partition_key"]}} |
| 140 | + ] |
| 141 | + }, |
| 142 | + } |
| 143 | + return {**base, **additional_keys} |
| 144 | + |
| 145 | + |
| 146 | +def basic_transact_write_items_response(items): |
| 147 | + """Get a transact_write_items response in resource (ddb) format for any items.""" |
| 148 | + return { |
| 149 | + "ItemCollectionMetrics": { |
| 150 | + INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: [ |
| 151 | + {"ItemCollectionKey": {"partition_key": items[-1]["partition_key"]}} |
| 152 | + ] |
| 153 | + }, |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | +# No exhaustive response for transact_write_items; |
| 158 | +# The basic_transact_write_items_response is sufficient |
| 159 | + |
| 160 | + |
| 161 | +def basic_transact_get_items_response(items): |
| 162 | + """Get a transact_get_items response in resource (ddb) format for any items.""" |
| 163 | + return {"Responses": [{"Item": item} for item in items]} |
| 164 | + |
| 165 | + |
| 166 | +# No exhaustive response for transact_get_items; |
| 167 | +# The basic_transact_get_items_response is sufficient |
| 168 | + |
| 169 | + |
| 170 | +def basic_update_item_response(item): |
| 171 | + """Get an update_item response in resource (ddb) format for any item.""" |
| 172 | + return {"Attributes": item} |
| 173 | + |
| 174 | + |
| 175 | +def exhaustive_update_item_response(item): |
| 176 | + """ |
| 177 | + Get an update_item response in resource (ddb) format for any item. |
| 178 | + This is not intended to be a real response that DynamoDB would return, |
| 179 | + but the response should contain additional attributes that DynamoDB could return. |
| 180 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 181 | + """ |
| 182 | + base = basic_update_item_response(item) |
| 183 | + additional_keys = { |
| 184 | + "ItemCollectionMetrics": { |
| 185 | + "ItemCollectionKey": {"partition_key": item["partition_key"]}, |
| 186 | + }, |
| 187 | + } |
| 188 | + return {**base, **additional_keys} |
| 189 | + |
| 190 | + |
| 191 | +def basic_delete_item_response(item): |
| 192 | + """Get a delete_item response in resource (ddb) format for any item.""" |
| 193 | + return {"Attributes": item} |
| 194 | + |
| 195 | + |
| 196 | +def exhaustive_delete_item_response(item): |
| 197 | + """ |
| 198 | + Get a delete_item response in resource (ddb) format for any item. |
| 199 | + This is not intended to be a real response that DynamoDB would return, |
| 200 | + but the response should contain additional attributes that DynamoDB could return. |
| 201 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 202 | + """ |
| 203 | + base = basic_delete_item_response(item) |
| 204 | + additional_keys = { |
| 205 | + "ItemCollectionMetrics": { |
| 206 | + "ItemCollectionKey": {"partition_key": item["partition_key"]}, |
| 207 | + }, |
| 208 | + } |
| 209 | + return {**base, **additional_keys} |
| 210 | + |
| 211 | + |
| 212 | +def basic_execute_statement_response(items): |
| 213 | + """Get an execute_statement response in resource (ddb) format for any items.""" |
| 214 | + return {"Items": items} |
| 215 | + |
| 216 | + |
| 217 | +def exhaustive_execute_statement_response(items): |
| 218 | + """ |
| 219 | + Get an execute_statement response in resource (ddb) format for any items. |
| 220 | + This is not intended to be a real response that DynamoDB would return, |
| 221 | + but the response should contain additional attributes that DynamoDB could return. |
| 222 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 223 | + """ |
| 224 | + base = basic_execute_statement_response(items) |
| 225 | + additional_keys = { |
| 226 | + "LastEvaluatedKey": { |
| 227 | + "partition_key": items[-1]["partition_key"], |
| 228 | + "sort_key": items[-1]["sort_key"], |
| 229 | + }, |
| 230 | + } |
| 231 | + return {**base, **additional_keys} |
| 232 | + |
| 233 | + |
| 234 | +def basic_execute_transaction_response(items): |
| 235 | + """Get an execute_transaction response in resource (ddb) format for any items.""" |
| 236 | + return {"Responses": [{"Item": item} for item in items]} |
| 237 | + |
| 238 | + |
| 239 | +# No exhaustive response for execute_transaction; |
| 240 | +# The basic_execute_transaction_response is sufficient |
| 241 | + |
| 242 | + |
| 243 | +def basic_batch_execute_statement_response(items): |
| 244 | + """Get a batch_execute_statement response in resource (ddb) format for any items.""" |
| 245 | + return {"Responses": [{"Item": item} for item in items]} |
| 246 | + |
| 247 | + |
| 248 | +def exhaustive_batch_execute_statement_response(items): |
| 249 | + """ |
| 250 | + Get a batch_execute_statement response in resource (ddb) format for any items. |
| 251 | + This is not intended to be a real response that DynamoDB would return, |
| 252 | + but the response should contain additional attributes that DynamoDB could return. |
| 253 | + This is only intended to exhaustively test the conversion of the request between client and resource formats. |
| 254 | + """ |
| 255 | + base = basic_batch_execute_statement_response(items) |
| 256 | + base["Responses"][0]["Error"] = { |
| 257 | + "Item": { |
| 258 | + "partition_key": items[0]["partition_key"], |
| 259 | + "sort_key": items[0]["sort_key"], |
| 260 | + } |
| 261 | + } |
| 262 | + return base |
0 commit comments