Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix low level api operations fail without describe_table (#1249) #1250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions tests/integration/base_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

63 changes: 63 additions & 0 deletions tests/integration/table_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)