Skip to content
This repository has been archived by the owner on Sep 18, 2018. It is now read-only.

Commit

Permalink
Fixes from cr
Browse files Browse the repository at this point in the history
  • Loading branch information
tomislater committed Jun 18, 2016
1 parent 27f001d commit ff180ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 73 deletions.
3 changes: 1 addition & 2 deletions docs/howtouse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ How to install DynamoDB locally: http://docs.aws.amazon.com/amazondynamodb/lates
.. code-block:: python
dynamodb_proc = factories.dynamodb_proc(
jar_path='/path/to/dynamodb/DynamoDBLocal.jar',
port=8000 # default port
jar_path='/path/to/dynamodb/DynamoDBLocal.jar'
)
dynamodb = factories.dynamodb('dynamodb_proc')
Expand Down
17 changes: 13 additions & 4 deletions src/pytest_dbfixtures/factories/dynamodb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 by Clearcode <http://clearcode.cc>
# Copyright (C) 2016 by Clearcode <http://clearcode.cc>
# and associates (see AUTHORS).

# This file is part of pytest-dbfixtures.
Expand All @@ -22,16 +22,24 @@
from pytest_dbfixtures.utils import try_import, get_process_fixture


def dynamodb_proc(jar_path=None, host='localhost', port=8000):
class JarPathException(Exception):
pass


def dynamodb_proc(jar_path=None, host='localhost', port='?'):
"""
DynamoDB process factory.
:param str jar_path: path to jar file
:param str jar_path: a path to jar file. A path cannot contain spaces
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html?shortFooter=true
:param str host: hostname
:param int port: port
:return: function which makes a DynamoDB process
"""
if not jar_path:
raise JarPathException('You have to provide a path to the jar file.')

@pytest.fixture(scope='session')
def dynamodb_proc_fixture(request):
"""
Expand Down Expand Up @@ -77,7 +85,8 @@ def dynamodb_factory(request):
Connect to the local DynamoDB.
:param FixtureRequest request: fixture request object
:rtype: Subclass of :py:class:`~boto3.resources.base.ServiceResource`
:rtype: :py:class:`~botocore.client.DynamoDB`
https://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html#DynamoDB.Client
:returns: connection to DynamoDB database
"""
proc_fixture = get_process_fixture(request, process_fixture_name)
Expand Down
79 changes: 12 additions & 67 deletions tests/test_dynamodb.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import uuid
import pytest

from pytest_dbfixtures import factories
from pytest_dbfixtures.factories.dynamodb import JarPathException

dynamodb_proc = factories.dynamodb_proc(
jar_path='/tmp/dynamodb/DynamoDBLocal.jar'
)
dynamodb = factories.dynamodb('dynamodb_proc')

dynamodb_proc_random_port = factories.dynamodb_proc(
jar_path='/tmp/dynamodb/DynamoDBLocal.jar',
port='?',
)
dynamodb_random_port = factories.dynamodb('dynamodb_proc_random_port')


def test_dynamodb(dynamodb):
"""
Expand All @@ -27,21 +25,13 @@ def test_dynamodb(dynamodb):
{
'AttributeName': 'id',
'KeyType': 'HASH'
},
{
'AttributeName': 'data',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'id',
'AttributeType': 'N'
},
{
'AttributeName': 'data',
'AttributeType': 'S'
},
}

],
ProvisionedThroughput={
Expand All @@ -50,76 +40,31 @@ def test_dynamodb(dynamodb):
}
)

_id = 89734943
data = "test1 test2 test3"
_id = str(uuid.uuid4())

# put an item into db
table.put_item(
Item={
'id': _id,
'data': data,
'test_key': 'test_value'
}
},
)

# get the item
item = table.get_item(
Key={
'id': _id,
'data': data,
}
)

# check the content of the item
assert item['Item']['test_key'] == 'test_value'


def test_dynamodb_random_port(dynamodb_random_port):
def test_dynamodb_raise():
"""
Test random port for DynamoDB.
# Create a table
# Put an item
# Get the item and check the content of this item
We want to inform a user that he has to provide a path to the jar file.
"""
# create a table
table = dynamodb_random_port.create_table(
TableName='Test',
KeySchema=[
{
'AttributeName': 'id',
'KeyType': 'HASH'
}
],
AttributeDefinitions=[
{
'AttributeName': 'id',
'AttributeType': 'N'
}

],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)

_id = 1111111

# put an item into db
table.put_item(
Item={
'id': _id,
'test_key': 'test_value'
}
)

# get the item
item = table.get_item(
Key={
'id': _id,
}
)

# check the content of the item
assert item['Item']['test_key'] == 'test_value'
with pytest.raises(JarPathException) as excinfo:
factories.dynamodb_proc()
assert 'You have to provide a path to the jar file.' == str(excinfo)

0 comments on commit ff180ec

Please sign in to comment.