Skip to content

Commit

Permalink
Clean up auto-noncing in integ tests #52
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Aug 12, 2016
1 parent ba23122 commit 5c39df0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
25 changes: 14 additions & 11 deletions tests/integ/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import blinker
import boto3
import itertools
import pytest
Expand All @@ -15,6 +16,16 @@ def pytest_addoption(parser):
help="make table names unique for parallel runs")


def pytest_configure(config):
nonce = config.getoption("--nonce")

@before_create_table.connect_via(sender=blinker.ANY, weak=False)
def nonce_table_name(_, model, **__):
table_name = model.Meta.table_name
if not table_name.endswith(nonce):
model.Meta.table_name += nonce


def pytest_unconfigure(config):
it = boto_client.get_paginator("list_tables").paginate()
tables = [response["TableNames"] for response in it]
Expand All @@ -30,20 +41,12 @@ def pytest_unconfigure(config):
print("Failed to clean up table '{}'".format(table))


@pytest.fixture
@pytest.fixture(scope="session")
def nonce(request):
return request.config.getoption("--nonce")


@pytest.fixture
def engine(nonce):
def engine():
bloop_client = Client(boto_client=boto_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
return Engine(client=bloop_client)
31 changes: 27 additions & 4 deletions tests/integ/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
"""Basic scenarios, symmetric tests"""
from bloop import new_base, Column, Integer
import pytest
from bloop import String
from bloop import new_base, Column, Integer, NotModified


def test_crud(engine):
class User(new_base()):
id = Column(Integer, hash_key=True)
class User(new_base()):
id = Column(Integer, hash_key=True)
name = Column(String)


def test_crud(engine):
engine.bind(User)

user = User(id=0, name="first")
engine.save(user)

same_user = User(id=user.id)
engine.load(same_user)
assert user.name == same_user.name

same_user.name = "second"
engine.save(same_user)

engine.load(user)
assert user.name == same_user.name

engine.delete(user)

with pytest.raises(NotModified) as excinfo:
engine.load(same_user)
assert same_user in excinfo.value.objects

0 comments on commit 5c39df0

Please sign in to comment.