MCPcopy Create free account
hub / github.com/ExtendDB/extenddb / test_import_dynamodb_json

Method test_import_dynamodb_json

tests/test_import_export.py:173–213  ·  view source on GitHub ↗

Import items from DYNAMODB_JSON file.

(self, dynamodb_client, unique_table_name, cleanup_table)

Source from the content-addressed store, hash-verified

171 """Tests for ImportTable."""
172
173 def test_import_dynamodb_json(self, dynamodb_client, unique_table_name, cleanup_table):
174 """Import items from DYNAMODB_JSON file."""
175 name = unique_table_name
176 cleanup_table(name)
177
178 items = [
179 {"Item": {"pk": {"S": f"imp-{i}"}, "val": {"N": str(i)}}}
180 for i in range(3)
181 ]
182 with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
183 for item in items:
184 f.write(json.dumps(item) + "\n")
185 source_path = f.name
186
187 try:
188 resp = extenddb_request("ImportTable", {
189 "FileSource": {"Path": source_path},
190 "InputFormat": "DYNAMODB_JSON",
191 "TableCreationParameters": {
192 "TableName": name,
193 "AttributeDefinitions": [
194 {"AttributeName": "pk", "AttributeType": "S"},
195 ],
196 "KeySchema": [
197 {"AttributeName": "pk", "KeyType": "HASH"},
198 ],
199 "BillingMode": "PAY_PER_REQUEST",
200 },
201 })
202 desc = resp["ImportTableDescription"]
203 assert desc["ImportStatus"] == "COMPLETED"
204 assert desc["ImportedItemCount"] == 3
205 assert desc["ErrorCount"] == 0
206
207 for i in range(3):
208 item = dynamodb_client.get_item(
209 TableName=name, Key={"pk": {"S": f"imp-{i}"}}
210 )
211 assert item["Item"]["val"]["N"] == str(i)
212 finally:
213 os.unlink(source_path)
214
215 def test_import_csv(self, dynamodb_client, unique_table_name, cleanup_table):
216 """Import items from CSV file."""

Callers

nothing calls this directly

Calls 4

cleanup_tableFunction · 0.85
extenddb_requestFunction · 0.85
writeMethod · 0.80
get_itemMethod · 0.80

Tested by

no test coverage detected