From be5986c0b5b56cf0fc1955981394663b063fa834 Mon Sep 17 00:00:00 2001 From: Ilya Shmygol Date: Wed, 11 Dec 2019 15:08:45 +0100 Subject: [PATCH] Test query by non exists index --- tests/test_dynamodb2/test_dynamodb.py | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_dynamodb2/test_dynamodb.py b/tests/test_dynamodb2/test_dynamodb.py index 2b0833d98..da2b7c094 100644 --- a/tests/test_dynamodb2/test_dynamodb.py +++ b/tests/test_dynamodb2/test_dynamodb.py @@ -2630,6 +2630,43 @@ def test_scan_by_non_exists_index(): ) +@mock_dynamodb2 +def test_query_by_non_exists_index(): + dynamodb = boto3.client("dynamodb", region_name="us-east-1") + + dynamodb.create_table( + TableName="test", + KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}], + AttributeDefinitions=[ + {"AttributeName": "id", "AttributeType": "S"}, + {"AttributeName": "gsi_col", "AttributeType": "S"}, + ], + ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}, + GlobalSecondaryIndexes=[ + { + "IndexName": "test_gsi", + "KeySchema": [{"AttributeName": "gsi_col", "KeyType": "HASH"}], + "Projection": {"ProjectionType": "ALL"}, + "ProvisionedThroughput": { + "ReadCapacityUnits": 1, + "WriteCapacityUnits": 1, + }, + } + ], + ) + + with assert_raises(ValueError) as ex: + dynamodb.query( + TableName="test", + IndexName="non_exists_index", + KeyConditionExpression="CarModel=M", + ) + + str(ex.exception).should.equal( + "Invalid index: non_exists_index for table: test. Available indexes are: test_gsi" + ) + + @mock_dynamodb2 def test_batch_items_returns_all(): dynamodb = _create_user_table()