def test_send_subscription_fail_message_to_client_with_invalid_query(server):
node_script = '''
module.paths.push('{0}')
WebSocket = require('ws')
const SubscriptionClient =
require('subscriptions-transport-ws').SubscriptionClient
const client = new SubscriptionClient('ws://localhost:{1}/socket')
setTimeout(function () {{
client.subscribe({{
query: `subscription useInfo($id: String) {{
user(id: $id) {{
id
birthday
}}
}}`,
operationName: 'useInfo',
variables: {{
id: 3,
}},
}}, function (error, result) {{
}}
);
}}, 100);
client.client.onmessage = (message) => {{
let msg = JSON.parse(message.data)
console.log(JSON.stringify({{[msg.type]: msg}}))
}};
'''.format(
os.path.join(os.path.dirname(__file__), 'node_modules'), TEST_PORT)
p = subprocess.Popen(
['node', '-e', node_script],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
time.sleep(.2)
q = queue.Queue()
t = threading.Thread(target=enqueue_output, args=(p.stdout, q))
t.daemon = True
t.start()
time.sleep(.2)
ret_values = {}
while True:
try:
_line = q.get_nowait()
if isinstance(_line, bytes):
line = _line.decode()
line = json.loads(line)
ret_values[list(line.keys())[0]] = line[list(line.keys())[0]]
except ValueError:
pass
except queue.Empty:
break
assert ret_values['type'] == SUBSCRIPTION_FAIL
assert len(ret_values['payload']['errors']) > 0
# TODO: troubleshoot this a bit...passes, but receives extra messages which I'm
# filtering out w/ the "AttributeError" exception clause
test_subscription_transport.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录