@@ -661,6 +661,122 @@ class Query(ObjectType):
661661 }"""
662662 )
663663
664+ def test_django_objecttype_convert_choices_global_false (
665+ self , graphene_settings , PetModel
666+ ):
667+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CONVERT = False
668+
669+ class Pet (DjangoObjectType ):
670+ class Meta :
671+ model = PetModel
672+ fields = "__all__"
673+
674+ class Query (ObjectType ):
675+ pet = Field (Pet )
676+
677+ schema = Schema (query = Query )
678+
679+ assert str (schema ) == dedent (
680+ """\
681+ type Query {
682+ pet: Pet
683+ }
684+
685+ type Pet {
686+ id: ID!
687+ kind: String!
688+ cuteness: Int!
689+ }"""
690+ )
691+
692+ def test_django_objecttype_convert_choices_true_global_false (
693+ self , graphene_settings , PetModel
694+ ):
695+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CONVERT = False
696+
697+ class Pet (DjangoObjectType ):
698+ class Meta :
699+ model = PetModel
700+ fields = "__all__"
701+ convert_choices_to_enum = True
702+
703+ class Query (ObjectType ):
704+ pet = Field (Pet )
705+
706+ schema = Schema (query = Query )
707+
708+ assert str (schema ) == dedent (
709+ """\
710+ type Query {
711+ pet: Pet
712+ }
713+
714+ type Pet {
715+ id: ID!
716+ kind: TestsPetModelKindChoices!
717+ cuteness: TestsPetModelCutenessChoices!
718+ }
719+
720+ \" ""An enumeration.\" ""
721+ enum TestsPetModelKindChoices {
722+ \" ""Cat\" ""
723+ CAT
724+
725+ \" ""Dog\" ""
726+ DOG
727+ }
728+
729+ \" ""An enumeration.\" ""
730+ enum TestsPetModelCutenessChoices {
731+ \" ""Kind of cute\" ""
732+ A_1
733+
734+ \" ""Pretty cute\" ""
735+ A_2
736+
737+ \" ""OMG SO CUTE!!!\" ""
738+ A_3
739+ }"""
740+ )
741+
742+ def test_django_objecttype_convert_choices_enum_list_global_false (
743+ self , graphene_settings , PetModel
744+ ):
745+ graphene_settings .DJANGO_CHOICE_FIELD_ENUM_CONVERT = False
746+
747+ class Pet (DjangoObjectType ):
748+ class Meta :
749+ model = PetModel
750+ convert_choices_to_enum = ["kind" ]
751+ fields = "__all__"
752+
753+ class Query (ObjectType ):
754+ pet = Field (Pet )
755+
756+ schema = Schema (query = Query )
757+
758+ assert str (schema ) == dedent (
759+ """\
760+ type Query {
761+ pet: Pet
762+ }
763+
764+ type Pet {
765+ id: ID!
766+ kind: TestsPetModelKindChoices!
767+ cuteness: Int!
768+ }
769+
770+ \" ""An enumeration.\" ""
771+ enum TestsPetModelKindChoices {
772+ \" ""Cat\" ""
773+ CAT
774+
775+ \" ""Dog\" ""
776+ DOG
777+ }"""
778+ )
779+
664780
665781@with_local_registry
666782def test_django_objecttype_name_connection_propagation ():
0 commit comments