2
2
import sys
3
3
from typing import Dict , Tuple , Union
4
4
5
+ import graphene
5
6
import pytest
6
7
import sqlalchemy
7
8
import sqlalchemy_utils as sqa_utils
8
- from sqlalchemy import Column , func , select , types
9
+ from graphene .relay import Node
10
+ from graphene .types .structures import Structure
11
+ from sqlalchemy import Column , func , types
9
12
from sqlalchemy .dialects import postgresql
10
13
from sqlalchemy .ext .declarative import declarative_base
11
14
from sqlalchemy .ext .hybrid import hybrid_property
12
15
from sqlalchemy .inspection import inspect
13
16
from sqlalchemy .orm import column_property , composite
14
17
15
- import graphene
16
- from graphene .relay import Node
17
- from graphene .types .structures import Structure
18
-
18
+ from .models import (
19
+ Article ,
20
+ CompositeFullName ,
21
+ Pet ,
22
+ Reporter ,
23
+ ShoppingCart ,
24
+ ShoppingCartItem ,
25
+ )
26
+ from .utils import wrap_select_func
19
27
from ..converter import (
20
28
convert_sqlalchemy_column ,
21
29
convert_sqlalchemy_composite ,
27
35
from ..fields import UnsortedSQLAlchemyConnectionField , default_connection_field_factory
28
36
from ..registry import Registry , get_global_registry
29
37
from ..types import ORMField , SQLAlchemyObjectType
38
+ from ..utils import is_sqlalchemy_version_less_than
30
39
from .models import (
31
40
Article ,
32
41
CompositeFullName ,
@@ -204,9 +213,9 @@ def prop_method() -> int | str:
204
213
return "not allowed in gql schema"
205
214
206
215
with pytest .raises (
207
- ValueError ,
208
- match = r"Cannot convert hybrid_property Union to "
209
- r"graphene.Union: the Union contains scalars. \.*" ,
216
+ ValueError ,
217
+ match = r"Cannot convert hybrid_property Union to "
218
+ r"graphene.Union: the Union contains scalars. \.*" ,
210
219
):
211
220
get_hybrid_property_type (prop_method )
212
221
@@ -460,7 +469,7 @@ class TestEnum(enum.IntEnum):
460
469
461
470
def test_should_columproperty_convert ():
462
471
field = get_field_from_column (
463
- column_property (select ([ func .sum (func .cast (id , types .Integer ))] ).where (id == 1 ))
472
+ column_property (wrap_select_func ( func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
464
473
)
465
474
466
475
assert field .type == graphene .Int
@@ -477,10 +486,18 @@ def test_should_jsontype_convert_jsonstring():
477
486
assert get_field (types .JSON ).type == graphene .JSONString
478
487
479
488
489
+ @pytest .mark .skipif (
490
+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
491
+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
492
+ )
480
493
def test_should_variant_int_convert_int ():
481
494
assert get_field (types .Variant (types .Integer (), {})).type == graphene .Int
482
495
483
496
497
+ @pytest .mark .skipif (
498
+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
499
+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
500
+ )
484
501
def test_should_variant_string_convert_string ():
485
502
assert get_field (types .Variant (types .String (), {})).type == graphene .String
486
503
@@ -811,8 +828,8 @@ class Meta:
811
828
)
812
829
813
830
for (
814
- hybrid_prop_name ,
815
- hybrid_prop_expected_return_type ,
831
+ hybrid_prop_name ,
832
+ hybrid_prop_expected_return_type ,
816
833
) in shopping_cart_item_expected_types .items ():
817
834
hybrid_prop_field = ShoppingCartItemType ._meta .fields [hybrid_prop_name ]
818
835
@@ -823,7 +840,7 @@ class Meta:
823
840
str (hybrid_prop_expected_return_type ),
824
841
)
825
842
assert (
826
- hybrid_prop_field .description is None
843
+ hybrid_prop_field .description is None
827
844
) # "doc" is ignored by hybrid property
828
845
829
846
###################################################
@@ -870,8 +887,8 @@ class Meta:
870
887
)
871
888
872
889
for (
873
- hybrid_prop_name ,
874
- hybrid_prop_expected_return_type ,
890
+ hybrid_prop_name ,
891
+ hybrid_prop_expected_return_type ,
875
892
) in shopping_cart_expected_types .items ():
876
893
hybrid_prop_field = ShoppingCartType ._meta .fields [hybrid_prop_name ]
877
894
@@ -882,5 +899,5 @@ class Meta:
882
899
str (hybrid_prop_expected_return_type ),
883
900
)
884
901
assert (
885
- hybrid_prop_field .description is None
902
+ hybrid_prop_field .description is None
886
903
) # "doc" is ignored by hybrid property
0 commit comments