コード例 #1
0
def test_bind_concrete_base():
    engine = bloop.Engine()
    engine.client = Mock(spec=bloop.client.Client)

    class Concrete(bloop.new_base()):
        pass

    engine.bind(base=Concrete)
    engine.client.create_table.assert_called_once_with(Concrete)
    engine.client.validate_table.assert_called_once_with(Concrete)
コード例 #2
0
def test_unbound_engine_view():
    """Trying to mutate an unbound model through an EngineView fails"""
    class UnboundModel(bloop.new_base()):
        id = bloop.Column(bloop.String, hash_key=True)

    instance = UnboundModel(id="foo")

    with pytest.raises(bloop.exceptions.UnboundModel):
        with bloop.Engine().context() as view:
            view._dump(UnboundModel, instance)
コード例 #3
0
def test_bind_different_engines():
    first_engine = bloop.Engine()
    first_engine.client = Mock(spec=bloop.client.Client)
    second_engine = bloop.Engine()
    second_engine.client = Mock(spec=bloop.client.Client)

    class Concrete(bloop.new_base()):
        pass

    first_engine.bind(base=Concrete)
    second_engine.bind(base=Concrete)

    # Create/Validate are only called once per model, regardless of how many
    # times the model is bound to different engines
    first_engine.client.create_table.assert_called_once_with(Concrete)
    first_engine.client.validate_table.assert_called_once_with(Concrete)
    second_engine.client.create_table.assert_not_called()
    second_engine.client.validate_table.assert_not_called()

    # The model (and its columns) are bound to each engine's TypeEngine,
    # regardless of how many times the model has been bound already
    assert Concrete in first_engine.type_engine.bound_types
    assert Concrete in second_engine.type_engine.bound_types
コード例 #4
0
def test_bind_skip_abstract_models():
    class Abstract(bloop.new_base()):
        class Meta:
            abstract = True

    class Concrete(Abstract):
        pass

    class AlsoAbstract(Concrete):
        class Meta:
            abstract = True

    class AlsoConcrete(AlsoAbstract):
        pass

    engine = bloop.Engine()
    engine.client = Mock(spec=bloop.client.Client)

    engine.bind(base=Abstract)
    engine.client.create_table.assert_any_call(Concrete)
    engine.client.validate_table.assert_any_call(Concrete)
    engine.client.create_table.assert_any_call(AlsoConcrete)
    engine.client.validate_table.assert_any_call(AlsoConcrete)
コード例 #5
0
def engine():
    engine = bloop.Engine()
    engine.client = Mock(spec=bloop.client.Client)
    engine.bind(base=BaseModel)
    return engine
コード例 #6
0
def build_engine(profile_name) -> bloop.Engine:
    session = boto3.Session(profile_name=profile_name)
    dynamodb = session.client("dynamodb")
    dynamodbstreams = session.client("dynamodbstreams")
    engine = bloop.Engine(dynamodb=dynamodb, dynamodbstreams=dynamodbstreams)
    return engine
コード例 #7
0
def test_bind_non_model():
    """Can't bind things that don't subclass new_base()"""
    engine = bloop.Engine()
    engine.client = Mock(spec=bloop.client.Client)
    with pytest.raises(ValueError):
        engine.bind(base=object())