Import items from CSV file.
(self, dynamodb_client, unique_table_name, cleanup_table)
| 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.""" |
| 217 | name = unique_table_name |
| 218 | cleanup_table(name) |
| 219 | |
| 220 | csv_content = "pk,name,age\ncsv-1,Alice,30\ncsv-2,Bob,25\n" |
| 221 | with tempfile.NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as f: |
| 222 | f.write(csv_content) |
| 223 | source_path = f.name |
| 224 | |
| 225 | try: |
| 226 | resp = extenddb_request("ImportTable", { |
| 227 | "FileSource": {"Path": source_path}, |
| 228 | "InputFormat": "CSV", |
| 229 | "TableCreationParameters": { |
| 230 | "TableName": name, |
| 231 | "AttributeDefinitions": [ |
| 232 | {"AttributeName": "pk", "AttributeType": "S"}, |
| 233 | ], |
| 234 | "KeySchema": [ |
| 235 | {"AttributeName": "pk", "KeyType": "HASH"}, |
| 236 | ], |
| 237 | "BillingMode": "PAY_PER_REQUEST", |
| 238 | }, |
| 239 | }) |
| 240 | desc = resp["ImportTableDescription"] |
| 241 | assert desc["ImportStatus"] == "COMPLETED" |
| 242 | assert desc["ImportedItemCount"] == 2 |
| 243 | |
| 244 | item = dynamodb_client.get_item( |
| 245 | TableName=name, Key={"pk": {"S": "csv-1"}} |
| 246 | ) |
| 247 | assert item["Item"]["name"]["S"] == "Alice" |
| 248 | assert item["Item"]["age"]["S"] == "30" |
| 249 | finally: |
| 250 | os.unlink(source_path) |
| 251 | |
| 252 | def test_import_nonexistent_source(self, dynamodb_client, unique_table_name, cleanup_table): |
| 253 | """Import from nonexistent path returns error.""" |
nothing calls this directly
no test coverage detected