Skip to content

Commit

Permalink
chore: rewrite tests for not using manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed May 18, 2024
1 parent aaaccf9 commit 62b582e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 43 deletions.
14 changes: 7 additions & 7 deletions tests/aio_model/test_deleting.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import uuid

from tests.conftest import postgres_only, manager_for_all_dbs
from tests.conftest import dbs_all, dbs_postgres
from tests.models import TestModel
from tests.utils import model_has_fields


@manager_for_all_dbs
async def test_delete__count(manager):
@dbs_all
async def test_delete__count(db):
query = TestModel.insert_many([
{'text': "Test %s" % uuid.uuid4()},
{'text': "Test %s" % uuid.uuid4()},
Expand All @@ -18,8 +18,8 @@ async def test_delete__count(manager):
assert count == 2


@manager_for_all_dbs
async def test_delete__by_condition(manager):
@dbs_all
async def test_delete__by_condition(db):
expected_text = "text1"
deleted_text = "text2"
query = TestModel.insert_many([
Expand All @@ -35,8 +35,8 @@ async def test_delete__by_condition(manager):
assert res[0].text == expected_text


@postgres_only
async def test_delete__return_model(manager):
@dbs_postgres
async def test_delete__return_model(db):
m = await TestModel.aio_create(text="text", data="data")

res = await TestModel.delete().returning(TestModel).aio_execute()
Expand Down
34 changes: 17 additions & 17 deletions tests/aio_model/test_inserting.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import uuid

from tests.conftest import postgres_only, manager_for_all_dbs
from tests.conftest import dbs_all, dbs_postgres
from tests.models import TestModel, UUIDTestModel
from tests.utils import model_has_fields


@manager_for_all_dbs
async def test_insert_many(manager):
@dbs_all
async def test_insert_many(db):
last_id = await TestModel.insert_many([
{'text': "Test %s" % uuid.uuid4()},
{'text': "Test %s" % uuid.uuid4()},
Expand All @@ -18,17 +18,17 @@ async def test_insert_many(manager):
assert last_id in [m.id for m in res]


@manager_for_all_dbs
async def test_insert__return_id(manager):
@dbs_all
async def test_insert__return_id(db):
last_id = await TestModel.insert(text="Test %s" % uuid.uuid4()).aio_execute()

res = await TestModel.select().aio_execute()
obj = res[0]
assert last_id == obj.id


@postgres_only
async def test_insert_on_conflict_ignore__last_id_is_none(manager):
@dbs_postgres
async def test_insert_on_conflict_ignore__last_id_is_none(db):
query = TestModel.insert(text="text").on_conflict_ignore()
await query.aio_execute()

Expand All @@ -37,8 +37,8 @@ async def test_insert_on_conflict_ignore__last_id_is_none(manager):
assert last_id is None


@postgres_only
async def test_insert_on_conflict_ignore__return_model(manager):
@dbs_postgres
async def test_insert_on_conflict_ignore__return_model(db):
query = TestModel.insert(text="text", data="data").on_conflict_ignore().returning(TestModel)

res = await query.aio_execute()
Expand All @@ -54,8 +54,8 @@ async def test_insert_on_conflict_ignore__return_model(manager):
}) is True


@postgres_only
async def test_insert_on_conflict_ignore__inserted_once(manager):
@dbs_postgres
async def test_insert_on_conflict_ignore__inserted_once(db):
query = TestModel.insert(text="text").on_conflict_ignore()
last_id = await query.aio_execute()

Expand All @@ -66,15 +66,15 @@ async def test_insert_on_conflict_ignore__inserted_once(manager):
assert res[0].id == last_id


@postgres_only
async def test_insert__uuid_pk(manager):
@dbs_postgres
async def test_insert__uuid_pk(db):
query = UUIDTestModel.insert(text="Test %s" % uuid.uuid4())
last_id = await query.aio_execute()
assert len(str(last_id)) == 36


@postgres_only
async def test_insert__return_model(manager):
@dbs_postgres
async def test_insert__return_model(db):
text = "Test %s" % uuid.uuid4()
data = "data"
query = TestModel.insert(text=text, data=data).returning(TestModel)
Expand All @@ -87,8 +87,8 @@ async def test_insert__return_model(manager):
) is True


@postgres_only
async def test_insert_many__return_model(manager):
@dbs_postgres
async def test_insert_many__return_model(db):
texts = [f"text{n}" for n in range(2)]
query = TestModel.insert_many([
{"text": text} for text in texts
Expand Down
6 changes: 3 additions & 3 deletions tests/aio_model/test_selecting.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import peewee
from tests.conftest import manager_for_all_dbs
from tests.conftest import manager_for_all_dbs, dbs_all
from tests.models import TestModel, TestModelAlpha, TestModelBeta


@manager_for_all_dbs
async def test_select_w_join(manager):
@dbs_all
async def test_select_w_join(db):
alpha = await TestModelAlpha.aio_create(text="Test 1")
beta = await TestModelBeta.aio_create(alpha_id=alpha.id, text="text")

Expand Down
15 changes: 6 additions & 9 deletions tests/aio_model/test_shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import uuid

import pytest

from tests.conftest import manager_for_all_dbs, postgres_only
from tests.models import TestModel, TestModelAlpha, TestModelBeta

from tests.conftest import dbs_all
from tests.models import TestModel


@manager_for_all_dbs
async def test_aio_get(manager):
@dbs_all
async def test_aio_get(db):
obj1 = await TestModel.aio_create(text="Test 1")
obj2 = await TestModel.aio_create(text="Test 2")

Expand All @@ -22,8 +19,8 @@ async def test_aio_get(manager):
await TestModel.aio_get(TestModel.text == "unknown")


@manager_for_all_dbs
async def test_aio_get_or_none(manager):
@dbs_all
async def test_aio_get_or_none(db):
obj1 = await TestModel.aio_create(text="Test 1")

result = await TestModel.aio_get_or_none(TestModel.id == obj1.id)
Expand Down
14 changes: 7 additions & 7 deletions tests/aio_model/test_updating.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import uuid

from tests.conftest import postgres_only, manager_for_all_dbs
from tests.conftest import dbs_all, dbs_postgres
from tests.models import TestModel


@manager_for_all_dbs
async def test_update__count(manager):
@dbs_all
async def test_update__count(db):
for n in range(3):
await TestModel.aio_create(text=f"{n}")
count = await TestModel.update(data="new_data").aio_execute()

assert count == 3


@manager_for_all_dbs
async def test_update__field_updated(manager):
@dbs_all
async def test_update__field_updated(db):
text = "Test %s" % uuid.uuid4()
obj1 = await TestModel.aio_create(text=text)
await TestModel.update(text="Test update query").where(TestModel.id == obj1.id).aio_execute()
Expand All @@ -23,8 +23,8 @@ async def test_update__field_updated(manager):
assert obj2.text == "Test update query"


@postgres_only
async def test_update__returning_model(manager):
@dbs_postgres
async def test_update__returning_model(db):
await TestModel.aio_create(text="text1", data="data")
await TestModel.aio_create(text="text2", data="data")
new_data = "New_data"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ async def db(request):
MYSQL_DBS = ["mysql", "mysql-pool"]


dbs_postgres = pytest.mark.parametrize(
"db", PG_DBS, indirect=["db"]
)


dbs_all = pytest.mark.parametrize(
"db", PG_DBS + MYSQL_DBS, indirect=["db"]
)
Expand Down

0 comments on commit 62b582e

Please sign in to comment.