Fix dynamo item not found.

This commit is contained in:
Steve Pulec 2015-07-13 10:33:36 -04:00 committed by Andrew Harris
parent bbb021d06d
commit 75461cb110
3 changed files with 11 additions and 3 deletions

View File

@ -381,6 +381,7 @@ class DynamoDBBackend(BaseBackend):
def get_item(self, table_name, keys): def get_item(self, table_name, keys):
table = self.get_table(table_name) table = self.get_table(table_name)
if not table: if not table:
raise ValueError()
return None return None
hash_key, range_key = self.get_keys_value(table, keys) hash_key, range_key = self.get_keys_value(table, keys)
return table.get_item(hash_key, range_key) return table.get_item(hash_key, range_key)

View File

@ -196,8 +196,8 @@ class DynamoHandler(BaseResponse):
return dynamo_json_dump(item_dict) return dynamo_json_dump(item_dict)
else: else:
# Item not found # Item not found
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException' er = '{}'
return self.error(er, status=404) return self.error(er, status=200)
def batch_get_item(self): def batch_get_item(self):
table_batches = self.body['RequestItems'] table_batches = self.body['RequestItems']

View File

@ -10,7 +10,7 @@ try:
from boto.dynamodb2.fields import HashKey from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.table import Table from boto.dynamodb2.table import Table
from boto.dynamodb2.table import Item from boto.dynamodb2.table import Item
from boto.dynamodb2.exceptions import ConditionalCheckFailedException from boto.dynamodb2.exceptions import ConditionalCheckFailedException, ItemNotFound
except ImportError: except ImportError:
pass pass
@ -369,6 +369,13 @@ def test_get_key_fields():
kf[0].should.equal('forum_name') kf[0].should.equal('forum_name')
@requires_boto_gte("2.9")
@mock_dynamodb2
def test_get_missing_item():
table = create_table()
table.get_item.when.called_with(forum_name='missing').should.throw(ItemNotFound)
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@mock_dynamodb2 @mock_dynamodb2
def test_get_special_item(): def test_get_special_item():