@@ -2608,7 +2608,7 @@ def test_has_iam_mixin():
2608
2608
assert api_schema .has_iam_mixin
2609
2609
2610
2610
2611
- def get_file_descriptor_proto_for_method_settings_tests (
2611
+ def get_file_descriptor_proto_for_tests (
2612
2612
fields : Sequence [descriptor_pb2 .FieldDescriptorProto ] = None ,
2613
2613
client_streaming : bool = False ,
2614
2614
server_streaming : bool = False ,
@@ -2621,7 +2621,7 @@ def get_file_descriptor_proto_for_method_settings_tests(
2621
2621
`descriptor_pb2.FileDescriptorProto` should use client streaming.
2622
2622
server_streaming (bool): Whether the methods in the return object
2623
2623
`descriptor_pb2.FileDescriptorProto` should use server streaming.
2624
- Return :
2624
+ Returns :
2625
2625
descriptor_pb2.FileDescriptorProto: Returns an object describing the API.
2626
2626
"""
2627
2627
@@ -2686,7 +2686,7 @@ def test_api_all_methods():
2686
2686
Tests the `all_methods` method of `gapic.schema.api` method which returns a map of
2687
2687
all methods for the API.
2688
2688
"""
2689
- fd = get_file_descriptor_proto_for_method_settings_tests ()
2689
+ fd = get_file_descriptor_proto_for_tests ()
2690
2690
api_schema = api .API .build (fd , "google.example.v1beta1" )
2691
2691
assert len (api_schema .all_methods ) == 2
2692
2692
assert list (api_schema .all_methods .keys ()) == [
@@ -2695,6 +2695,58 @@ def test_api_all_methods():
2695
2695
]
2696
2696
2697
2697
2698
+ def test_read_python_settings_from_service_yaml ():
2699
+ service_yaml_config = {
2700
+ "apis" : [
2701
+ {"name" : "google.example.v1beta1.ServiceOne.Example1" },
2702
+ ],
2703
+ "publishing" : {
2704
+ "library_settings" : [
2705
+ {
2706
+ "version" : "google.example.v1beta1" ,
2707
+ "python_settings" : {
2708
+ "experimental_features" : {"rest_async_io_enabled" : True },
2709
+ },
2710
+ }
2711
+ ]
2712
+ },
2713
+ }
2714
+ cli_options = Options (service_yaml_config = service_yaml_config )
2715
+ fd = get_file_descriptor_proto_for_tests (fields = [])
2716
+ api_schema = api .API .build (fd , "google.example.v1beta1" , opts = cli_options )
2717
+ assert api_schema .all_library_settings == {
2718
+ "google.example.v1beta1" : client_pb2 .ClientLibrarySettings (
2719
+ version = "google.example.v1beta1" ,
2720
+ python_settings = client_pb2 .PythonSettings (
2721
+ experimental_features = client_pb2 .PythonSettings .ExperimentalFeatures (
2722
+ rest_async_io_enabled = True
2723
+ )
2724
+ ),
2725
+ )
2726
+ }
2727
+
2728
+
2729
+ def test_python_settings_duplicate_version_raises_error ():
2730
+ """
2731
+ Test that `ClientLibrarySettingsError` is raised when there are duplicate versions in
2732
+ `client_pb2.ClientLibrarySettings`.
2733
+ """
2734
+ fd = get_file_descriptor_proto_for_tests ()
2735
+ api_schema = api .API .build (fd , "google.example.v1beta1" )
2736
+ clientlibrarysettings = [
2737
+ client_pb2 .ClientLibrarySettings (
2738
+ version = "google.example.v1beta1" ,
2739
+ ),
2740
+ client_pb2 .ClientLibrarySettings (
2741
+ version = "google.example.v1beta1" ,
2742
+ ),
2743
+ ]
2744
+ with pytest .raises (
2745
+ api .ClientLibrarySettingsError , match = "(?i)duplicate version"
2746
+ ):
2747
+ api_schema .enforce_valid_library_settings (clientlibrarysettings )
2748
+
2749
+
2698
2750
def test_read_method_settings_from_service_yaml ():
2699
2751
"""
2700
2752
Tests the `gapic.schema.api.all_method_settings` method which reads
@@ -2730,7 +2782,7 @@ def test_read_method_settings_from_service_yaml():
2730
2782
name = "mollusc" , type = "TYPE_STRING" , options = field_options , number = 2
2731
2783
)
2732
2784
fields = [squid , mollusc ]
2733
- fd = get_file_descriptor_proto_for_method_settings_tests (fields = fields )
2785
+ fd = get_file_descriptor_proto_for_tests (fields = fields )
2734
2786
api_schema = api .API .build (fd , "google.example.v1beta1" , opts = cli_options )
2735
2787
assert api_schema .all_method_settings == {
2736
2788
"google.example.v1beta1.ServiceOne.Example1" : client_pb2 .MethodSettings (
@@ -2746,7 +2798,7 @@ def test_method_settings_duplicate_selector_raises_error():
2746
2798
Test that `MethodSettingsError` is raised when there are duplicate selectors in
2747
2799
`client_pb2.MethodSettings`.
2748
2800
"""
2749
- fd = get_file_descriptor_proto_for_method_settings_tests ()
2801
+ fd = get_file_descriptor_proto_for_tests ()
2750
2802
api_schema = api .API .build (fd , "google.example.v1beta1" )
2751
2803
methodsettings = [
2752
2804
client_pb2 .MethodSettings (
@@ -2770,7 +2822,7 @@ def test_method_settings_invalid_selector_raises_error():
2770
2822
method_example1 = "google.example.v1beta1.DoesNotExist.Example1"
2771
2823
method_example2 = "google.example.v1beta1.ServiceOne.DoesNotExist"
2772
2824
2773
- fd = get_file_descriptor_proto_for_method_settings_tests ()
2825
+ fd = get_file_descriptor_proto_for_tests ()
2774
2826
api_schema = api .API .build (fd , "google.example.v1beta1" )
2775
2827
methodsettings = [
2776
2828
client_pb2 .MethodSettings (
@@ -2802,7 +2854,7 @@ def test_method_settings_unsupported_auto_populated_field_type_raises_error():
2802
2854
`client_pb2.MethodSettings.auto_populated_fields` is not of type string.
2803
2855
"""
2804
2856
squid = make_field_pb2 (name = "squid" , type = "TYPE_INT32" , number = 1 )
2805
- fd = get_file_descriptor_proto_for_method_settings_tests (fields = [squid ])
2857
+ fd = get_file_descriptor_proto_for_tests (fields = [squid ])
2806
2858
api_schema = api .API .build (fd , "google.example.v1beta1" )
2807
2859
methodsettings = [
2808
2860
client_pb2 .MethodSettings (
@@ -2820,7 +2872,7 @@ def test_method_settings_auto_populated_field_not_found_raises_error():
2820
2872
`client_pb2.MethodSettings.auto_populated_fields` is not found in the top-level
2821
2873
request message of the selector.
2822
2874
"""
2823
- fd = get_file_descriptor_proto_for_method_settings_tests ()
2875
+ fd = get_file_descriptor_proto_for_tests ()
2824
2876
api_schema = api .API .build (fd , "google.example.v1beta1" )
2825
2877
methodsettings = [
2826
2878
client_pb2 .MethodSettings (
@@ -2846,7 +2898,7 @@ def test_method_settings_auto_populated_nested_field_raises_error():
2846
2898
type = 'TYPE_MESSAGE' ,
2847
2899
)
2848
2900
2849
- fd = get_file_descriptor_proto_for_method_settings_tests (
2901
+ fd = get_file_descriptor_proto_for_tests (
2850
2902
fields = [octopus .field_pb ]
2851
2903
)
2852
2904
api_schema = api .API .build (fd , "google.example.v1beta1" )
@@ -2865,7 +2917,7 @@ def test_method_settings_auto_populated_field_client_streaming_rpc_raises_error(
2865
2917
Test that `MethodSettingsError` is raised when the selector in
2866
2918
`client_pb2.MethodSettings.selector` maps to a method which uses client streaming.
2867
2919
"""
2868
- fd = get_file_descriptor_proto_for_method_settings_tests (
2920
+ fd = get_file_descriptor_proto_for_tests (
2869
2921
client_streaming = True
2870
2922
)
2871
2923
api_schema = api .API .build (fd , "google.example.v1beta1" )
@@ -2886,7 +2938,7 @@ def test_method_settings_auto_populated_field_server_streaming_rpc_raises_error(
2886
2938
Test that `MethodSettingsError` is raised when the selector in
2887
2939
`client_pb2.MethodSettings.selector` maps to a method which uses server streaming.
2888
2940
"""
2889
- fd = get_file_descriptor_proto_for_method_settings_tests (
2941
+ fd = get_file_descriptor_proto_for_tests (
2890
2942
server_streaming = True
2891
2943
)
2892
2944
api_schema = api .API .build (fd , "google.example.v1beta1" )
@@ -2914,7 +2966,7 @@ def test_method_settings_unsupported_auto_populated_field_behavior_raises_error(
2914
2966
squid = make_field_pb2 (
2915
2967
name = "squid" , type = "TYPE_STRING" , options = field_options , number = 1
2916
2968
)
2917
- fd = get_file_descriptor_proto_for_method_settings_tests (fields = [squid ])
2969
+ fd = get_file_descriptor_proto_for_tests (fields = [squid ])
2918
2970
api_schema = api .API .build (fd , "google.example.v1beta1" )
2919
2971
methodsettings = [
2920
2972
client_pb2 .MethodSettings (
@@ -2936,7 +2988,7 @@ def test_method_settings_auto_populated_field_field_info_format_not_specified_ra
2936
2988
the format of the field is not specified.
2937
2989
"""
2938
2990
squid = make_field_pb2 (name = "squid" , type = "TYPE_STRING" , number = 1 )
2939
- fd = get_file_descriptor_proto_for_method_settings_tests (fields = [squid ])
2991
+ fd = get_file_descriptor_proto_for_tests (fields = [squid ])
2940
2992
api_schema = api .API .build (fd , "google.example.v1beta1" )
2941
2993
methodsettings = [
2942
2994
client_pb2 .MethodSettings (
@@ -2962,7 +3014,7 @@ def test_method_settings_unsupported_auto_populated_field_field_info_format_rais
2962
3014
squid = make_field_pb2 (
2963
3015
name = "squid" , type = "TYPE_STRING" , options = field_options , number = 1
2964
3016
)
2965
- fd = get_file_descriptor_proto_for_method_settings_tests (fields = [squid ])
3017
+ fd = get_file_descriptor_proto_for_tests (fields = [squid ])
2966
3018
api_schema = api .API .build (fd , "google.example.v1beta1" )
2967
3019
methodsettings = [
2968
3020
client_pb2 .MethodSettings (
@@ -3001,7 +3053,7 @@ def test_method_settings_invalid_multiple_issues():
3001
3053
# Field Octopus Errors
3002
3054
# - Not annotated with google.api.field_info.format = UUID4
3003
3055
octopus = make_field_pb2 (name = "octopus" , type = "TYPE_STRING" , number = 1 )
3004
- fd = get_file_descriptor_proto_for_method_settings_tests (
3056
+ fd = get_file_descriptor_proto_for_tests (
3005
3057
fields = [squid , octopus ]
3006
3058
)
3007
3059
api_schema = api .API .build (fd , "google.example.v1beta1" )
0 commit comments