mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-14 05:37:02 +03:00
b1abebdb97
* support reverse relationship for proxy models * support multi table inheritence * update query test for multi table inheritance * remove debugger * support local many to many in model inheritance * format and lint --------- Co-authored-by: Firas K <3097061+firaskafri@users.noreply.github.com>
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
from pytest import raises
|
|
|
|
from ..registry import Registry
|
|
from ..types import DjangoObjectType
|
|
from .models import Reporter
|
|
|
|
|
|
def test_should_raise_if_no_model():
|
|
with raises(Exception) as excinfo:
|
|
|
|
class Character1(DjangoObjectType):
|
|
fields = "__all__"
|
|
|
|
assert "valid Django Model" in str(excinfo.value)
|
|
|
|
|
|
def test_should_raise_if_model_is_invalid():
|
|
with raises(Exception) as excinfo:
|
|
|
|
class Character2(DjangoObjectType):
|
|
class Meta:
|
|
model = 1
|
|
fields = "__all__"
|
|
|
|
assert "valid Django Model" in str(excinfo.value)
|
|
|
|
|
|
def test_should_map_fields_correctly():
|
|
class ReporterType2(DjangoObjectType):
|
|
class Meta:
|
|
model = Reporter
|
|
registry = Registry()
|
|
fields = "__all__"
|
|
|
|
fields = list(ReporterType2._meta.fields.keys())
|
|
assert fields[:-3] == [
|
|
"id",
|
|
"first_name",
|
|
"last_name",
|
|
"email",
|
|
"pets",
|
|
"a_choice",
|
|
"fans",
|
|
"reporter_type",
|
|
]
|
|
|
|
assert sorted(fields[-3:]) == ["apnewsreporter", "articles", "films"]
|
|
|
|
|
|
def test_should_map_only_few_fields():
|
|
class Reporter2(DjangoObjectType):
|
|
class Meta:
|
|
model = Reporter
|
|
fields = ("id", "email")
|
|
|
|
assert list(Reporter2._meta.fields.keys()) == ["id", "email"]
|