forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_graphql_queries.py
1278 lines (934 loc) · 58.6 KB
/
test_graphql_queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import pytest
import ruamel.yaml as yaml
import textwrap
import warnings
from context import PytestConf
from validate import assert_response_code, check_query_f, get_conf_f
usefixtures = pytest.mark.usefixtures
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('bigquery')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBasicBigquery:
def test_empty_perms(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/empty_perms.yaml", transport)
def test_timestamp_perm(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/timestamp_perm.yaml", transport)
def test_exact_article_id(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/exact_article_id.yaml", transport)
def test_perms_published_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/perms_published_articles.yaml", transport)
# types
def test_select_query_all_types(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_query_all_types.yaml", transport)
# batching # works only with http, not with websocket
def test_select_query_batching(self, hge_ctx, transport):
if transport == 'http':
check_query_f(hge_ctx, self.dir() + "/select_query_batching.yaml", transport)
def test_select_query_batching_with_one_error(self, hge_ctx, transport):
if transport == 'http':
check_query_f(hge_ctx, self.dir() + "/select_query_batching_with_one_error.yaml", transport)
# fragments
def test_select_query_top_level_fragment(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_top_level_fragment.yaml', transport)
def test_select_query_nested_fragment(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_nested_fragment.yaml', transport)
def test_select_query_fragment_cycles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_fragment_cycles.yaml', transport)
def test_select_query_fragment_with_variable(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_fragment_with_variable.yaml', transport)
# invalid # this is not applicable to bigquery, it simply returns empty results
def test_select_query_invalid_escape_sequence(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_query_invalid_escape_sequence.yaml", transport)
# aggregates
def test_select_join_provenance_queries(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_join_provenance.yaml", transport)
# offsets
def test_offset_regression(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/offset_regression.yaml", transport)
# BigQuery-specific configuration: global_limit
def test_global_limit(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/global_limit.yaml", transport)
def test_basic_remote_join(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/basic_remote_joins.yaml", transport)
def test_nested_array_relationships(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/nested_array_relationships.yaml", transport)
def test_agg_nodes(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/agg_nodes.yaml", transport)
def test_distinct_on(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/distinct_on.yaml", transport)
# Timestamp value parsing, https://github.com/hasura/graphql-engine/issues/8076
def test_timestamp_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/timestamp_filter.yaml", transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/bigquery'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('bigquery')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpSearchBigquery:
def test_city_where_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_like_bigquery.yaml', transport)
def test_city_where_not_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_nlike_bigquery.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/search'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('citus', 'mssql', 'postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBasicPostgresMSSQLCitus:
def test_select_query_multiple_columns_arr_fkey(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_multiple_columns_arr_fkey.yaml", transport)
def test_select_query_multiple_columns_obj_fkey(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_multiple_columns_obj_fkey.yaml", transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('mssql')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBasicMSSQL:
def test_select_various_mssql_types(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_test_types_mssql.yaml', transport)
def test_select_query_user_col_change(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_query_user_col_change_mssql.yaml")
def test_nodes_aggregates_mssql(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/nodes_aggregates_mssql.yaml", transport)
def test_nodes_aggregates_conditions_mssql(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/nodes_aggregates_conditions_mssql.yaml", transport)
def test_author_with_permission(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_with_permission_mssql.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBasicPostgres:
def test_select_various_postgres_types(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_test_types_postgres.yaml', transport)
def test_select_query_invalid_escape_sequence(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/select_query_invalid_escape_sequence.yaml", transport)
def test_nested_select_with_foreign_key_alter(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/nested_select_with_foreign_key_alter.yaml", transport)
def test_select_query_user_col_change(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_query_user_col_change_postgres.yaml")
def test_select_query_person_citext(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_query_person_citext.yaml", transport)
def test_select_query_batching(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/select_query_batching.yaml", transport)
def test_select_query_batching_with_mutation(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/select_query_batching_with_mutation.yaml", transport)
def test_select_query_batching_with_one_error(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/select_query_batching_with_one_error.yaml", transport)
def test_create_invalid_fkey_relationship(self, hge_ctx, transport):
resp = hge_ctx.v1q_f(self.dir() + '/setup_invalid_fkey_relationship.yaml', expected_status_code = 400)
assert resp['error'] == "Expecting object { table, columns }."
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('citus', 'postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryFragmentsPostgresCitus:
def test_select_query_top_level_fragment(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_top_level_fragment.yaml', transport)
def test_select_query_nested_fragment(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_nested_fragment.yaml', transport)
def test_select_query_fragment_cycles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_fragment_cycles.yaml', transport)
def test_select_query_fragment_with_variable(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_fragment_with_variable.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryAgg:
def test_article_agg_count_sum_avg_max_min_with_aliases(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_count_sum_avg_max_min_with_aliases.yaml', transport)
def test_article_agg_where(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_where.yaml', transport)
def test_author_agg_with_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_agg_with_articles.yaml', transport)
def test_author_agg_with_articles_where(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_agg_with_articles_where.yaml', transport)
def test_article_deeply_nested_aggregate(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_deeply_nested_aggregate.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/aggregations'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('mssql', 'postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryAggPermPostgresMSSQL:
def test_author_agg_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_agg_articles.yaml', transport)
def test_article_agg_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_fail.yaml', transport)
def test_author_articles_agg_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_articles_agg_fail.yaml', transport)
def test_author_post_agg_order_by(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_post_agg_order_by.yaml', transport)
def test_article_agg_without_select_access_to_any_col(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_with_role_without_select_access.yaml', transport)
def test_article_agg_with_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_with_filter.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/agg_perm'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryAggPermPostgres:
# This test should be part of TestGraphQLQueryAggPermCommon and it is not because of
# known issue with sql server aggregate count query on multiple columns.
# Refer https://github.com/hasura/graphql-engine/issues/7873
# Move the test to above said class when the issue is fixed.
def test_article_agg_with_select_access(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article_agg_with_role_with_select_access.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/agg_perm'
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryLimits:
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_limit_1(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_limit_1.yaml', transport)
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_limit_2(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_limit_2.yaml', transport)
def test_limit_null(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/select_query_article_limit_null.yaml')
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_err_str_limit_error(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_string_limit_error.yaml', transport)
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_err_neg_limit_error(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_neg_limit_error.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/limits'
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryOffsets:
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_offset_1_limit_2(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_offset_1_limit_2.yaml', transport)
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_offset_2_limit_1(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_offset_2_limit_1.yaml', transport)
@pytest.mark.parametrize("transport", ['http', 'websocket'])
def test_int_as_string_offset(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_article_string_offset.yaml', transport)
def test_err_neg_offset_error(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/select_query_article_neg_offset_error.yaml')
@classmethod
def dir(cls):
return 'queries/graphql_query/offset'
@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription'])
@pytest.mark.backend('mssql', 'postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpBasicPostgresMSSQL:
def test_order_delivered_at_is_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_order_delivered_at_is_null.yaml', transport)
def test_order_delivered_at_is_not_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_order_delivered_at_is_not_null.yaml', transport)
def test_author_article_where_not_equal(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_neq.yaml', transport)
def test_author_article_where_greater_than(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_gt.yaml', transport)
def test_author_article_where_greater_than_or_equal(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_gte.yaml', transport)
def test_author_article_where_less_than(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_lt.yaml', transport)
def test_author_article_where_not_less_than(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_not_lt.yaml', transport)
def test_author_article_where_less_than_or_equal(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_lte.yaml', transport)
def test_article_author_is_published_and_registered(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_article_author_is_published_and_registered.yaml', transport)
def test_article_author_not_published_nor_registered(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_article_author_not_published_or_not_registered.yaml', transport)
def test_author_article_where_in(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_in.yaml', transport)
def test_author_article_where_nin(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_nin.yaml', transport)
def test_author_article_where_permissions(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_permissions.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpBasicPostgres:
def test_author_article_operator_ne_not_found_err(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_operator_ne_not_found_err_postgres.yaml', transport)
def test_author_article_where_in_empty_array(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_in_empty_array_postgres.yaml', transport)
def test_author_article_where_nin_empty_array(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_where_nin_empty_array_postgres.yaml', transport)
def test_article_author_unexpected_operator_in_where_err(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_unexpected_operator_in_where_err_postgres.yaml', transport)
def test_uuid_test_in_uuid_col(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_uuid_test_in_uuid_col_postgres.yaml', transport)
def test_self_referential_relationships(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/self_referential_relationships.yaml', transport)
def test_query_account_permission_success(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_account_permission_success.yaml', transport)
def test_query_account_permission_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_account_permission_fail.yaml', transport)
def test_in_sql_identifier_array(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/in_sql_identifier_array.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('mssql')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpBasicMSSQL:
def test_author_article_operator_ne_not_found_err(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_operator_ne_not_found_err_mssql.yaml', transport)
def test_article_author_unexpected_operator_in_where_err(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_unexpected_operator_in_where_err_mssql.yaml', transport)
def test_uuid_test_in_uuid_col(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_uuid_test_in_uuid_col_mssql.yaml', transport)
def test_bools(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_bools_mssql.yaml', transport)
def test_create_invalid_fkey_relationship(self, hge_ctx, transport):
resp = hge_ctx.v1metadataq_f(self.dir() + '/setup_invalid_fkey_relationship_mssql.yaml', expected_status_code = 400)
assert resp['error'] == "Error when parsing command create_array_relationship.\nSee our documentation at https://hasura.io/docs/latest/graphql/core/api-reference/metadata-api/index.html#metadata-apis.\nInternal error message: Expecting object { table, columns }."
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphqlQueryPermissions:
def test_user_select_unpublished_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_select_query_unpublished_articles.yaml', transport)
def test_user_select_query_article_author(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_select_query_article_author.yaml', transport)
def test_user_only_other_users_published_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_can_query_other_users_published_articles.yaml', transport)
def test_anonymous_only_published_articles(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/anonymous_can_only_get_published_articles.yaml', transport)
def test_anonymous_only_published_articles_v1alpha1(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/anonymous_can_only_get_published_articles_v1alpha1.yaml', transport)
def test_user_cannot_access_remarks_col(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_cannot_access_remarks_col.yaml', transport)
def test_user_can_query_geometry_values_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_can_query_geometry_values_filter.yaml', transport)
def test_user_can_query_geometry_values_filter_session_vars(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_can_query_geometry_values_filter_session_vars.yaml', transport)
def test_user_can_query_jsonb_values_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_can_query_jsonb_values_filter.yaml', transport)
def test_user_can_query_jsonb_values_filter_session_vars(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_can_query_jsonb_values_filter_session_vars.yaml', transport)
def test_artist_select_query_Track_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/artist_select_query_Track_fail.yaml', transport)
def test_artist_select_query_Track(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/artist_select_query_Track.yaml', transport)
def test_artist_search_tracks(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/artist_search_tracks.yaml', transport)
def test_artist_search_tracks_aggregate(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/artist_search_tracks_aggregate.yaml', transport)
def test_staff_passed_students(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/staff_passed_students.yaml', transport)
def test_user_query_auction(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_query_auction.yaml', transport)
# FIXME: This test fails nondeterministically: strict=false doesn't seem to
# work on CI, so just disable for now:
# @pytest.mark.xfail(reason="Refer https://github.com/hasura/graphql-engine-internal/issues/252")
# def test_jsonb_has_all(self, hge_ctx, transport):
# check_query_f(hge_ctx, self.dir() + '/jsonb_has_all.yaml', transport)
def test_jsonb_has_any(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/jsonb_has_any.yaml', transport)
def test_in_and_nin(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/in_and_nin.yaml', transport)
def test_iregex(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/iregex.yaml', transport)
def test_user_accessing_books_by_pk_should_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/user_should_not_be_able_to_access_books_by_pk.yaml')
def test_author_articles_without_required_headers_set(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_articles_without_required_headers.yaml', transport)
def test_reader_author(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/reader_author.yaml', transport)
def test_tutor_get_students(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/tutor_get_students.yaml', transport)
def test_tutor_get_students_session(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/tutor_get_students_session.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/permissions'
# These tests only test the schema specific stuff which will
# be common across all the backends, to add DB specific tests
# look for the TestGraphQLInheritedRoles<backend> test classes
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLInheritedRolesSchema:
@classmethod
def dir(cls):
return 'queries/graphql_query/permissions/inherited_roles'
setup_metadata_api_version = "v2"
def test_basic_inherited_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/basic_inherited_roles.yaml')
def test_inherited_role_when_some_roles_may_not_have_permission_configured(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/inherited_role_with_some_roles_having_no_permissions.yaml')
def test_throw_error_when_roles_form_a_cycle(self, hge_ctx, transport):
export_metadata_query = {
"type": "export_metadata",
"args": {}
}
resp = hge_ctx.v1q(export_metadata_query)
circular_roles_metadata = [
{
"role_name": "intermediate_circular_role_1",
"role_set": [
"manager_employee",
"circular_role"
]
},
{
"role_name": "intermediate_circular_role_2",
"role_set": [
"intermediate_circular_role_1",
"employee"
]
},
{
"role_name": "circular_role",
"role_set": [
"intermediate_circular_role_2",
"author"
]
}
]
resp["inherited_roles"] = resp["inherited_roles"] + circular_roles_metadata
import_metadata_query = {
"type": "replace_metadata",
"args": {
"metadata": resp
}
}
resp = hge_ctx.v1q(import_metadata_query, expected_status_code = 400)
assert resp['error'] == '''found cycle(s) in roles: ["circular_role","intermediate_circular_role_2","intermediate_circular_role_1","circular_role"]'''
def test_explicit_metadata_permission_should_override_role_inheritance(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/override_inherited_permission.yaml')
def test_inherited_role_inherits_from_inherited_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/inherited_role_parent_is_another_inherited_role.yaml')
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLInheritedRolesPostgres:
@classmethod
def dir(cls):
return 'queries/graphql_query/permissions/inherited_roles'
setup_metadata_api_version = "v2"
def test_basic_inherited_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/basic_inherited_roles.yaml')
def test_inherited_role_when_some_roles_may_not_have_permission_configured(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/inherited_role_with_some_roles_having_no_permissions.yaml')
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@pytest.mark.backend('mssql')
@usefixtures('per_class_tests_db_state')
class TestGraphQLInheritedRolesMSSQL:
@classmethod
def dir(cls):
return 'queries/graphql_query/permissions/inherited_roles_mssql'
def test_basic_inherited_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/basic_inherited_roles.yaml')
def test_inherited_role_when_some_roles_may_not_have_permission_configured(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/inherited_role_with_some_roles_having_no_permissions.yaml')
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.backend('postgres')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpSearchPostgres:
def test_city_where_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_like.yaml', transport)
def test_city_where_not_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_nlike.yaml', transport)
def test_city_where_ilike(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_ilike_postgres.yaml', transport)
def test_city_where_not_ilike(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_nilike_postgres.yaml', transport)
def test_city_where_similar(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_similar_postgres.yaml', transport)
def test_city_where_not_similar(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_not_similar_postgres.yaml', transport)
def test_city_where_regex(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_regex_postgres.yaml', transport)
def test_city_where_nregex(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_nregex_postgres.yaml', transport)
def test_city_where_iregex(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_iregex_postgres.yaml', transport)
def test_city_where_niregex(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_niregex_postgres.yaml', transport)
def test_project_where_ilike(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_project_where_ilike_postgres.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/search'
@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription'])
@pytest.mark.backend('mssql')
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpSearchMSSQL:
def test_city_where_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_like_mssql.yaml', transport)
def test_city_where_not_like(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_city_where_nlike_mssql.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/search'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryBoolExpJsonB:
def test_query_cast_geometry_to_geography(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_cast_jsonb_to_string.yaml', transport)
def test_jsonb_contains_article_latest(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_article_author_jsonb_contains_latest.yaml', transport)
def test_jsonb_contains_article_beststeller(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_author_article_jsonb_contains_bestseller.yaml', transport)
def test_jsonb_contained_in_latest(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_article_author_jsonb_contained_in_latest.yaml', transport)
def test_jsonb_contained_in_bestseller_latest(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_article_author_jsonb_contained_in_bestseller_latest.yaml', transport)
def test_jsonb_has_key_sim_type(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_product_jsonb_has_key_sim_type.yaml', transport)
def test_jsonb_has_keys_any_os_operating_system(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_product_jsonb_has_keys_any_os_operating_system.yaml', transport)
def test_jsonb_has_keys_all_touchscreen_ram(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_product_jsonb_has_keys_all_ram_touchscreen.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/jsonb'
@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription'])
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryBoolExpPostGIS:
def test_query_using_point(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_using_point.yaml', transport)
def test_query_using_line(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_using_line.yaml', transport)
def test_query_using_polygon(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_using_polygon.yaml', transport)
def test_query_geography_spatial_ops(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_geography_spatial_ops.yaml', transport)
def test_query_geometry_3d_spatial_ops(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_geometry_3d_spatial_ops.yaml', transport)
def test_query_cast_geometry_to_geography(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_cast_geometry_to_geography.yaml', transport)
def test_query_cast_geography_to_geometry(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_cast_geography_to_geometry.yaml', transport)
def test_query_illegal_cast_is_not_allowed(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_illegal_cast_is_not_allowed.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/postgis'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryBoolExpRaster:
def test_query_st_intersects_geom_nband(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_st_intersects_geom_nband.yaml', transport)
def test_query_st_intersects_geom_nband_no_rows(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_st_intersects_geom_nband_no_rows.yaml', transport)
def test_query_st_intersects_rast(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_st_intersects_rast.yaml', transport)
def test_query_st_intersects_rast_no_rows(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_st_intersects_rast_no_rows.yaml', transport)
def test_query_st_intersects_rast_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/query_st_intersects_rast_fail.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/boolexp/raster'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryOrderBy:
def test_articles_order_by_without_id(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/articles_order_by_without_id.yaml', transport)
def test_articles_order_by_rel_author_id(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/articles_order_by_rel_author_id.yaml', transport)
def test_articles_order_by_rel_author_rel_contact_phone(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/articles_order_by_rel_author_rel_contact_phone.yaml', transport)
def test_articles_order_by_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/articles_order_by_null.yaml', transport)
def test_album_order_by_tracks_count(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/album_order_by_tracks_count.yaml', transport)
def test_album_order_by_tracks_duration_avg(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/album_order_by_tracks_duration_avg.yaml', transport)
def test_album_order_by_tracks_max_name(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/album_order_by_tracks_max_name.yaml', transport)
def test_album_order_by_tracks_bytes_stddev(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/album_order_by_tracks_bytes_stddev.yaml', transport)
def test_employee_distinct_department_order_by_salary_desc(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/employee_distinct_department_order_by_salary_desc.yaml', transport)
def test_employee_distinct_department_order_by_salary_asc(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/employee_distinct_department_order_by_salary_asc.yaml', transport)
def test_employee_distinct_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/employee_distinct_fail.yaml', transport)
def test_album_order_by_tracks_tags(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/album_order_by_tracks_tags.yaml', transport)
def test_Track_order_by_size(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/Track_order_by_size.yaml', transport)
def test_author_order_by_get_articles_aggregate(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_order_by_get_articles_aggregate.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/order_by'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryCustomSchema:
def test_author(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author.yaml', transport)
def test_article(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/article.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/custom_schema'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryCustomTableName:
def test_author(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + 'author.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/custom_schema/custom_table_name/'
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryEnums:
@classmethod
def dir(cls):
return 'queries/graphql_query/enums'
def test_introspect(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/introspect.yaml', transport)
def test_introspect_user_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/introspect_user_role.yaml', transport)
def test_select_enum_field(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_enum_field.yaml', transport)
def test_select_where_enum_eq(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq.yaml', transport)
def test_select_where_enum_eq_bad_value(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_bad_value.yaml', transport)
def test_select_where_enum_eq_string(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_string.yaml', transport)
def test_select_where_enum_eq_variable(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_variable.yaml', transport)
def test_select_where_enum_eq_variable_bad_value(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_variable_bad_value.yaml', transport)
def test_select_where_enum_eq_without_enum_table_visibility(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_without_enum_table_visibility.yaml', transport)
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryComputedFields:
@classmethod
def dir(cls):
return 'queries/graphql_query/computed_fields'
def test_computed_fields(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/computed_fields.yaml', transport)
def test_computed_fields_permission(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/computed_fields_permission.yaml', transport)
def test_locations(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/locations.yaml', transport)
def test_float_test(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/float_test.yaml', transport)
def test_tracked_function_as_computed_field(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/tracked_function_as_comp_field.yaml')
def test_scalar_computed_field_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/scalar_computed_field_filter.yaml')
def test_table_computed_field_filter(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/table_computed_field_filter.yaml')
def test_table_computed_field_filter_fail(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/table_computed_field_filter_fail.yaml')
def test_table_computed_field_filter_session_argument(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/table_computed_field_filter_session_argument.yaml')
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
class TestGraphQLQueryCaching:
@classmethod
def dir(cls):
return 'queries/graphql_query/caching'
def test_include_directive(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/include_directive.yaml', transport)
def test_introspection(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/introspection.yaml', transport)
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
@pytest.mark.admin_secret
@pytest.mark.hge_env('HASURA_GRAPHQL_UNAUTHORIZED_ROLE', 'anonymous')
class TestUnauthorizedRolePermission:
@classmethod
def dir(cls):
return 'queries/unauthorized_role'
def test_unauth_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/unauthorized_role.yaml', transport, False)
@usefixtures('per_class_tests_db_state')
@pytest.mark.admin_secret
@pytest.mark.hge_env('HASURA_GRAPHQL_UNAUTHORIZED_ROLE', 'anonymous')
class TestFallbackUnauthorizedRoleCookie:
@classmethod
def dir(cls):
return 'queries/unauthorized_role'
def test_fallback_unauth_role_jwt_cookie_not_set(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/cookie_header_absent_unauth_role_set.yaml', add_auth=False)
@usefixtures('per_class_tests_db_state', 'jwt_configuration')
@pytest.mark.admin_secret
@pytest.mark.jwt('rsa')
@pytest.mark.hge_env('HASURA_GRAPHQL_UNAUTHORIZED_ROLE', 'anonymous')
class TestFallbackUnauthorizedRoleCookieWithJwt:
@classmethod
def dir(cls):
return 'queries/unauthorized_role'
def test_fallback_unauth_role_jwt_cookie_not_set(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/cookie_header_absent_unauth_role_set.yaml', add_auth=False)
@usefixtures('per_class_tests_db_state', 'jwt_configuration')
@pytest.mark.admin_secret
@pytest.mark.jwt('rsa')
class TestMissingUnauthorizedRoleAndCookie:
@classmethod
def dir(cls):
return 'queries/unauthorized_role'
def test_error_unauth_role_not_set_jwt_cookie_not_set(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/cookie_header_absent_unauth_role_not_set.yaml', add_auth=False)
@usefixtures('per_class_tests_db_state')
class TestGraphQLExplainPostgresMSSQL:
@classmethod
def dir(cls):
return 'queries/explain'
def test_simple_query_as_admin(self, hge_ctx):
q = {"query": {"query": "query abc { __typename }", "operationName": "abc"}}
hge_ctx.v1GraphqlExplain(q)
def test_simple_query_as_user(self, hge_ctx):
q = {"query": {"query": "query abc { __typename }", "operationName": "abc"}}
hge_ctx.v1GraphqlExplain(q, {"x-hasura-role": "random_user"}, expected_status_code = 400)
@pytest.mark.backend('postgres', 'mssql')
def test_simple_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + hge_ctx.backend_suffix('/simple_query') + ".yaml")
@pytest.mark.backend('postgres', 'mssql')
def test_permissions_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + hge_ctx.backend_suffix('/permissions_query') + ".yaml")
def test_limit_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + '/limit_query.yaml')
def test_limit_orderby_column_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + '/limit_orderby_column_query.yaml')
def test_limit_orderby_relationship_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + '/limit_orderby_relationship_query.yaml')
def test_limit_offset_orderby_relationship_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + '/limit_offset_orderby_relationship_query.yaml')
def test_orderby_array_relationship_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + '/orderby_array_relationship_query.yaml')
@pytest.mark.backend('postgres', 'mssql')
def test_documented_query(self, hge_ctx):
self.with_admin_secret("query", hge_ctx, self.dir() + hge_ctx.backend_suffix('/docs_query') + ".yaml")
@pytest.mark.backend('postgres', 'mssql')
def test_documented_subscription(self, hge_ctx):