1
1
import json
2
2
3
- from graphql .error import GraphQLError
3
+ from pytest import raises
4
+
4
5
from promise import Promise
5
6
7
+ from graphql .error import GraphQLError , GraphQLSyntaxError
8
+ from graphql .execution import ExecutionResult
9
+
6
10
from graphql_server import (
7
11
HttpQueryError ,
8
12
RequestParams ,
13
17
load_json_body ,
14
18
run_http_query ,
15
19
)
16
- from pytest import raises
17
20
18
21
from .schema import schema
19
22
from .utils import as_dicts
@@ -529,7 +532,7 @@ def test_batch_allows_post_with_operation_name():
529
532
]
530
533
531
534
532
- def test_get_reponses_using_executor ():
535
+ def test_get_responses_using_executor ():
533
536
class TestExecutor (object ):
534
537
called = False
535
538
waited = False
@@ -550,14 +553,18 @@ def execute(self, fn, *args, **kwargs):
550
553
schema , "get" , {}, dict (query = query ), executor = TestExecutor (),
551
554
)
552
555
556
+ assert isinstance (results , list )
557
+ assert len (results ) == 1
558
+ assert isinstance (results [0 ], ExecutionResult )
559
+
553
560
assert as_dicts (results ) == [{"data" : {"test" : "Hello World" }}]
554
561
assert params == [RequestParams (query = query , variables = None , operation_name = None )]
555
562
assert TestExecutor .called
556
563
assert TestExecutor .waited
557
564
assert not TestExecutor .cleaned
558
565
559
566
560
- def test_get_reponses_using_executor_return_promise ():
567
+ def test_get_responses_using_executor_return_promise ():
561
568
class TestExecutor (object ):
562
569
called = False
563
570
waited = False
@@ -583,10 +590,61 @@ def execute(self, fn, *args, **kwargs):
583
590
return_promise = True ,
584
591
)
585
592
593
+ assert isinstance (result_promises , list )
594
+ assert len (result_promises ) == 1
595
+ assert isinstance (result_promises [0 ], Promise )
586
596
results = Promise .all (result_promises ).get ()
587
597
588
598
assert as_dicts (results ) == [{"data" : {"test" : "Hello World" }}]
589
599
assert params == [RequestParams (query = query , variables = None , operation_name = None )]
590
600
assert TestExecutor .called
591
601
assert not TestExecutor .waited
592
602
assert TestExecutor .cleaned
603
+
604
+
605
+ def test_syntax_error_using_executor_return_promise ():
606
+ class TestExecutor (object ):
607
+ called = False
608
+ waited = False
609
+ cleaned = False
610
+
611
+ def wait_until_finished (self ):
612
+ TestExecutor .waited = True
613
+
614
+ def clean (self ):
615
+ TestExecutor .cleaned = True
616
+
617
+ def execute (self , fn , * args , ** kwargs ):
618
+ TestExecutor .called = True
619
+ return fn (* args , ** kwargs )
620
+
621
+ query = "this is a syntax error"
622
+ result_promises , params = run_http_query (
623
+ schema ,
624
+ "get" ,
625
+ {},
626
+ dict (query = query ),
627
+ executor = TestExecutor (),
628
+ return_promise = True ,
629
+ )
630
+
631
+ assert isinstance (result_promises , list )
632
+ assert len (result_promises ) == 1
633
+ assert isinstance (result_promises [0 ], Promise )
634
+ results = Promise .all (result_promises ).get ()
635
+
636
+ assert isinstance (results , list )
637
+ assert len (results ) == 1
638
+ result = results [0 ]
639
+ assert isinstance (result , ExecutionResult )
640
+
641
+ assert result .data is None
642
+ assert isinstance (result .errors , list )
643
+ assert len (result .errors ) == 1
644
+ error = result .errors [0 ]
645
+ assert isinstance (error , GraphQLSyntaxError )
646
+
647
+ assert params == [RequestParams (query = query , variables = None , operation_name = None )]
648
+ assert not TestExecutor .called
649
+ assert not TestExecutor .waited
650
+ assert not TestExecutor .cleaned
0 commit comments