Add dynamodb continuous backups (#2976)
* remove print statement * Add dynamodb.describe_continuous_backups * Add dynamodb.update_continuous_backups * Fix Python 2 timestamp error
This commit is contained in:
parent
9e7803dc36
commit
65e790c4eb
4 changed files with 198 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals, print_function
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import boto
|
||||
|
|
@ -2049,6 +2050,141 @@ def test_set_ttl():
|
|||
resp["TimeToLiveDescription"]["TimeToLiveStatus"].should.equal("DISABLED")
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_describe_continuous_backups():
|
||||
# given
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
table_name = client.create_table(
|
||||
TableName="test",
|
||||
AttributeDefinitions=[
|
||||
{"AttributeName": "client", "AttributeType": "S"},
|
||||
{"AttributeName": "app", "AttributeType": "S"},
|
||||
],
|
||||
KeySchema=[
|
||||
{"AttributeName": "client", "KeyType": "HASH"},
|
||||
{"AttributeName": "app", "KeyType": "RANGE"},
|
||||
],
|
||||
BillingMode="PAY_PER_REQUEST",
|
||||
)["TableDescription"]["TableName"]
|
||||
|
||||
# when
|
||||
response = client.describe_continuous_backups(TableName=table_name)
|
||||
|
||||
# then
|
||||
response["ContinuousBackupsDescription"].should.equal(
|
||||
{
|
||||
"ContinuousBackupsStatus": "ENABLED",
|
||||
"PointInTimeRecoveryDescription": {"PointInTimeRecoveryStatus": "DISABLED"},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_describe_continuous_backups_errors():
|
||||
# given
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
client.describe_continuous_backups(TableName="not-existing-table")
|
||||
|
||||
# then
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("DescribeContinuousBackups")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("TableNotFoundException")
|
||||
ex.response["Error"]["Message"].should.equal("Table not found: not-existing-table")
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_continuous_backups():
|
||||
# given
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
table_name = client.create_table(
|
||||
TableName="test",
|
||||
AttributeDefinitions=[
|
||||
{"AttributeName": "client", "AttributeType": "S"},
|
||||
{"AttributeName": "app", "AttributeType": "S"},
|
||||
],
|
||||
KeySchema=[
|
||||
{"AttributeName": "client", "KeyType": "HASH"},
|
||||
{"AttributeName": "app", "KeyType": "RANGE"},
|
||||
],
|
||||
BillingMode="PAY_PER_REQUEST",
|
||||
)["TableDescription"]["TableName"]
|
||||
|
||||
# when
|
||||
response = client.update_continuous_backups(
|
||||
TableName=table_name,
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True},
|
||||
)
|
||||
|
||||
# then
|
||||
response["ContinuousBackupsDescription"]["ContinuousBackupsStatus"].should.equal(
|
||||
"ENABLED"
|
||||
)
|
||||
point_in_time = response["ContinuousBackupsDescription"][
|
||||
"PointInTimeRecoveryDescription"
|
||||
]
|
||||
earliest_datetime = point_in_time["EarliestRestorableDateTime"]
|
||||
earliest_datetime.should.be.a(datetime)
|
||||
latest_datetime = point_in_time["LatestRestorableDateTime"]
|
||||
latest_datetime.should.be.a(datetime)
|
||||
point_in_time["PointInTimeRecoveryStatus"].should.equal("ENABLED")
|
||||
|
||||
# when
|
||||
# a second update should not change anything
|
||||
response = client.update_continuous_backups(
|
||||
TableName=table_name,
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True},
|
||||
)
|
||||
|
||||
# then
|
||||
response["ContinuousBackupsDescription"]["ContinuousBackupsStatus"].should.equal(
|
||||
"ENABLED"
|
||||
)
|
||||
point_in_time = response["ContinuousBackupsDescription"][
|
||||
"PointInTimeRecoveryDescription"
|
||||
]
|
||||
point_in_time["EarliestRestorableDateTime"].should.equal(earliest_datetime)
|
||||
point_in_time["LatestRestorableDateTime"].should.equal(latest_datetime)
|
||||
point_in_time["PointInTimeRecoveryStatus"].should.equal("ENABLED")
|
||||
|
||||
# when
|
||||
response = client.update_continuous_backups(
|
||||
TableName=table_name,
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": False},
|
||||
)
|
||||
|
||||
# then
|
||||
response["ContinuousBackupsDescription"].should.equal(
|
||||
{
|
||||
"ContinuousBackupsStatus": "ENABLED",
|
||||
"PointInTimeRecoveryDescription": {"PointInTimeRecoveryStatus": "DISABLED"},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_continuous_backups_errors():
|
||||
# given
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
client.update_continuous_backups(
|
||||
TableName="not-existing-table",
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True},
|
||||
)
|
||||
|
||||
# then
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("UpdateContinuousBackups")
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
ex.response["Error"]["Code"].should.contain("TableNotFoundException")
|
||||
ex.response["Error"]["Message"].should.equal("Table not found: not-existing-table")
|
||||
|
||||
|
||||
# https://github.com/spulec/moto/issues/1043
|
||||
@mock_dynamodb2
|
||||
def test_query_missing_expr_names():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue