Пример #1
0
def test_returned_transaction_uses_connection_from_pool():
    pool, conn = Mock(), Mock()
    pool.getconn.return_value = conn
    tree = Tree(pool=pool)
    transaction = tree.make_transaction()
    assert transaction.connection is conn
Пример #2
0
def test_make_transaction_returns_a_transaction_object():
    conn = Mock()
    tree = Tree(connection=conn)
    transaction = tree.make_transaction()
    assert transaction.__class__ == Transaction
Пример #3
0
def test_returned_transaction_uses_assigned_transaction_object():
    conn = Mock()
    tree = Tree(connection=conn)
    transaction = tree.make_transaction()
    assert transaction.connection is conn
Пример #4
0
def test_make_transaction_returns_a_transaction_object():
    conn = Mock()
    tree = Tree(connection=conn)
    transaction = tree.make_transaction()
    assert transaction.__class__ == Transaction
Пример #5
0
def test_returned_transaction_uses_assigned_transaction_object():
    conn = Mock()
    tree = Tree(connection=conn)
    transaction = tree.make_transaction()
    assert transaction.connection is conn
Пример #6
0
def test_it_requires_either_connection_or_pool():
    with pytest.raises(TypeError):
        Tree()
Пример #7
0
def test_it_cant_deal_with_both_connection_and_pool():
    with pytest.raises(TypeError):
        Tree(connection=Mock(), pool=Mock())
Пример #8
0
def test_close_connection():
    conn = Mock()
    Tree(connection=conn).close()
    assert conn.close.called
Пример #9
0
def test_it_takes_a_connection_pool(dsn):
    pool = Mock()
    assert Tree(pool=pool).pool is pool
Пример #10
0
def test_it_takes_a_connection():
    conn = Mock()
    assert Tree(connection=conn).connection is conn
Пример #11
0
def test_cm_commits_transaction():
    conn = Mock()
    tree = Tree(connection=conn)
    with tree() as transaction:  # noqa
        pass
    assert conn.commit.called
Пример #12
0
def test_returned_transaction_uses_connection_from_pool():
    pool, conn = Mock(), Mock()
    pool.getconn.return_value = conn
    tree = Tree(pool=pool)
    transaction = tree.make_transaction()
    assert transaction.connection is conn
Пример #13
0
def test_make_transaction_returns_a_read_write_transaction_object():
    conn = Mock()
    tree = Tree(connection=conn)
    transaction = tree.make_transaction(write=True)
    assert transaction.__class__ == ReadWriteTransaction
Пример #14
0
def test_get_connection_returns_connection_from_pool():
    pool, conn = Mock(), Mock()
    pool.getconn.return_value = conn
    tree = Tree(pool=pool)
    assert tree.get_connection() is conn
    assert pool.getconn.called
Пример #15
0
def test_get_connection_returns_the_assigned_one():
    conn = Mock()
    tree = Tree(connection=conn)
    assert tree.get_connection() is conn
Пример #16
0
def test_close_pool():
    pool = Mock()
    Tree(pool=pool).close()
    assert pool.closeall.called