Skip to content

Commit

Permalink
fix and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jan 12, 2025
1 parent 51771ba commit 88063df
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tests/metaclass/test_meta_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import edgy
from edgy import Manager, QuerySet
from edgy.exceptions import ForeignKeyBadConfigured, ImproperlyConfigured
from edgy.exceptions import ForeignKeyBadConfigured, ImproperlyConfigured, ModelCollisionError
from edgy.testclient import DatabaseTestClient
from tests.settings import DATABASE_URL

Expand Down Expand Up @@ -120,21 +120,44 @@ class Meta:
assert raised.value.args[0] == "Meta.indexes must be a list of Index types."


def test_raises_ModelCollisionError():
with pytest.raises(ModelCollisionError) as raised:

class User(edgy.StrictModel):
name = edgy.CharField(max_length=255)

class Meta:
registry = models

assert raised.value.args[0] == (
'A model with the same name is already registered: "User".\n'
'If this is not a bug, define the behaviour by setting "on_conflict" to either "keep" or "replace".'
)


def test_no_raises_ModelCollisionError():
class User(edgy.StrictModel, skip_registry=True):
name = edgy.CharField(max_length=255)

class Meta:
registry = models


def test_raises_ForeignKeyBadConfigured():
name = "profiles"

with pytest.raises(ForeignKeyBadConfigured) as raised:

class User(edgy.StrictModel):
class User2(edgy.StrictModel):
name = edgy.CharField(max_length=255)

class Meta:
registry = models

class Profile(edgy.StrictModel):
user = edgy.ForeignKey(User, null=False, on_delete=edgy.CASCADE, related_name=name)
user = edgy.ForeignKey(User2, null=False, on_delete=edgy.CASCADE, related_name=name)
another_user = edgy.ForeignKey(
User, null=False, on_delete=edgy.CASCADE, related_name=name
User2, null=False, on_delete=edgy.CASCADE, related_name=name
)

class Meta:
Expand Down

0 comments on commit 88063df

Please sign in to comment.