|
7 | 7 |
|
8 | 8 | from ..converter import convert_sqlalchemy_composite
|
9 | 9 | from ..fields import (SQLAlchemyConnectionField,
|
10 |
| - UnsortedSQLAlchemyConnectionField, |
| 10 | + UnsortedSQLAlchemyConnectionField, createConnectionField, |
11 | 11 | registerConnectionFieldFactory,
|
12 | 12 | unregisterConnectionFieldFactory)
|
13 | 13 | from ..types import ORMField, SQLAlchemyObjectType, SQLAlchemyObjectTypeOptions
|
@@ -224,6 +224,19 @@ class Meta:
|
224 | 224 | assert pets_field.type().description == 'Overridden'
|
225 | 225 |
|
226 | 226 |
|
| 227 | +def test_invalid_model_attr(): |
| 228 | + err_msg = ( |
| 229 | + "Cannot map ORMField to a model attribute.\n" |
| 230 | + "Field: 'ReporterType.first_name'" |
| 231 | + ) |
| 232 | + with pytest.raises(ValueError, match=err_msg): |
| 233 | + class ReporterType(SQLAlchemyObjectType): |
| 234 | + class Meta: |
| 235 | + model = Reporter |
| 236 | + |
| 237 | + first_name = ORMField(model_attr='does_not_exist') |
| 238 | + |
| 239 | + |
227 | 240 | def test_only_fields():
|
228 | 241 | class ReporterType(SQLAlchemyObjectType):
|
229 | 242 | class Meta:
|
@@ -364,33 +377,40 @@ class Meta:
|
364 | 377 |
|
365 | 378 |
|
366 | 379 | def test_deprecated_registerConnectionFieldFactory():
|
367 |
| - registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) |
| 380 | + with pytest.warns(DeprecationWarning): |
| 381 | + registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) |
368 | 382 |
|
369 |
| - class ReporterType(SQLAlchemyObjectType): |
370 |
| - class Meta: |
371 |
| - model = Reporter |
372 |
| - interfaces = (Node,) |
| 383 | + class ReporterType(SQLAlchemyObjectType): |
| 384 | + class Meta: |
| 385 | + model = Reporter |
| 386 | + interfaces = (Node,) |
373 | 387 |
|
374 |
| - class ArticleType(SQLAlchemyObjectType): |
375 |
| - class Meta: |
376 |
| - model = Article |
377 |
| - interfaces = (Node,) |
| 388 | + class ArticleType(SQLAlchemyObjectType): |
| 389 | + class Meta: |
| 390 | + model = Article |
| 391 | + interfaces = (Node,) |
378 | 392 |
|
379 |
| - assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) |
| 393 | + assert isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) |
380 | 394 |
|
381 | 395 |
|
382 | 396 | def test_deprecated_unregisterConnectionFieldFactory():
|
383 |
| - registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) |
384 |
| - unregisterConnectionFieldFactory() |
| 397 | + with pytest.warns(DeprecationWarning): |
| 398 | + registerConnectionFieldFactory(_TestSQLAlchemyConnectionField) |
| 399 | + unregisterConnectionFieldFactory() |
385 | 400 |
|
386 |
| - class ReporterType(SQLAlchemyObjectType): |
387 |
| - class Meta: |
388 |
| - model = Reporter |
389 |
| - interfaces = (Node,) |
| 401 | + class ReporterType(SQLAlchemyObjectType): |
| 402 | + class Meta: |
| 403 | + model = Reporter |
| 404 | + interfaces = (Node,) |
| 405 | + |
| 406 | + class ArticleType(SQLAlchemyObjectType): |
| 407 | + class Meta: |
| 408 | + model = Article |
| 409 | + interfaces = (Node,) |
| 410 | + |
| 411 | + assert not isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) |
390 | 412 |
|
391 |
| - class ArticleType(SQLAlchemyObjectType): |
392 |
| - class Meta: |
393 |
| - model = Article |
394 |
| - interfaces = (Node,) |
395 | 413 |
|
396 |
| - assert not isinstance(ReporterType._meta.fields['articles'].type(), _TestSQLAlchemyConnectionField) |
| 414 | +def test_deprecated_createConnectionField(): |
| 415 | + with pytest.warns(DeprecationWarning): |
| 416 | + createConnectionField(None) |
0 commit comments