diff --git a/moto/dynamodb/responses.py b/moto/dynamodb/responses.py index 7fac386a7..add8fd5d6 100644 --- a/moto/dynamodb/responses.py +++ b/moto/dynamodb/responses.py @@ -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) diff --git a/tests/test_dynamodb/test_dynamodb.py b/tests/test_dynamodb/test_dynamodb.py index df31c2f3d..a5df4a0ad 100644 --- a/tests/test_dynamodb/test_dynamodb.py +++ b/tests/test_dynamodb/test_dynamodb.py @@ -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():