|
4 | 4 | import six
|
5 | 5 | from promise import Promise
|
6 | 6 |
|
| 7 | +from .. import utils |
7 | 8 | from ..registry import Registry
|
8 | 9 | from ..types import SQLAlchemyObjectType, SQLAlchemyObjectTypeOptions
|
9 | 10 | from .models import Article, Reporter
|
@@ -181,3 +182,35 @@ class Meta:
|
181 | 182 | resolver, TestConnection, ReporterWithCustomOptions, None, None
|
182 | 183 | )
|
183 | 184 | assert result is not None
|
| 185 | + |
| 186 | + |
| 187 | +def test_errors_propagated(): |
| 188 | + # Get current `class_mapper` value |
| 189 | + old_class_mapper = utils.class_mapper |
| 190 | + |
| 191 | + try: |
| 192 | + # Define unique error to detect |
| 193 | + class UniqueError(Exception): |
| 194 | + pass |
| 195 | + |
| 196 | + # Redefine `class_mapper` in utils |
| 197 | + def new_class_mapper(*args, **kwargs): |
| 198 | + raise UniqueError() |
| 199 | + utils.class_mapper = new_class_mapper |
| 200 | + |
| 201 | + # Make sure that errors are propagated from class_mapper when instantiating classes |
| 202 | + error = None |
| 203 | + try: |
| 204 | + class Tree(SQLAlchemyObjectType): |
| 205 | + class Meta(object): |
| 206 | + model = Article |
| 207 | + |
| 208 | + except UniqueError as e: |
| 209 | + error = e |
| 210 | + |
| 211 | + # Check that an error occured, and that it was a SQLAlchemy error |
| 212 | + assert error is not None |
| 213 | + assert isinstance(error, UniqueError) |
| 214 | + finally: |
| 215 | + # Restore original class mapper |
| 216 | + utils.class_mapper = old_class_mapper |
0 commit comments