|
8 | 8 | import pytest
|
9 | 9 |
|
10 | 10 | from graphql_ws import base
|
| 11 | +from graphql_ws.base_sync import SubscriptionObserver |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def test_not_implemented():
|
@@ -77,3 +78,35 @@ def test_context_operations():
|
77 | 78 | assert not context.has_operation(1)
|
78 | 79 | # Removing a non-existant operation fails silently.
|
79 | 80 | context.remove_operation(999)
|
| 81 | + |
| 82 | + |
| 83 | +def test_observer_data(): |
| 84 | + ws = mock.Mock() |
| 85 | + context = base.BaseConnectionContext(ws) |
| 86 | + send_result, send_error, send_message = mock.Mock(), mock.Mock(), mock.Mock() |
| 87 | + observer = SubscriptionObserver( |
| 88 | + connection_context=context, |
| 89 | + op_id=1, |
| 90 | + send_execution_result=send_result, |
| 91 | + send_error=send_error, |
| 92 | + send_message=send_message, |
| 93 | + ) |
| 94 | + observer.on_next('data') |
| 95 | + assert send_result.called |
| 96 | + assert not send_error.called |
| 97 | + |
| 98 | + |
| 99 | +def test_observer_exception(): |
| 100 | + ws = mock.Mock() |
| 101 | + context = base.BaseConnectionContext(ws) |
| 102 | + send_result, send_error, send_message = mock.Mock(), mock.Mock(), mock.Mock() |
| 103 | + observer = SubscriptionObserver( |
| 104 | + connection_context=context, |
| 105 | + op_id=1, |
| 106 | + send_execution_result=send_result, |
| 107 | + send_error=send_error, |
| 108 | + send_message=send_message, |
| 109 | + ) |
| 110 | + observer.on_next(TypeError('some bad message')) |
| 111 | + assert send_error.called |
| 112 | + assert not send_result.called |
0 commit comments