How do I use ddbmock with dynamodb-mapper?
Can someone explain how to set up dynamodb_mapper (along with boto ?) To use ddbmock with sqlite backend like Amazon DynamoDB - replacement for functional testing?
Right now, I tried out a "simple" boto and was able to get it to work with ddbmock (with sqlite) by running a local ddbmock server and connecting with boto:
db = connect_boto_network(host='127.0.0.1', port=6543)
.. and then I use the db object for all my database operations. However dynamodb_mapper uses this way to get the db connection:
conn = ConnectionBorg()
As I understand it, it uses the boto default method to communicate with the (real) DynamoDB. So basically I'm wondering if there is a way (preferred?) To connect ConnectionBorg () to my local ddbmock server like I did with boto above? Thanks for any suggestions.
source to share
Library mode
In library mode, not server mode:
import boto
from ddbmock import config
from ddbmock import connect_boto_patch
# switch to sqlite backend
config.STORAGE_ENGINE_NAME = 'sqlite'
# define the database path. defaults to 'dynamo.db'
config.STORAGE_SQLITE_FILE = '/tmp/my_database.sqlite'
# Wire-up boto and ddbmock together
db = connect_boto_patch()
Anyone accessing dynamodb service via boto will use ddbmock under the hood.
Server Mode
If you still want to use ddbmock in server mode, I'll try to change ConnectionBorg._shared_state['_region']
at the very beginning of the test setup code:
ConnectionBorg._shared_state['_region'] = RegionInfo(name='ddbmock', endpoint="localhost:6543")
As far as I understand, any dynamodb access via any instance ConnectionBorg
following these lines will use the ddbmock entry point.
This suggests that I have never tested it. I make sure the ddbmock authors give an update on this.
source to share