Fix Dynamodb table key name. Closes #524.

This commit is contained in:
Steve Pulec 2016-05-05 22:14:23 -04:00
parent 68de6feb01
commit 6803444d61
4 changed files with 33 additions and 10 deletions

View File

@ -182,10 +182,9 @@ class Table(object):
self.created_at = datetime.datetime.now()
self.items = defaultdict(dict)
@property
def describe(self):
def describe(self, base_key='TableDescription'):
results = {
'Table': {
base_key: {
'AttributeDefinitions': self.attr,
'ProvisionedThroughput': self.throughput,
'TableSizeBytes': 0,
@ -525,7 +524,6 @@ class DynamoDBBackend(BaseBackend):
for key in keys:
if key in table.hash_key_names:
return key, None
# import pdb; pdb.set_trace()
# for potential_hash, potential_range in zip(table.hash_key_names, table.range_key_names):
# if set([potential_hash, potential_range]) == set(keys):
# return potential_hash, potential_range

View File

@ -109,7 +109,7 @@ class DynamoHandler(BaseResponse):
global_indexes=global_indexes,
indexes=local_secondary_indexes)
if table is not None:
return dynamo_json_dump(table.describe)
return dynamo_json_dump(table.describe())
else:
er = 'com.amazonaws.dynamodb.v20111205#ResourceInUseException'
return self.error(er)
@ -118,7 +118,7 @@ class DynamoHandler(BaseResponse):
name = self.body['TableName']
table = dynamodb_backend2.delete_table(name)
if table is not None:
return dynamo_json_dump(table.describe)
return dynamo_json_dump(table.describe())
else:
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'
return self.error(er)
@ -130,7 +130,7 @@ class DynamoHandler(BaseResponse):
if 'ProvisionedThroughput' in self.body:
throughput = self.body["ProvisionedThroughput"]
table = dynamodb_backend2.update_table_throughput(name, throughput)
return dynamo_json_dump(table.describe)
return dynamo_json_dump(table.describe())
def describe_table(self):
name = self.body['TableName']
@ -139,7 +139,7 @@ class DynamoHandler(BaseResponse):
except KeyError:
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'
return self.error(er)
return dynamo_json_dump(table.describe)
return dynamo_json_dump(table.describe(base_key='Table'))
def put_item(self):
name = self.body['TableName']

View File

@ -1288,7 +1288,7 @@ def test_boto3_query_gsi_range_comparison():
@mock_dynamodb2
def test_update_table_throughput():
def test_boto3_update_table_throughput():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
# Create the DynamoDB table.
@ -1336,7 +1336,7 @@ def test_update_table_throughput():
@mock_dynamodb2
def test_update_table_gsi_throughput():
def test_boto3_update_table_gsi_throughput():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
# Create the DynamoDB table.

View File

@ -519,6 +519,31 @@ def test_conflicting_writes():
boto3
"""
@mock_dynamodb2
def test_boto3_create_table():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.create_table(
TableName='users',
KeySchema=[
{
'AttributeName': 'username',
'KeyType': 'HASH'
},
],
AttributeDefinitions=[
{
'AttributeName': 'username',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
)
table.name.should.equal('users')
def _create_user_table():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')