adding first error handling

This commit is contained in:
zmsmith 2013-03-10 15:46:27 -04:00
parent e9eb36e58c
commit 1cc0e0eac7
2 changed files with 16 additions and 1 deletions

View File

@ -21,6 +21,9 @@ class DynamoHandler(object):
if match:
return match.split(".")[1]
def error(self, type_, status=400):
return json.dumps({'__type': type_}), dict(status=400)
def dispatch(self):
method = self.get_method_name(self.headers)
if method:
@ -35,7 +38,11 @@ class DynamoHandler(object):
def DescribeTable(self, uri, body, headers):
name = json.loads(body)['TableName']
table = dynamodb_backend.tables[name]
try:
table = dynamodb_backend.tables[name]
except KeyError:
er = 'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'
return self.error(er)
return json.dumps(table.describe)

View File

@ -5,6 +5,8 @@ from freezegun import freeze_time
from moto import mock_dynamodb
from moto.dynamodb import dynamodb_backend
from boto.exception import DynamoDBResponseError
@mock_dynamodb
def test_list_tables():
@ -14,6 +16,12 @@ def test_list_tables():
assert conn.list_tables() == ['TestTable']
@mock_dynamodb
def test_describe_missing_table():
conn = boto.connect_dynamodb('the_key', 'the_secret')
conn.describe_table.when.called_with('messages').should.throw(DynamoDBResponseError)
@freeze_time("2012-01-14")
@mock_dynamodb
def test_describe_table():