Skip to content

Commit cc90ad0

Browse files
committed
Added more tests
1 parent 6c4e73b commit cc90ad0

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

.travis.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: python
22
sudo: false
33
python:
44
- 2.7
5-
- 3.4
6-
- 3.5
7-
- 3.6
5+
# - 3.4
6+
# - 3.5
7+
# - 3.6
88
- "pypy-5.3.1"
99
before_install:
1010
- |
@@ -33,6 +33,11 @@ matrix:
3333
- pip install pytest-asyncio
3434
script:
3535
- py.test --cov=graphql graphql tests tests_py35
36+
- python: '3.6'
37+
after_install:
38+
- pip install pytest-asyncio
39+
script:
40+
- py.test --cov=graphql graphql tests tests_py35
3641
- python: '2.7'
3742
install: pip install flake8
3843
script:

graphql/execution/tests/test_subscribe.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,119 @@ def test_produces_a_payload_for_multiple_subscribe_in_same_subscription():
264264

265265
assert payload1[0].data == expected_payload
266266
assert payload2[0].data == expected_payload
267+
268+
269+
# Subscription Publish Phase
270+
def test_produces_a_payload_per_subscription_event():
271+
stream = Subject()
272+
send_important_email, subscription = create_subscription(stream)
273+
274+
payload = []
275+
276+
subscription.subscribe(payload.append)
277+
send_important_email(Email(
278+
279+
subject='Alright',
280+
message='Tests are good',
281+
unread=True,
282+
))
283+
expected_payload = {
284+
'importantEmail': {
285+
'email': {
286+
'from': '[email protected]',
287+
'subject': 'Alright',
288+
},
289+
'inbox': {
290+
'unread': 1,
291+
'total': 2,
292+
},
293+
}
294+
}
295+
296+
assert len(payload) == 1
297+
assert payload[0].data == expected_payload
298+
299+
send_important_email(Email(
300+
301+
subject='Tools',
302+
message='I <3 making things',
303+
unread=True,
304+
))
305+
expected_payload = {
306+
'importantEmail': {
307+
'email': {
308+
'from': '[email protected]',
309+
'subject': 'Tools',
310+
},
311+
'inbox': {
312+
'unread': 2,
313+
'total': 3,
314+
},
315+
}
316+
}
317+
318+
assert len(payload) == 2
319+
assert payload[-1].data == expected_payload
320+
321+
# The client decides to disconnect
322+
stream.on_completed()
323+
324+
send_important_email(Email(
325+
326+
subject='Important',
327+
message='Read me please',
328+
unread=True,
329+
))
330+
331+
assert len(payload) == 2
332+
333+
334+
def test_event_order_is_correct_for_multiple_publishes():
335+
stream = Subject()
336+
send_important_email, subscription = create_subscription(stream)
337+
338+
payload = []
339+
340+
subscription.subscribe(payload.append)
341+
send_important_email(Email(
342+
343+
subject='Message',
344+
message='Tests are good',
345+
unread=True,
346+
))
347+
send_important_email(Email(
348+
349+
subject='Message 2',
350+
message='Tests are good 2',
351+
unread=True,
352+
))
353+
354+
expected_payload1 = {
355+
'importantEmail': {
356+
'email': {
357+
'from': '[email protected]',
358+
'subject': 'Message',
359+
},
360+
'inbox': {
361+
'unread': 1,
362+
'total': 2,
363+
},
364+
}
365+
}
366+
367+
expected_payload2 = {
368+
'importantEmail': {
369+
'email': {
370+
'from': '[email protected]',
371+
'subject': 'Message 2',
372+
},
373+
'inbox': {
374+
'unread': 2,
375+
'total': 3,
376+
},
377+
}
378+
}
379+
380+
assert len(payload) == 2
381+
assert payload[0].data == expected_payload1
382+
assert payload[1].data == expected_payload2

0 commit comments

Comments
 (0)