From a5eaaaad51b2f2dd1ec5997249c5296010920ab0 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 15 Mar 2013 17:14:14 -0400 Subject: [PATCH] fix for scanning without filter --- moto/dynamodb/responses.py | 2 +- .../test_dynamodb_table_with_range_key.py | 17 ++++++++++------- .../test_dynamodb_table_without_range_key.py | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/moto/dynamodb/responses.py b/moto/dynamodb/responses.py index 77c2d0484..8be7d88ee 100644 --- a/moto/dynamodb/responses.py +++ b/moto/dynamodb/responses.py @@ -244,7 +244,7 @@ class DynamoHandler(object): name = body['TableName'] filters = {} - scan_filters = body['ScanFilter'] + scan_filters = body.get('ScanFilter', {}) for attribute_name, scan_filter in scan_filters.iteritems(): # Keys are attribute names. Values are tuples of (comparison, comparison_value) comparison_operator = scan_filter["ComparisonOperator"] diff --git a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py index b4516e7a8..bff2be93b 100644 --- a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py @@ -135,7 +135,7 @@ def test_item_put_without_table(): conn.layer1.put_item.when.called_with( table_name='undeclared-table', - item =dict( + item=dict( hash_key='LOLCat Forum', range_key='Check this out!', ), @@ -302,10 +302,10 @@ def test_query_with_undeclared_table(): table_name='undeclared-table', hash_key_value={'S': 'the-key'}, range_key_conditions={ - "AttributeValueList":[{ - "S":"User B" + "AttributeValueList": [{ + "S": "User B" }], - "ComparisonOperator":"EQ", + "ComparisonOperator": "EQ", }, ).should.throw(DynamoDBResponseError) @@ -348,6 +348,9 @@ def test_scan(): ) item.put() + results = table.scan() + results.response['Items'].should.have.length_of(3) + results = table.scan(scan_filter={'SentBy': condition.EQ('User B')}) results.response['Items'].should.have.length_of(1) @@ -378,10 +381,10 @@ def test_scan_with_undeclared_table(): table_name='undeclared-table', scan_filter={ "SentBy": { - "AttributeValueList":[{ - "S":"User B"} + "AttributeValueList": [{ + "S": "User B"} ], - "ComparisonOperator":"EQ" + "ComparisonOperator": "EQ" } }, ).should.throw(DynamoDBResponseError) diff --git a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py index 4222e3c18..c1ffdf2ce 100644 --- a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py @@ -291,6 +291,9 @@ def test_scan(): ) item.put() + results = table.scan() + results.response['Items'].should.have.length_of(3) + results = table.scan(scan_filter={'SentBy': condition.EQ('User B')}) results.response['Items'].should.have.length_of(1)