Skip to content

Commit 09dd6af

Browse files
committed
expanding test coverage
1 parent 4a5cf7e commit 09dd6af

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

graphene_sqlalchemy/converter.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ def dynamic_type():
5252
if not scalar:
5353
# repackage as List
5454
field.__dict__['_type'] = List(field.type)
55+
return field
5556
elif isinstance(attr, RelationshipProperty):
56-
field = convert_sqlalchemy_relationship(
57+
return convert_sqlalchemy_relationship(
5758
attr,
5859
obj_type,
5960
connection_field_factory,
6061
field_kwargs.pop('batching', batching),
6162
assoc_prop.value_attr,
6263
**field_kwargs
6364
).get_type()
64-
else:
65-
raise NotImplementedError(attr)
66-
67-
return field
65+
# else, not supported
6866

6967
return Dynamic(dynamic_type)
7068

graphene_sqlalchemy/tests/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def hybrid_prop(self):
7676

7777
composite_prop = composite(CompositeFullName, first_name, last_name, doc="Composite")
7878

79-
pet_names = association_proxy('pets', 'name')
79+
headlines = association_proxy('articles', 'headline')
8080

8181

8282
class Article(Base):
@@ -85,7 +85,7 @@ class Article(Base):
8585
headline = Column(String(100))
8686
pub_date = Column(Date())
8787
reporter_id = Column(Integer(), ForeignKey("reporters.id"))
88-
reporter_pets = association_proxy('reporter', 'pets')
88+
recommended_reads = association_proxy('reporter', 'articles')
8989

9090

9191
class ReflectedEditor(type):

graphene_sqlalchemy/tests/test_converter.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,17 @@ class Meta:
287287

288288

289289
def test_should_convert_association_proxy():
290-
class P(SQLAlchemyObjectType):
290+
class PetType(SQLAlchemyObjectType):
291291
class Meta:
292292
model = Pet
293+
class ArticleType(SQLAlchemyObjectType):
294+
class Meta:
295+
model = Article
293296

294297
field = convert_sqlalchemy_association_proxy(
295298
Reporter,
296-
Reporter.pet_names,
297-
P,
299+
Reporter.headlines,
300+
PetType,
298301
get_global_registry(),
299302
default_connection_field_factory,
300303
True,
@@ -306,15 +309,15 @@ class Meta:
306309

307310
dynamic_field = convert_sqlalchemy_association_proxy(
308311
Article,
309-
Article.reporter_pets,
310-
P,
312+
Article.recommended_reads,
313+
ArticleType,
311314
get_global_registry(),
312315
default_connection_field_factory,
313316
True,
314317
mock_resolver,
315318
)
316319
assert isinstance(dynamic_field, graphene.Dynamic)
317-
assert dynamic_field.get_type().type.of_type == P
320+
assert dynamic_field.get_type().type.of_type == ArticleType
318321

319322

320323
def test_should_postgresql_uuid_convert():

graphene_sqlalchemy/tests/test_query.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def resolve_reporters(self, _info):
5757
columnProp
5858
hybridProp
5959
compositeProp
60+
headlines
6061
}
6162
reporters {
6263
firstName
@@ -69,6 +70,7 @@ def resolve_reporters(self, _info):
6970
"hybridProp": "John",
7071
"columnProp": 2,
7172
"compositeProp": "John Doe",
73+
"headlines": ['Hi!'],
7274
},
7375
"reporters": [{"firstName": "John"}, {"firstName": "Jane"}],
7476
}

graphene_sqlalchemy/tests/test_types.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class Meta:
7171
model = Article
7272
interfaces = (Node,)
7373

74+
class PetType(SQLAlchemyObjectType):
75+
class Meta:
76+
model = Pet
77+
interfaces = (Node,)
78+
79+
7480
assert list(ReporterType._meta.fields.keys()) == [
7581
# Columns
7682
"column_prop", # SQLAlchemy retuns column properties first
@@ -84,7 +90,7 @@ class Meta:
8490
# Hybrid
8591
"hybrid_prop",
8692
# AssociationProxy
87-
"pet_names",
93+
"headlines",
8894
# Relationship
8995
"pets",
9096
"articles",
@@ -121,11 +127,15 @@ class Meta:
121127
assert favorite_article_field.type().description is None
122128

123129
# assocation proxy
124-
assoc_field = ReporterType._meta.fields['pet_names']
130+
assoc_field = ReporterType._meta.fields['headlines']
125131
assert isinstance(assoc_field, Dynamic)
126132
assert isinstance(assoc_field.type().type, List)
127133
assert assoc_field.type().type.of_type == String
128134

135+
assoc_field = ArticleType._meta.fields['recommended_reads']
136+
assert isinstance(assoc_field, Dynamic)
137+
assert assoc_field.type().type == ArticleType.connection
138+
129139

130140
def test_sqlalchemy_override_fields():
131141
@convert_sqlalchemy_composite.register(CompositeFullName)
@@ -187,7 +197,7 @@ class Meta:
187197
# Then the automatic SQLAlchemy fields
188198
"id",
189199
"favorite_pet_kind",
190-
"pet_names",
200+
"headlines",
191201
]
192202

193203
first_name_field = ReporterType._meta.fields['first_name']
@@ -285,7 +295,7 @@ class Meta:
285295
"favorite_pet_kind",
286296
"composite_prop",
287297
"hybrid_prop",
288-
"pet_names",
298+
"headlines",
289299
"pets",
290300
"articles",
291301
"favorite_article",

0 commit comments

Comments
 (0)