@@ -881,3 +881,109 @@ def test_max_list_length(client):
881
881
# Test that above length yields error
882
882
r = client .post (url , json = {"v" : ["the" , "longest" , "of" , "lists" ]})
883
883
assert "error" in r .json
884
+
885
+
886
+ def test_list_json_schema (client ):
887
+ url = "/json/list/json_schema"
888
+ # Test that passing schema validation yields input
889
+ v = [{"user_id" : 1 , "first_name" : "John" , "last_name" : "Doe" , "tags" : ["test_account" ]}]
890
+ r = client .post (url , json = {"v" : v })
891
+ assert type (r .json ["v" ]) is list
892
+ assert len (r .json ["v" ]) == 1
893
+ assert type (r .json ["v" ][0 ]) is dict
894
+ assert v [0 ] == r .json ["v" ][0 ]
895
+ # Test that failing schema validation yields error
896
+ v = [{"user_id" : 1 , "first_name" : "John" , "last_name" : "Doe" }]
897
+ r = client .post (url , json = {"v" : v })
898
+ assert "error" in r .json
899
+
900
+
901
+ def test_required_dict (client ):
902
+ url = "/json/dict/required"
903
+ # Test that dict yields input
904
+ v = {"a" : "b" }
905
+ r = client .post (url , json = {"v" : v })
906
+ assert "v" in r .json
907
+ assert type (r .json ["v" ]) is dict
908
+ assert v == r .json ["v" ]
909
+ # Test that non-dict yields error
910
+ r = client .post (url , json = {"v" : "a" })
911
+ assert "error" in r .json
912
+
913
+
914
+ def test_optional_dict (client ):
915
+ url = "/json/dict/optional"
916
+ # Test that dict yields input
917
+ v = {"a" : "b" }
918
+ r = client .post (url , json = {"v" : v })
919
+ assert "v" in r .json
920
+ assert type (r .json ["v" ]) is dict
921
+ assert v == r .json ["v" ]
922
+ # Test that non-dict yields error
923
+ r = client .post (url , json = {"v" : "a" })
924
+ assert "error" in r .json
925
+ # Test that no input yields None
926
+ r = client .post (url )
927
+ assert "v" in r .json
928
+ assert r .json ["v" ] is None
929
+
930
+
931
+ def test_dict_default (client ):
932
+ url = "/json/dict/default"
933
+ # Test that present dict yields input values
934
+ n_opt = {"e" : "f" }
935
+ opt = {"g" : "h" }
936
+ r = client .post (url , json = {"n_opt" : n_opt , "opt" : opt })
937
+ assert "n_opt" in r .json
938
+ assert "opt" in r .json
939
+ assert type (r .json ["n_opt" ]) is dict
940
+ assert type (r .json ["opt" ]) is dict
941
+ assert n_opt == r .json ["n_opt" ]
942
+ assert opt == r .json ["opt" ]
943
+ # Test that missing dict yields default values
944
+ n_opt = {"a" : "b" }
945
+ opt = {"c" : "d" }
946
+ r = client .post (url )
947
+ assert "n_opt" in r .json
948
+ assert "opt" in r .json
949
+ assert type (r .json ["n_opt" ]) is dict
950
+ assert type (r .json ["opt" ]) is dict
951
+ assert n_opt == r .json ["n_opt" ]
952
+ assert opt == r .json ["opt" ]
953
+
954
+
955
+ def test_dict_func (client ):
956
+ url = "/json/dict/func"
957
+ # Test that dict passing func yields input value
958
+ v = {"a" : "b" , "c" : "d" }
959
+ r = client .post (url , json = {"v" : v })
960
+ assert "v" in r .json
961
+ assert type (r .json ["v" ]) is dict
962
+ assert v == r .json ["v" ]
963
+ # Test that dict failing func yields error
964
+ v = {"A" : "B" , "C" : "D" }
965
+ r = client .post (url , json = {"v" : v })
966
+ assert "error" in r .json
967
+
968
+
969
+ def test_dict_json_schema (client ):
970
+ url = "/json/dict/json_schema"
971
+ # Test that dict passing schema yields input value
972
+ v = {
973
+ "user_id" : 1 ,
974
+ "first_name" : "John" ,
975
+ "last_name" : "Doe" ,
976
+ "tags" : []
977
+ }
978
+ r = client .post (url , json = {"v" : v })
979
+ assert "v" in r .json
980
+ assert type (r .json ["v" ]) is dict
981
+ assert v == r .json ["v" ]
982
+ # Test that dict failing schema yields error
983
+ v = {
984
+ "user_id" : 1 ,
985
+ "first_name" : "John" ,
986
+ "last_name" : "Doe"
987
+ }
988
+ r = client .post (url , json = {"v" : v })
989
+ assert "error" in r .json
0 commit comments