Skip to content

Commit 55043a1

Browse files
committed
Complete initial subscription_transport tests
See notes in tests/test_subscription_transport.py for how to run tests. This implementation is based on the apollographql/subscriptions-transport-ws library and uses their graphql subscriptions client for testing. Specifically, these tests are compatable with npm package released version subscriptions-transport-ws@0.5.4. Tests are about halfway complete for that release version.
1 parent f7c095e commit 55043a1

5 files changed

Lines changed: 479 additions & 16 deletions

File tree

graphql_subscriptions/subscription_transport_ws.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ def on_message(self, msg):
7777
if msg is None:
7878
return
7979

80-
class nonlocal:
81-
on_init_resolve = None
82-
on_init_reject = None
80+
nonlocal = {'on_init_resolve': None, 'on_init_reject': None}
8381

8482
def init_promise_handler(resolve, reject):
85-
nonlocal.on_init_resolve = resolve
86-
nonlocal.on_init_reject = reject
83+
nonlocal['on_init_resolve'] = resolve
84+
nonlocal['on_init_reject'] = reject
8785

8886
self.connection_context['init_promise'] = Promise(init_promise_handler)
8987

@@ -107,7 +105,7 @@ def on_message_return_handler(message):
107105
self.on_connect(
108106
parsed_message.get('payload'), self.ws))
109107

110-
nonlocal.on_init_resolve(on_connect_promise)
108+
nonlocal['on_init_resolve'](on_connect_promise)
111109

112110
def init_success_promise_handler(result):
113111
if not result:
@@ -218,7 +216,7 @@ def error_catch_handler(e):
218216
# not sure if this behavior is correct or
219217
# not per promises A spec...need to
220218
# investigate
221-
nonlocal.on_init_resolve(Promise.resolve(True))
219+
nonlocal['on_init_resolve'](Promise.resolve(True))
222220

223221
self.connection_context['init_promise'].then(
224222
subscription_start_promise_handler)
@@ -231,7 +229,7 @@ def subscription_end_promise_handler(result):
231229
del self.connection_subscriptions[sub_id]
232230

233231
# same rationale as above
234-
nonlocal.on_init_resolve(Promise.resolve(True))
232+
nonlocal['on_init_resolve'](Promise.resolve(True))
235233

236234
self.connection_context['init_promise'].then(
237235
subscription_end_promise_handler)

setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='graphql-subscriptions',
11-
version='0.1.7',
11+
version='0.1.8',
1212
author='Heath Ballard',
1313
author_email='heath.ballard@gmail.com',
1414
description=('A port of apollo-graphql subscriptions for python, using\
@@ -26,6 +26,11 @@
2626
'Programming Language :: Python :: 2.7',
2727
'License :: OSI Approved :: MIT License'
2828
],
29-
install_requires=['gevent-websocket', 'redis', 'promise', 'graphql-core'],
30-
tests_require=['pytest', 'pytest-mock', 'fakeredis', 'graphene'],
29+
install_requires=[
30+
'gevent-websocket', 'redis', 'promise==1.0.1', 'graphql-core'
31+
],
32+
tests_require=[
33+
'pytest', 'pytest-mock', 'fakeredis', 'graphene', 'subprocess32',
34+
'flask', 'flask-graphql', 'flask-sockets'
35+
],
3136
include_package_data=True)

tests/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"graphql": "^0.9.6",
4+
"subscriptions-transport-ws": "0.5.4"
5+
}
6+
}

tests/test_subscription_manager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313

1414

1515
@pytest.fixture
16-
def mock_redis(monkeypatch):
16+
def pubsub(monkeypatch):
1717
monkeypatch.setattr(redis, 'StrictRedis', fakeredis.FakeStrictRedis)
18-
19-
20-
@pytest.fixture
21-
def pubsub(mock_redis):
2218
return RedisPubsub()
2319

2420

0 commit comments

Comments
 (0)