Skip to content

Commit

Permalink
Merge pull request #48 from luqasz/master
Browse files Browse the repository at this point in the history
Do not hardcode boto3 settings
  • Loading branch information
fizyk committed Jul 17, 2017
2 parents 8a41152 + 7e60be6 commit 2aad151
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/pytest_dynamodb/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_config(request):
"""Return a dictionary with config options."""
config = {}
options = [
'dir', 'host', 'port', 'delay'
'dir', 'host', 'port', 'delay', 'aws_access_key',
'aws_secret_key', 'aws_region',
]
for option in options:
option_name = 'dynamodb_' + option
Expand Down Expand Up @@ -107,7 +108,7 @@ def dynamodb_proc_fixture(request):
),
host=dynamodb_host,
port=dynamodb_port,
timeout=60
timeout=60,
)
dynamodb_executor.start()
request.addfinalizer(dynamodb_executor.stop)
Expand All @@ -134,17 +135,17 @@ def dynamodb_factory(request):
:returns: connection to DynamoDB database
"""
proc_fixture = request.getfixturevalue(process_fixture_name)
config = get_config(request)

dynamo_db = boto3.resource(
'dynamodb',
endpoint_url='http://{host}:{port}'.format(
host=proc_fixture.host,
port=proc_fixture.port
),
# these args do not matter (we have to put something to them)
region_name='us-east-1',
aws_access_key_id='',
aws_secret_access_key='',
port=proc_fixture.port,
),
aws_access_key_id=config['aws_access_key'],
aws_secret_access_key=config['aws_secret_key'],
region_name=config['aws_region'],
)

# remove all tables
Expand Down
42 changes: 42 additions & 0 deletions src/pytest_dynamodb/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
_help_host = 'Host at which DynamoDB will accept connections'
_help_port = 'Port at which DynamoDB will accept connections'
_help_delay = "causes DynamoDB to introduce delays for certain operations"
_help_aws_secret_key = "AWS secret key."
_help_aws_access_key = "AWS access key."
_help_aws_region = "AWS region name."


def pytest_addoption(parser):
Expand Down Expand Up @@ -51,6 +54,45 @@ def pytest_addoption(parser):
default=False
)

parser.addini(
name='dynamodb_aws_secret_key',
help=_help_aws_secret_key,
default='secret_key',
)

parser.addoption(
'--dynamodb-aws_secret_key',
action='store',
dest='dynamodb_aws_secret_key',
help=_help_aws_secret_key,
)

parser.addini(
name='dynamodb_aws_access_key',
help=_help_aws_access_key,
default='access_key',
)

parser.addoption(
'--dynamodb-aws_access_key',
action='store',
dest='dynamodb_aws_access_key',
help=_help_aws_access_key,
)

parser.addini(
name='dynamodb_aws_region',
help=_help_aws_region,
default='us-west-1',
)

parser.addoption(
'--dynamodb-aws_region',
action='store',
dest='dynamodb_aws_region',
help=_help_aws_region,
)

parser.addoption(
'--dynamodb-dir',
action='store',
Expand Down

0 comments on commit 2aad151

Please sign in to comment.