2
2
import sys
3
3
from typing import Dict , Union
4
4
5
+ import graphene
5
6
import pytest
6
7
import sqlalchemy_utils as sqa_utils
7
- from sqlalchemy import Column , func , select , types
8
+ from graphene .relay import Node
9
+ from graphene .types .structures import Structure
10
+ from sqlalchemy import Column , func , types
8
11
from sqlalchemy .dialects import postgresql
9
12
from sqlalchemy .ext .declarative import declarative_base
10
13
from sqlalchemy .ext .hybrid import hybrid_property
11
14
from sqlalchemy .inspection import inspect
12
15
from sqlalchemy .orm import column_property , composite
13
16
14
- import graphene
15
- from graphene .relay import Node
16
- from graphene .types .structures import Structure
17
-
17
+ from .models import (
18
+ Article ,
19
+ CompositeFullName ,
20
+ Pet ,
21
+ Reporter ,
22
+ ShoppingCart ,
23
+ ShoppingCartItem ,
24
+ )
18
25
from ..converter import (
19
26
convert_sqlalchemy_column ,
20
27
convert_sqlalchemy_composite ,
24
31
from ..fields import UnsortedSQLAlchemyConnectionField , default_connection_field_factory
25
32
from ..registry import Registry , get_global_registry
26
33
from ..types import ORMField , SQLAlchemyObjectType
27
- from ..utils import SQL_VERSION_HIGHER_EQUAL_THAN_1_4 , is_sqlalchemy_version_less_than
28
- from .models import (
29
- Article ,
30
- CompositeFullName ,
31
- Pet ,
32
- Reporter ,
33
- ShoppingCart ,
34
- ShoppingCartItem ,
35
- )
34
+ from ..utils import is_sqlalchemy_version_less_than
36
35
37
36
38
37
def mock_resolver ():
@@ -88,9 +87,9 @@ def prop_method() -> int | str:
88
87
return "not allowed in gql schema"
89
88
90
89
with pytest .raises (
91
- ValueError ,
92
- match = r"Cannot convert hybrid_property Union to "
93
- r"graphene.Union: the Union contains scalars. \.*" ,
90
+ ValueError ,
91
+ match = r"Cannot convert hybrid_property Union to "
92
+ r"graphene.Union: the Union contains scalars. \.*" ,
94
93
):
95
94
get_hybrid_property_type (prop_method )
96
95
@@ -337,25 +336,9 @@ class TestEnum(enum.IntEnum):
337
336
assert graphene_type ._meta .enum .__members__ ["two" ].value == 2
338
337
339
338
340
- @pytest .mark .skipif (
341
- not SQL_VERSION_HIGHER_EQUAL_THAN_1_4 ,
342
- reason = "SQLAlchemy <1.4 does not support this" ,
343
- )
344
- def test_should_columproperty_convert_sqa_20 ():
345
- field = get_field_from_column (
346
- column_property (select (func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
347
- )
348
-
349
- assert field .type == graphene .Int
350
-
351
-
352
- @pytest .mark .skipif (
353
- not is_sqlalchemy_version_less_than ("2.0.0b1" ),
354
- reason = "SQLAlchemy >=2.0 does not support this syntax, see convert_sqa_20" ,
355
- )
356
339
def test_should_columproperty_convert ():
357
340
field = get_field_from_column (
358
- column_property (select ([ func .sum (func .cast (id , types .Integer ))] ).where (id == 1 ))
341
+ column_property (wrap_select_func ( func .sum (func .cast (id , types .Integer ))).where (id == 1 ))
359
342
)
360
343
361
344
assert field .type == graphene .Int
@@ -654,8 +637,8 @@ class Meta:
654
637
)
655
638
656
639
for (
657
- hybrid_prop_name ,
658
- hybrid_prop_expected_return_type ,
640
+ hybrid_prop_name ,
641
+ hybrid_prop_expected_return_type ,
659
642
) in shopping_cart_item_expected_types .items ():
660
643
hybrid_prop_field = ShoppingCartItemType ._meta .fields [hybrid_prop_name ]
661
644
@@ -666,7 +649,7 @@ class Meta:
666
649
str (hybrid_prop_expected_return_type ),
667
650
)
668
651
assert (
669
- hybrid_prop_field .description is None
652
+ hybrid_prop_field .description is None
670
653
) # "doc" is ignored by hybrid property
671
654
672
655
###################################################
@@ -714,8 +697,8 @@ class Meta:
714
697
)
715
698
716
699
for (
717
- hybrid_prop_name ,
718
- hybrid_prop_expected_return_type ,
700
+ hybrid_prop_name ,
701
+ hybrid_prop_expected_return_type ,
719
702
) in shopping_cart_expected_types .items ():
720
703
hybrid_prop_field = ShoppingCartType ._meta .fields [hybrid_prop_name ]
721
704
@@ -726,5 +709,5 @@ class Meta:
726
709
str (hybrid_prop_expected_return_type ),
727
710
)
728
711
assert (
729
- hybrid_prop_field .description is None
712
+ hybrid_prop_field .description is None
730
713
) # "doc" is ignored by hybrid property
0 commit comments