graphene-django/graphene_django/tests/test_schema.py
Santiago Aguiar 7c780a916a
Backport Django 4.1 compatibility fixes to v2 (#1413)
* handle deprecation warning for requires_system_checks

Removed in django 4.1.

* Fix broken UT due to pytest import error (#1368)

* import error resolved?

* Fix tests

* Remove Python 3.6

* django 4.1 requires python>=3.10

* Django 4.1 does support python 3.8 to 3.11

* Add Django 4.1 to tox

---------

Co-authored-by: Yuekui <yuekui@users.noreply.github.com>
Co-authored-by: Josh Warwick <josh.warwick15@gmail.com>
Co-authored-by: Kien Dang <mail@kien.ai>
2023-05-26 23:08:36 +03:00

54 lines
1.2 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):
pass
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
assert "valid Django Model" in str(excinfo.value)
def test_should_map_fields_correctly():
class ReporterType2(DjangoObjectType):
class Meta:
model = Reporter
registry = Registry()
fields = list(ReporterType2._meta.fields.keys())
assert fields[:-2] == [
"id",
"first_name",
"last_name",
"email",
"pets",
"a_choice",
"reporter_type",
]
assert sorted(fields[-2:]) == ["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"]