Skip to content

Commit

Permalink
create_table, bind_model signals #59
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Aug 12, 2016
1 parent ad95a0f commit ba23122
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bloop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .client import Client
from .column import Column
from .condition import Condition
from .engine import Engine
from .engine import Engine, before_bind_model, before_create_table
from .exceptions import (
AbstractModelException,
BloopException,
Expand Down Expand Up @@ -31,6 +31,6 @@
"AbstractModelException", "Boolean", "Binary", "BloopException", "Client", "Column", "Condition",
"ConstraintViolation", "DateTime", "Engine", "Float", "GlobalSecondaryIndex", "Integer", "List",
"LocalSecondaryIndex", "Map", "NotModified", "Set", "String", "TableMismatch", "TypedMap",
"UnboundModel", "UUID", "new_base"
"UnboundModel", "UUID", "before_bind_model", "before_create_table", "new_base"
]
__version__ = "0.9.12"
9 changes: 8 additions & 1 deletion bloop/engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import blinker
import declare

from .client import Client
Expand All @@ -10,7 +11,7 @@
from .util import walk_subclasses


__all__ = ["Engine"]
__all__ = ["Engine", "before_bind_model", "before_create_table"]

MISSING = object()
DEFAULT_CONFIG = {
Expand All @@ -19,6 +20,10 @@
"strict": True
}

# Signals!
before_bind_model = blinker.signal("before_bind_model")
before_create_table = blinker.signal("before_create_table")


def value_of(column):
"""value_of({'S': 'Space Invaders'}) -> 'Space Invaders'"""
Expand Down Expand Up @@ -129,6 +134,7 @@ def is_concrete(model):
# It also doesn't throw when the table already exists, making it safe
# to call multiple times for the same unbound model.
for model in unverified:
before_create_table.send(self, model=model)
self.client.create_table(model)

for model in concrete:
Expand All @@ -138,6 +144,7 @@ def is_concrete(model):
# next time its BaseModel is bound to an engine
verify_model(model)

before_bind_model.send(self, model=model)
self.type_engine.register(model)
for column in model.Meta.columns:
self.type_engine.register(column.typedef)
Expand Down
1 change: 1 addition & 0 deletions requirements-to-freeze.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
alabaster
arrow
blinker
boto3
coverage
declare
Expand Down
15 changes: 13 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
alabaster==0.7.9
arrow==0.8.0
Babel==2.3.4
blinker==1.4
boto3==1.4.0
botocore==1.4.43
botocore==1.4.46
coverage==4.2
declare==0.9.11
decorator==4.0.10
docutils==0.12
flake8==3.0.3
flake8==3.0.4
imagesize==0.7.1
ipython==5.0.0
ipython-genutils==0.1.0
Jinja2==2.8
jmespath==0.9.0
MarkupSafe==0.23
mccabe==0.5.2
pexpect==4.2.0
pickleshare==0.7.3
pluggy==0.3.1
prompt-toolkit==1.0.5
ptyprocess==0.5.1
py==1.4.31
pycodestyle==2.0.0
pyflakes==1.2.3
Expand All @@ -21,8 +29,11 @@ pytest==2.9.2
python-dateutil==2.5.3
pytz==2016.6.1
s3transfer==0.1.1
simplegeneric==0.8.1
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.4.5
tox==2.3.1
traitlets==4.2.2
virtualenv==15.0.3
wcwidth==0.1.7
2 changes: 1 addition & 1 deletion scripts/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TOX_COMMAND="tox -e $TOXENV --"

if [ "$TOXENV" = "integ" ]; then
TOX_COMMAND="$TOX_COMMAND --nonce=travis-$TRAVIS_BUILD_NUMBER-$TRAVIS_JOB_NUMBER"
TOX_COMMAND="$TOX_COMMAND --nonce=-travis-$TRAVIS_JOB_NUMBER"
fi

$TOX_COMMAND
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_version():

REQUIREMENTS = [
"arrow==0.8.0",
"blinker==1.4",
"boto3==1.4.0",
"declare==0.9.11"
]
Expand Down
16 changes: 12 additions & 4 deletions tests/integ/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import random
import string

from bloop import Client, Engine
from bloop import Client, Engine, before_create_table
boto_client = boto3.client("dynamodb", region_name="us-west-2")


def pytest_addoption(parser):
default_nonce = "local-" + "".join(random.choice(string.ascii_letters) for _ in range(16))
default_nonce = "-local-" + "".join(random.choice(string.ascii_letters) for _ in range(16))
parser.addoption(
"--nonce", action="store", default=default_nonce,
help="make table names unique for parallel runs")
Expand All @@ -36,6 +36,14 @@ def nonce(request):


@pytest.fixture
def engine():
def engine(nonce):
bloop_client = Client(boto_client=boto_client)
return Engine(client=bloop_client)
engine = Engine(client=bloop_client)

def nonce_table_name(sender, model, **kwargs):
table_name = model.Meta.table_name
if not table_name.endswith(nonce):
model.Meta.table_name += nonce

before_create_table.connect(nonce_table_name, weak=False)
return engine

0 comments on commit ba23122

Please sign in to comment.