Skip to content

Commit

Permalink
Update tests to use the new monkay based way
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Nov 15, 2024
1 parent a169170 commit 61ed55c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
5 changes: 3 additions & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ hide:
- Rework Migrate system to simply use Monkay instance.
- Replace `get_registry_copy` by `get_migration_prepared_registry`.
- Breaking: migration configuration takes place in settings.
- Breaking: EdgyExtra and Migrate are replaced by `edgy.Instance` but still available.
- Breaking: `model_apps` is replaced by `preloads`.
- Breaking: EdgyExtra and Migrate are replaced by `edgy.Instance` but are still available.
- Breaking: EdgyExtra is provided by the also obsolete Migrate.
- Breaking: `model_apps` is replaced by `preloads` but still available during the migration time.

### Fixed

Expand Down
10 changes: 5 additions & 5 deletions tests/contrib/multi_tenancy/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from esmerald import Esmerald

import edgy
from edgy import Migrate, Registry
from edgy import Instance, Registry
from edgy.contrib.multi_tenancy import TenantModel
from edgy.contrib.multi_tenancy.models import TenantMixin
from edgy.core.db import fields
Expand Down Expand Up @@ -51,7 +51,7 @@ async def test_migrate_objs_main_only():

app = Esmerald()

Migrate(app=app, registry=models)
Instance(app=app, registry=models)
registry = edgy.get_migration_prepared_registry()
assert len(registry.metadata_by_name[None].tables.keys()) == 2

Expand All @@ -68,7 +68,7 @@ async def test_migrate_objs_all():

app = Esmerald()

Migrate(app=app, registry=models)
Instance(app=app, registry=models)
with edgy.monkay.with_settings(edgy.monkay.settings.model_copy(update={"multi_schema": True})):
registry = edgy.get_migration_prepared_registry()

Expand All @@ -94,7 +94,7 @@ async def test_migrate_objs_namespace_only():

app = Esmerald()

Migrate(app=app, registry=models)
Instance(app=app, registry=models)
with edgy.monkay.with_settings(
edgy.monkay.settings.model_copy(update={"multi_schema": "saffier"})
):
Expand All @@ -118,7 +118,7 @@ async def test_migrate_objs_few():

app = Esmerald()

Migrate(app=app, registry=models)
Instance(app=app, registry=models)
with edgy.monkay.with_settings(
edgy.monkay.settings.model_copy(update={"multi_schema": "saffier|^$"})
):
Expand Down
20 changes: 14 additions & 6 deletions tests/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from esmerald import Esmerald

import edgy
from edgy import Migrate, Registry
from edgy import Registry
from edgy.testclient import DatabaseTestClient
from tests.settings import DATABASE_URL

Expand Down Expand Up @@ -39,9 +39,16 @@ class Meta:
registry = models


def test_migrate_without_model_apps():
@pytest.mark.parametrize(
"init,deprecated", [("Instance", True), ("Migrate", True), ("EdgyExtra", True)]
)
def test_migrate_without_model_apps(init, deprecated):
app = Esmerald()
migrate = Migrate(app=app, registry=models)
if deprecated:
with pytest.warns(DeprecationWarning):
migrate = init(app=app, registry=models)
else:
migrate = init(app=app, registry=models)

assert len(models.models) == 3
assert len(migrate.registry.models) == 3
Expand All @@ -60,7 +67,8 @@ def test_migrate_with_fake_model_apps(model_apps):

assert len(nother.models) == 0

Migrate(app=app, registry=nother, model_apps=model_apps)
with pytest.warns(DeprecationWarning):
edgy.Migrate(app=app, registry=nother, model_apps=model_apps)
registry = edgy.get_migration_prepared_registry()
assert len(nother.models) == 2
assert len(registry.models) == 2
Expand All @@ -77,5 +85,5 @@ def test_raises_assertation_error_on_model_apps(model_apps):

assert len(nother.models) == 0

with pytest.raises(AssertionError):
Migrate(app=app, registry=nother, model_apps=model_apps)
with pytest.raises(AssertionError), pytest.warns(DeprecationWarning):
edgy.Migrate(app=app, registry=nother, model_apps=model_apps)

0 comments on commit 61ed55c

Please sign in to comment.