def test_create_complex(): expected = { 'AttributeDefinitions': [ {'AttributeType': 'S', 'AttributeName': 'date'}, {'AttributeType': 'S', 'AttributeName': 'email'}, {'AttributeType': 'S', 'AttributeName': 'joined'}, {'AttributeType': 'S', 'AttributeName': 'name'}], 'GlobalSecondaryIndexes': [{ 'IndexName': 'by_email', 'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'email'}], 'Projection': {'ProjectionType': 'ALL'}, 'ProvisionedThroughput': { 'ReadCapacityUnits': 4, 'WriteCapacityUnits': 5}}], 'KeySchema': [{'KeyType': 'HASH', 'AttributeName': 'name'}, {'KeyType': 'RANGE', 'AttributeName': 'date'}], 'LocalSecondaryIndexes': [{ 'IndexName': 'by_joined', 'KeySchema': [ {'KeyType': 'HASH', 'AttributeName': 'name'}, {'KeyType': 'RANGE', 'AttributeName': 'joined'}], 'Projection': { 'NonKeyAttributes': ['joined', 'email', 'date', 'name'], 'ProjectionType': 'INCLUDE'}}], 'ProvisionedThroughput': { 'ReadCapacityUnits': 3, 'WriteCapacityUnits': 2}, 'TableName': 'CustomTableName'} assert_unordered(create_table_request(ComplexModel), expected)
def test_create_table_no_stream(): """No StreamSpecification if Model.Meta.stream is None""" class Model(BaseModel): class Meta: stream = None id = Column(String, hash_key=True) table = create_table_request(Model) assert "StreamSpecification" not in table
def test_create_simple(): expected = { 'AttributeDefinitions': [ {'AttributeName': 'id', 'AttributeType': 'S'}], 'KeySchema': [{'AttributeName': 'id', 'KeyType': 'HASH'}], 'ProvisionedThroughput': { 'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1}, 'TableName': 'Simple'} assert_unordered(create_table_request(SimpleModel), expected)
def test_create_table_with_stream(include, view_type): """A table that streams only new images""" class Model(BaseModel): class Meta: stream = {"include": include} id = Column(String, hash_key=True) table = create_table_request(Model) assert table["StreamSpecification"] == { "StreamEnabled": True, "StreamViewType": view_type }
def test_expected_description(): # Eventually expected_table_description will probably diverge from create_table # This will guard against (or coverage should show) if there's drift create = create_table_request(ComplexModel) expected = expected_table_description(ComplexModel) assert_unordered(create, expected)