mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 19:14:11 +03:00
b7e4937775
* Create new fields and exclude options that are aliased to exclude_fields and only_fields * Update docs * Add some checking around fields and exclude definitions * Add all fields option * Update docs to include `__all__` option * Actual order of fields is not stable * Update docs/queries.rst Co-Authored-By: Semyon Pupkov <semen.pupkov@gmail.com> * Fix example code * Format code * Start raising PendingDeprecationWarnings for using only_fields and exclude_fields * Update tests
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
from py.test 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"]
|