|
24 | 24 | simple_key_dict,
|
25 | 25 | )
|
26 | 26 | from ...requests import (
|
27 |
| - basic_batch_execute_statement_request, |
28 | 27 | basic_batch_get_item_request_ddb,
|
29 | 28 | basic_batch_get_item_request_dict,
|
30 | 29 | basic_batch_write_item_delete_request_ddb,
|
|
33 | 32 | basic_batch_write_item_put_request_dict,
|
34 | 33 | basic_delete_item_request_ddb,
|
35 | 34 | basic_delete_item_request_dict,
|
36 |
| - basic_execute_statement_request, |
37 |
| - basic_execute_transaction_request, |
| 35 | + basic_execute_statement_request_encrypted_table, |
| 36 | + basic_execute_statement_request_plaintext_table, |
| 37 | + basic_execute_transaction_request_encrypted_table, |
| 38 | + basic_execute_transaction_request_plaintext_table, |
| 39 | + basic_batch_execute_statement_request_encrypted_table, |
| 40 | + basic_batch_execute_statement_request_plaintext_table, |
38 | 41 | basic_get_item_request_ddb,
|
39 | 42 | basic_get_item_request_dict,
|
40 | 43 | basic_put_item_request_ddb,
|
@@ -428,68 +431,129 @@ def test_WHEN_update_item_with_signed_attribute_THEN_raises_DynamoDbEncryptionTr
|
428 | 431 | client.update_item(**update_item_request_signed_attribute)
|
429 | 432 |
|
430 | 433 |
|
| 434 | +@pytest.fixture(params=[True, False], ids=["encrypted_table", "plaintext_table"]) |
| 435 | +def execute_uses_encrypted_table(request): |
| 436 | + return request.param |
| 437 | + |
431 | 438 | @pytest.fixture
|
432 |
| -def execute_statement_request(): |
433 |
| - return basic_execute_statement_request() |
| 439 | +def execute_statement_request(execute_uses_encrypted_table): |
| 440 | + if execute_uses_encrypted_table: |
| 441 | + return basic_execute_statement_request_encrypted_table() |
| 442 | + return basic_execute_statement_request_plaintext_table() |
434 | 443 |
|
435 | 444 |
|
436 |
| -def test_WHEN_execute_statement_THEN_raises_DynamoDbEncryptionTransformsException( |
| 445 | +def test_WHEN_execute_statement_for_encrypted_table_THEN_raises_DynamoDbEncryptionTransformsException( |
437 | 446 | client,
|
438 | 447 | execute_statement_request,
|
439 | 448 | encrypted,
|
| 449 | + execute_uses_encrypted_table, |
440 | 450 | ):
|
441 | 451 | """Test that execute_statement raises DynamoDbEncryptionTransformsException."""
|
442 | 452 | if not encrypted:
|
443 | 453 | pytest.skip("Skipping negative test for plaintext client")
|
444 | 454 |
|
445 |
| - # Given: Encrypted client and update item parameters |
446 |
| - # Then: DynamoDbEncryptionTransformsException is raised |
447 |
| - with pytest.raises(DynamoDbEncryptionTransformsException): |
448 |
| - # When: Calling update_item |
449 |
| - client.execute_statement(**execute_statement_request) |
| 455 | + if execute_uses_encrypted_table: |
| 456 | + # Given: Encrypted client and execute_statement request on encrypted table |
| 457 | + # Then: DynamoDbEncryptionTransformsException is raised |
| 458 | + with pytest.raises(DynamoDbEncryptionTransformsException): |
| 459 | + # When: Calling execute_statement |
| 460 | + client.execute_statement(**execute_statement_request) |
| 461 | + else: |
| 462 | + pytest.skip("Skipping test for plaintext table; this test is only for encrypted tables") |
| 463 | + |
| 464 | +def test_WHEN_execute_statement_for_plaintext_table_THEN_passes( |
| 465 | + client, |
| 466 | + execute_statement_request, |
| 467 | + execute_uses_encrypted_table, |
| 468 | +): |
| 469 | + if execute_uses_encrypted_table: |
| 470 | + pytest.skip("Skipping test for encrypted table; this test is only for plaintext tables") |
450 | 471 |
|
| 472 | + # Given: Client calls execute_statement on plaintext table |
| 473 | + # When: Calling execute_statement |
| 474 | + response = client.execute_statement(**execute_statement_request) |
| 475 | + # Then: Success |
| 476 | + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
451 | 477 |
|
452 | 478 | @pytest.fixture
|
453 |
| -def execute_transaction_request(): |
454 |
| - return basic_execute_transaction_request() |
| 479 | +def execute_transaction_request(execute_uses_encrypted_table): |
| 480 | + if execute_uses_encrypted_table: |
| 481 | + return basic_execute_transaction_request_encrypted_table() |
| 482 | + return basic_execute_transaction_request_plaintext_table() |
455 | 483 |
|
456 | 484 |
|
457 |
| -def test_WHEN_execute_transaction_THEN_raises_DynamoDbEncryptionTransformsException( |
| 485 | +def test_WHEN_execute_transaction_for_encrypted_table_THEN_raises_DynamoDbEncryptionTransformsException( |
458 | 486 | client,
|
459 | 487 | execute_transaction_request,
|
460 | 488 | encrypted,
|
| 489 | + execute_uses_encrypted_table, |
461 | 490 | ):
|
462 | 491 | """Test that execute_transaction raises DynamoDbEncryptionTransformsException."""
|
463 | 492 | if not encrypted:
|
464 | 493 | pytest.skip("Skipping negative test for plaintext client")
|
| 494 | + |
| 495 | + if execute_uses_encrypted_table: |
| 496 | + # Given: Encrypted client and execute_transaction request on encrypted table |
| 497 | + # Then: DynamoDbEncryptionTransformsException is raised |
| 498 | + with pytest.raises(DynamoDbEncryptionTransformsException): |
| 499 | + # When: Calling execute_transaction |
| 500 | + client.execute_transaction(**execute_transaction_request) |
| 501 | + else: |
| 502 | + pytest.skip("Skipping test for plaintext table; this test is only for encrypted tables") |
465 | 503 |
|
466 |
| - # Given: Encrypted client and update item parameters |
467 |
| - # Then: DynamoDbEncryptionTransformsException is raised |
468 |
| - with pytest.raises(DynamoDbEncryptionTransformsException): |
469 |
| - # When: Calling update_item |
470 |
| - client.execute_transaction(**execute_transaction_request) |
| 504 | +def test_WHEN_execute_transaction_for_plaintext_table_THEN_passes( |
| 505 | + client, |
| 506 | + execute_transaction_request, |
| 507 | + execute_uses_encrypted_table, |
| 508 | +): |
| 509 | + if execute_uses_encrypted_table: |
| 510 | + pytest.skip("Skipping test for encrypted table; this test is only for plaintext tables") |
471 | 511 |
|
| 512 | + # Given: Client calls execute_transaction on plaintext table |
| 513 | + # When: Calling execute_transaction |
| 514 | + response = client.execute_transaction(**execute_transaction_request) |
| 515 | + # Then: Success |
| 516 | + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
472 | 517 |
|
473 | 518 | @pytest.fixture
|
474 |
| -def batch_execute_statement_request(): |
475 |
| - return basic_batch_execute_statement_request() |
| 519 | +def batch_execute_statement_request(execute_uses_encrypted_table): |
| 520 | + if execute_uses_encrypted_table: |
| 521 | + return basic_batch_execute_statement_request_encrypted_table() |
| 522 | + return basic_batch_execute_statement_request_plaintext_table() |
476 | 523 |
|
477 | 524 |
|
478 |
| -def test_WHEN_batch_execute_statement_THEN_raises_DynamoDbEncryptionTransformsException( |
| 525 | +def test_WHEN_batch_execute_statement_for_encrypted_table_THEN_raises_DynamoDbEncryptionTransformsException( |
479 | 526 | client,
|
480 | 527 | batch_execute_statement_request,
|
481 | 528 | encrypted,
|
| 529 | + execute_uses_encrypted_table, |
482 | 530 | ):
|
483 | 531 | """Test that batch_execute_statement raises DynamoDbEncryptionTransformsException."""
|
484 | 532 | if not encrypted:
|
485 | 533 | pytest.skip("Skipping negative test for plaintext client")
|
486 | 534 |
|
487 |
| - # Given: Encrypted client and update item parameters |
488 |
| - # Then: DynamoDbEncryptionTransformsException is raised |
489 |
| - with pytest.raises(DynamoDbEncryptionTransformsException): |
490 |
| - # When: Calling update_item |
491 |
| - client.batch_execute_statement(**batch_execute_statement_request) |
| 535 | + if execute_uses_encrypted_table: |
| 536 | + # Given: Encrypted client and batch_execute_statement request on encrypted table |
| 537 | + # Then: DynamoDbEncryptionTransformsException is raised |
| 538 | + with pytest.raises(DynamoDbEncryptionTransformsException): |
| 539 | + # When: Calling batch_execute_statement |
| 540 | + client.batch_execute_statement(**batch_execute_statement_request) |
| 541 | + else: |
| 542 | + pytest.skip("Skipping test for plaintext table; this test is only for encrypted tables") |
492 | 543 |
|
| 544 | +def test_WHEN_batch_execute_statement_for_plaintext_table_THEN_passes( |
| 545 | + client, |
| 546 | + batch_execute_statement_request, |
| 547 | + execute_uses_encrypted_table, |
| 548 | +): |
| 549 | + if execute_uses_encrypted_table: |
| 550 | + pytest.skip("Skipping test for encrypted table; this test is only for plaintext tables") |
| 551 | + |
| 552 | + # Given: Client calls batch_execute_statement on plaintext table |
| 553 | + # When: Calling batch_execute_statement |
| 554 | + response = client.batch_execute_statement(**batch_execute_statement_request) |
| 555 | + # Then: Success |
| 556 | + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
493 | 557 |
|
494 | 558 | def test_WHEN_get_paginator_THEN_correct_paginator_is_returned():
|
495 | 559 | """Test get_paginator for scan and query operations."""
|
|
0 commit comments