Merge #913.
This commit is contained in:
parent
408a70992c
commit
0adebeed24
36 changed files with 669 additions and 58 deletions
|
|
@ -2,11 +2,13 @@ from __future__ import unicode_literals, print_function
|
|||
|
||||
import six
|
||||
import boto
|
||||
import boto3
|
||||
import sure # noqa
|
||||
import requests
|
||||
from moto import mock_dynamodb2, mock_dynamodb2_deprecated
|
||||
from moto.dynamodb2 import dynamodb_backend2
|
||||
from boto.exception import JSONResponseError
|
||||
from botocore.exceptions import ClientError
|
||||
from tests.helpers import requires_boto_gte
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
|
|
@ -64,3 +66,86 @@ def test_describe_missing_table():
|
|||
aws_secret_access_key="sk")
|
||||
with assert_raises(JSONResponseError):
|
||||
conn.describe_table('messages')
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_list_table_tags():
|
||||
name = 'TestTable'
|
||||
conn = boto3.client('dynamodb',
|
||||
region_name='us-west-2',
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk")
|
||||
conn.create_table(TableName=name,
|
||||
KeySchema=[{'AttributeName':'id','KeyType':'HASH'}],
|
||||
AttributeDefinitions=[{'AttributeName':'id','AttributeType':'S'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits':5,'WriteCapacityUnits':5})
|
||||
table_description = conn.describe_table(TableName=name)
|
||||
arn = table_description['Table']['TableArn']
|
||||
tags = [{'Key':'TestTag', 'Value': 'TestValue'}]
|
||||
conn.tag_resource(ResourceArn=arn,
|
||||
Tags=tags)
|
||||
resp = conn.list_tags_of_resource(ResourceArn=arn)
|
||||
assert resp["Tags"] == tags
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_list_table_tags_empty():
|
||||
name = 'TestTable'
|
||||
conn = boto3.client('dynamodb',
|
||||
region_name='us-west-2',
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk")
|
||||
conn.create_table(TableName=name,
|
||||
KeySchema=[{'AttributeName':'id','KeyType':'HASH'}],
|
||||
AttributeDefinitions=[{'AttributeName':'id','AttributeType':'S'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits':5,'WriteCapacityUnits':5})
|
||||
table_description = conn.describe_table(TableName=name)
|
||||
arn = table_description['Table']['TableArn']
|
||||
tags = [{'Key':'TestTag', 'Value': 'TestValue'}]
|
||||
# conn.tag_resource(ResourceArn=arn,
|
||||
# Tags=tags)
|
||||
resp = conn.list_tags_of_resource(ResourceArn=arn)
|
||||
assert resp["Tags"] == []
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_list_table_tags_paginated():
|
||||
name = 'TestTable'
|
||||
conn = boto3.client('dynamodb',
|
||||
region_name='us-west-2',
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk")
|
||||
conn.create_table(TableName=name,
|
||||
KeySchema=[{'AttributeName':'id','KeyType':'HASH'}],
|
||||
AttributeDefinitions=[{'AttributeName':'id','AttributeType':'S'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits':5,'WriteCapacityUnits':5})
|
||||
table_description = conn.describe_table(TableName=name)
|
||||
arn = table_description['Table']['TableArn']
|
||||
for i in range(11):
|
||||
tags = [{'Key':'TestTag%d' % i, 'Value': 'TestValue'}]
|
||||
conn.tag_resource(ResourceArn=arn,
|
||||
Tags=tags)
|
||||
resp = conn.list_tags_of_resource(ResourceArn=arn)
|
||||
assert len(resp["Tags"]) == 10
|
||||
assert 'NextToken' in resp.keys()
|
||||
resp2 = conn.list_tags_of_resource(ResourceArn=arn,
|
||||
NextToken=resp['NextToken'])
|
||||
assert len(resp2["Tags"]) == 1
|
||||
assert 'NextToken' not in resp2.keys()
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_list_not_found_table_tags():
|
||||
conn = boto3.client('dynamodb',
|
||||
region_name='us-west-2',
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk")
|
||||
arn = 'DymmyArn'
|
||||
try:
|
||||
conn.list_tags_of_resource(ResourceArn=arn)
|
||||
except ClientError as exception:
|
||||
assert exception.response['Error']['Code'] == "ResourceNotFoundException"
|
||||
|
|
|
|||
|
|
@ -77,13 +77,14 @@ def test_create_table():
|
|||
'TableSizeBytes': 0,
|
||||
'TableName': 'messages',
|
||||
'TableStatus': 'ACTIVE',
|
||||
'TableArn': 'arn:aws:dynamodb:us-east-1:123456789011:table/messages',
|
||||
'KeySchema': [
|
||||
{'KeyType': 'HASH', 'AttributeName': 'forum_name'},
|
||||
{'KeyType': 'RANGE', 'AttributeName': 'subject'}
|
||||
],
|
||||
'LocalSecondaryIndexes': [],
|
||||
'ItemCount': 0, 'CreationDateTime': 1326499200.0,
|
||||
'GlobalSecondaryIndexes': [],
|
||||
'GlobalSecondaryIndexes': []
|
||||
}
|
||||
}
|
||||
table.describe().should.equal(expected)
|
||||
|
|
@ -109,6 +110,7 @@ def test_create_table_with_local_index():
|
|||
'TableSizeBytes': 0,
|
||||
'TableName': 'messages',
|
||||
'TableStatus': 'ACTIVE',
|
||||
'TableArn': 'arn:aws:dynamodb:us-east-1:123456789011:table/messages',
|
||||
'KeySchema': [
|
||||
{'KeyType': 'HASH', 'AttributeName': 'forum_name'},
|
||||
{'KeyType': 'RANGE', 'AttributeName': 'subject'}
|
||||
|
|
@ -125,7 +127,7 @@ def test_create_table_with_local_index():
|
|||
],
|
||||
'ItemCount': 0,
|
||||
'CreationDateTime': 1326499200.0,
|
||||
'GlobalSecondaryIndexes': [],
|
||||
'GlobalSecondaryIndexes': []
|
||||
}
|
||||
}
|
||||
table.describe().should.equal(expected)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ def test_create_table():
|
|||
'TableSizeBytes': 0,
|
||||
'TableName': 'messages',
|
||||
'TableStatus': 'ACTIVE',
|
||||
'TableArn': 'arn:aws:dynamodb:us-east-1:123456789011:table/messages',
|
||||
'KeySchema': [
|
||||
{'KeyType': 'HASH', 'AttributeName': 'forum_name'}
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue