diff --git a/tests/integration/base_integration_test.py b/tests/integration/base_integration_test.py index 87c38636..d4b02b9e 100644 --- a/tests/integration/base_integration_test.py +++ b/tests/integration/base_integration_test.py @@ -167,3 +167,83 @@ def test_connection_integration(ddb_url): ) print("conn.delete_table...") conn.delete_table(table_name) + + +def test_conn_without_describe_table_called(ddb_url, table: str): + conn = Connection(host=ddb_url) + # conn.describe_table(table) # bug: operations don't work without calling describe_table first + + conn.put_item( + table, + 'item1-hash', + attributes={'foo': {'S': 'bar'}}, + ) + get_response = conn.get_item( + table, + 'item1-hash', + ) + assert get_response.get('Item') == {'id': {'S': 'item1-hash'}, 'foo': {'S': 'bar'}} + + conn.update_item( + table, + 'item1-hash', + actions=[Path('foo').set("rab")] + ) + + get_response_after_update = conn.get_item( + table, + 'item1-hash', + ) + assert get_response_after_update.get('Item') == {'id': {'S': 'item1-hash'}, 'foo': {'S': 'rab'}} + + conn.delete_item( + table, + 'item1-hash', + ) + get_response_after_delete = conn.get_item( + table, + 'item1-hash', + ) + assert get_response_after_delete.get('Item') == None + + +@pytest.fixture +def table(ddb_url): + table_name = 'pynamodb-ci-connection' + + conn = Connection(host=ddb_url) + params = { + 'read_capacity_units': 1, + 'write_capacity_units': 1, + 'attribute_definitions': [ + { + 'attribute_type': STRING, + 'attribute_name': 'id' + }, + ], + 'key_schema': [ + { + 'key_type': HASH, + 'attribute_name': 'id' + } + ], + } + conn.create_table(table_name, **params) + for i in range(0,10): + time.sleep(1) + if conn.describe_table(table_name) is not None: + break + if i == 9: + raise TimeoutError + + for i in range(0,10): + time.sleep(1) + if conn.describe_table(table_name)['TableStatus'] == 'ACTIVE': + break + if i == 9: + raise TimeoutError + + yield table_name + + conn.delete_table(table_name) + diff --git a/tests/integration/table_integration_test.py b/tests/integration/table_integration_test.py index f05b5e71..9af9465e 100644 --- a/tests/integration/table_integration_test.py +++ b/tests/integration/table_integration_test.py @@ -2,6 +2,7 @@ Run tests against dynamodb using the table abstraction """ import time +from pynamodb.connection.base import Connection from pynamodb.constants import PROVISIONED_THROUGHPUT, READ_CAPACITY_UNITS from pynamodb.connection import TableConnection from pynamodb.expressions.condition import BeginsWith, NotExists @@ -154,3 +155,65 @@ def test_table_integration(ddb_url): conn.scan() print("conn.delete_table...") conn.delete_table() + + +def test_table_conn_without_describe_table_called(ddb_url, table: str): + conn = TableConnection(table_name=table, host=ddb_url) + # conn.describe_table() # bug: operations don't work without calling describe_table first + conn.put_item( + 'item1-hash', + attributes={'foo': {'S': 'bar'}}, + ) + assert conn.get_item('item1-hash').get('Item') == {'id': {'S': 'item1-hash'}, 'foo': {'S': 'bar'}} + + conn.update_item( + 'item1-hash', + actions=[Path('foo').set("rab")] + ) + + assert conn.get_item('item1-hash').get('Item') == {'id': {'S': 'item1-hash'}, 'foo': {'S': 'rab'}} + + conn.delete_item('item1-hash') + assert conn.get_item('item1-hash').get('Item') == None + + +@pytest.fixture +def table(ddb_url): + table_name = 'pynamodb-ci-connection' + + conn = Connection(host=ddb_url) + params = { + 'read_capacity_units': 1, + 'write_capacity_units': 1, + 'attribute_definitions': [ + { + 'attribute_type': STRING, + 'attribute_name': 'id' + }, + ], + 'key_schema': [ + { + 'key_type': HASH, + 'attribute_name': 'id' + } + ], + } + conn.create_table(table_name, **params) + for i in range(0,10): + time.sleep(1) + if conn.describe_table(table_name) is not None: + break + if i == 9: + raise TimeoutError + + for i in range(0,10): + time.sleep(1) + if conn.describe_table(table_name)['TableStatus'] == 'ACTIVE': + break + if i == 9: + raise TimeoutError + + yield table_name + + conn.delete_table(table_name) +