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_association_proxy ,
21
29
convert_sqlalchemy_column ,
28
36
from ..fields import UnsortedSQLAlchemyConnectionField , default_connection_field_factory
29
37
from ..registry import Registry , get_global_registry
30
38
from ..types import ORMField , SQLAlchemyObjectType
39
+ from ..utils import is_sqlalchemy_version_less_than
31
40
from .models import (
32
41
Article ,
33
42
CompositeFullName ,
@@ -206,9 +215,9 @@ def prop_method() -> int | str:
206
215
return "not allowed in gql schema"
207
216
208
217
with pytest .raises (
209
- ValueError ,
210
- match = r"Cannot convert hybrid_property Union to "
211
- r"graphene.Union: the Union contains scalars. \.*" ,
218
+ ValueError ,
219
+ match = r"Cannot convert hybrid_property Union to "
220
+ r"graphene.Union: the Union contains scalars. \.*" ,
212
221
):
213
222
get_hybrid_property_type (prop_method )
214
223
@@ -462,7 +471,7 @@ class TestEnum(enum.IntEnum):
462
471
463
472
def test_should_columproperty_convert ():
464
473
field = get_field_from_column (
465
- column_property (select ([ func .sum (func .cast (id , types .Integer ))] ).where (id == 1 ))
474
+ column_property (wrap_select_func ( func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
466
475
)
467
476
468
477
assert field .type == graphene .Int
@@ -479,10 +488,18 @@ def test_should_jsontype_convert_jsonstring():
479
488
assert get_field (types .JSON ).type == graphene .JSONString
480
489
481
490
491
+ @pytest .mark .skipif (
492
+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
493
+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
494
+ )
482
495
def test_should_variant_int_convert_int ():
483
496
assert get_field (types .Variant (types .Integer (), {})).type == graphene .Int
484
497
485
498
499
+ @pytest .mark .skipif (
500
+ (not is_sqlalchemy_version_less_than ("2.0.0b1" )),
501
+ reason = "SQLAlchemy >=2.0 does not support this: Variant is no longer used in SQLAlchemy" ,
502
+ )
486
503
def test_should_variant_string_convert_string ():
487
504
assert get_field (types .Variant (types .String (), {})).type == graphene .String
488
505
@@ -871,8 +888,8 @@ class Meta:
871
888
)
872
889
873
890
for (
874
- hybrid_prop_name ,
875
- hybrid_prop_expected_return_type ,
891
+ hybrid_prop_name ,
892
+ hybrid_prop_expected_return_type ,
876
893
) in shopping_cart_item_expected_types .items ():
877
894
hybrid_prop_field = ShoppingCartItemType ._meta .fields [hybrid_prop_name ]
878
895
@@ -883,7 +900,7 @@ class Meta:
883
900
str (hybrid_prop_expected_return_type ),
884
901
)
885
902
assert (
886
- hybrid_prop_field .description is None
903
+ hybrid_prop_field .description is None
887
904
) # "doc" is ignored by hybrid property
888
905
889
906
###################################################
@@ -930,8 +947,8 @@ class Meta:
930
947
)
931
948
932
949
for (
933
- hybrid_prop_name ,
934
- hybrid_prop_expected_return_type ,
950
+ hybrid_prop_name ,
951
+ hybrid_prop_expected_return_type ,
935
952
) in shopping_cart_expected_types .items ():
936
953
hybrid_prop_field = ShoppingCartType ._meta .fields [hybrid_prop_name ]
937
954
@@ -942,5 +959,5 @@ class Meta:
942
959
str (hybrid_prop_expected_return_type ),
943
960
)
944
961
assert (
945
- hybrid_prop_field .description is None
962
+ hybrid_prop_field .description is None
946
963
) # "doc" is ignored by hybrid property
0 commit comments