Skip to content

Commit

Permalink
Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravr committed Feb 18, 2025
1 parent 7a6d23b commit 9cc2267
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/test_piccolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from piccolo import columns as col
from piccolo.engine.postgres import PostgresEngine
import pytest

import settings
from apphelpers.db.piccolo import (
BaseTable,
dbtransaction_ctx,
dbtransaction,
destroy_db_from_basetable,
setup_db_from_basetable,
)
Expand All @@ -19,6 +20,7 @@
password=settings.DB_PASS,
)
)
dbtransaction_wrapper = dbtransaction(db)


class Book(BaseTable, db=db):
Expand All @@ -43,25 +45,22 @@ def teardown_module():


async def add_with_tr():
async with dbtransaction_ctx(db):
name = "The Pillars of the Earth"
await _add_book(name)
add_book = dbtransaction_wrapper(_add_book)
name = "The Pillars of the Earth"
await add_book(name)
names = [b[Book.name] for b in await Book.select().run()]
assert name in names

try:
async with dbtransaction_ctx(db):
name = "The Cathedral and the Bazaar"
await _add_book_loser(name)
except NameError:
pass

add_book_loser = dbtransaction_wrapper(_add_book_loser)
name = "The Cathedral and the Bazaar"
with pytest.raises(NameError):
await add_book_loser(name)
names = [b[Book.name] for b in await Book.select().run()]
assert name not in names

async with dbtransaction_ctx(db):
name = "The Ego Trick"
await _add_book(name)
add_book = dbtransaction_wrapper(_add_book)
name = "The Ego Trick"
await add_book(name)
names = [b[Book.name] for b in await Book.select().run()]
assert name in names

Expand Down

0 comments on commit 9cc2267

Please sign in to comment.