From 62b582e27609543096ef2e2f2ed21952183f2604 Mon Sep 17 00:00:00 2001 From: kalombo Date: Sat, 18 May 2024 22:27:42 +0500 Subject: [PATCH] chore: rewrite tests for not using manager --- tests/aio_model/test_deleting.py | 14 ++++++------ tests/aio_model/test_inserting.py | 34 ++++++++++++++-------------- tests/aio_model/test_selecting.py | 6 ++--- tests/aio_model/test_shortcuts.py | 15 +++++------- tests/aio_model/test_updating.py | 14 ++++++------ tests/{ => compat}/test_deleting.py | 0 tests/{ => compat}/test_inserting.py | 0 tests/{ => compat}/test_updating.py | 0 tests/conftest.py | 5 ++++ 9 files changed, 45 insertions(+), 43 deletions(-) rename tests/{ => compat}/test_deleting.py (100%) rename tests/{ => compat}/test_inserting.py (100%) rename tests/{ => compat}/test_updating.py (100%) diff --git a/tests/aio_model/test_deleting.py b/tests/aio_model/test_deleting.py index 4312c52..c0fea28 100644 --- a/tests/aio_model/test_deleting.py +++ b/tests/aio_model/test_deleting.py @@ -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()}, @@ -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([ @@ -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() diff --git a/tests/aio_model/test_inserting.py b/tests/aio_model/test_inserting.py index 94c4929..1f36322 100644 --- a/tests/aio_model/test_inserting.py +++ b/tests/aio_model/test_inserting.py @@ -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()}, @@ -18,8 +18,8 @@ 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() @@ -27,8 +27,8 @@ async def test_insert__return_id(manager): 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() @@ -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() @@ -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() @@ -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) @@ -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 diff --git a/tests/aio_model/test_selecting.py b/tests/aio_model/test_selecting.py index a90c2d0..29bc7bb 100644 --- a/tests/aio_model/test_selecting.py +++ b/tests/aio_model/test_selecting.py @@ -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") diff --git a/tests/aio_model/test_shortcuts.py b/tests/aio_model/test_shortcuts.py index eedb03c..40e6c6d 100644 --- a/tests/aio_model/test_shortcuts.py +++ b/tests/aio_model/test_shortcuts.py @@ -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") @@ -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) diff --git a/tests/aio_model/test_updating.py b/tests/aio_model/test_updating.py index 391448f..05294bb 100644 --- a/tests/aio_model/test_updating.py +++ b/tests/aio_model/test_updating.py @@ -1,11 +1,11 @@ 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() @@ -13,8 +13,8 @@ async def test_update__count(manager): 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() @@ -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" diff --git a/tests/test_deleting.py b/tests/compat/test_deleting.py similarity index 100% rename from tests/test_deleting.py rename to tests/compat/test_deleting.py diff --git a/tests/test_inserting.py b/tests/compat/test_inserting.py similarity index 100% rename from tests/test_inserting.py rename to tests/compat/test_inserting.py diff --git a/tests/test_updating.py b/tests/compat/test_updating.py similarity index 100% rename from tests/test_updating.py rename to tests/compat/test_updating.py diff --git a/tests/conftest.py b/tests/conftest.py index a8dd07f..fd3e175 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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"] )