Adding intitial DynamoDB setup and implementing ListTables target
This commit is contained in:
parent
7907585b65
commit
5086e6e590
@ -1,2 +1,3 @@
|
|||||||
|
from .dynamodb import mock_dynamodb
|
||||||
from .ec2 import mock_ec2
|
from .ec2 import mock_ec2
|
||||||
from .s3 import mock_s3
|
from .s3 import mock_s3
|
||||||
|
2
moto/dynamodb/__init__.py
Normal file
2
moto/dynamodb/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from .models import dynamodb_backend
|
||||||
|
mock_dynamodb = dynamodb_backend.decorator
|
11
moto/dynamodb/models.py
Normal file
11
moto/dynamodb/models.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from moto.core import BaseBackend
|
||||||
|
|
||||||
|
class DynamoDBBackend(BaseBackend):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.tables = {}
|
||||||
|
|
||||||
|
def create_table(self, name):
|
||||||
|
self.tables[name] = None
|
||||||
|
|
||||||
|
dynamodb_backend = DynamoDBBackend()
|
32
moto/dynamodb/responses.py
Normal file
32
moto/dynamodb/responses.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import re
|
||||||
|
import json
|
||||||
|
from .models import dynamodb_backend
|
||||||
|
|
||||||
|
class DynamoHandler(object):
|
||||||
|
|
||||||
|
def __init__(self, uri, body, headers):
|
||||||
|
self.uri = uri
|
||||||
|
self.body = body
|
||||||
|
self.headers = headers
|
||||||
|
|
||||||
|
def get_method_name(self, headers):
|
||||||
|
"""Parses request headers and extracts part od the X-Amz-Target
|
||||||
|
that corresponds to a method of DynamoHandler
|
||||||
|
|
||||||
|
ie: X-Amz-Target: DynamoDB_20111205.ListTables -> ListTables
|
||||||
|
"""
|
||||||
|
match = re.search(r'X-Amz-Target: \w+\.(\w+)', headers)
|
||||||
|
return match.groups()[0]
|
||||||
|
|
||||||
|
def dispatch(self):
|
||||||
|
method = self.get_method_name(self.headers)
|
||||||
|
return getattr(self, method)(self.uri, self.body, self.headers)
|
||||||
|
|
||||||
|
def ListTables(self, uri, body, headers):
|
||||||
|
tables = dynamodb_backend.tables.keys()
|
||||||
|
response = {"TableNames": tables}
|
||||||
|
return json.dumps(response)
|
||||||
|
|
||||||
|
|
||||||
|
def handler(uri, body, headers):
|
||||||
|
return DynamoHandler(uri, body, headers).dispatch()
|
5
moto/dynamodb/urls.py
Normal file
5
moto/dynamodb/urls.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .responses import handler
|
||||||
|
|
||||||
|
urls = {
|
||||||
|
"https://dynamodb.us-east-1.amazonaws.com/": handler,
|
||||||
|
}
|
12
tests/test_dynamodb/test_dynamodb.py
Normal file
12
tests/test_dynamodb/test_dynamodb.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import boto
|
||||||
|
|
||||||
|
from moto import mock_dynamodb
|
||||||
|
from moto.dynamodb import dynamodb_backend
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb
|
||||||
|
def test_create_table():
|
||||||
|
name = "TestTable"
|
||||||
|
dynamodb_backend.create_table(name)
|
||||||
|
conn = boto.connect_dynamodb('the_key', 'the_secret')
|
||||||
|
assert conn.list_tables() == ['TestTable']
|
Loading…
Reference in New Issue
Block a user