1
1
import pytest
2
2
3
- from airbyte_cdk .utils .mapping_helpers import combine_mappings
3
+ from airbyte_cdk .utils .mapping_helpers import (
4
+ RequestOption ,
5
+ RequestOptionType ,
6
+ _validate_component_request_option_paths ,
7
+ combine_mappings ,
8
+ )
4
9
5
10
6
11
@pytest .mark .parametrize (
@@ -46,14 +51,14 @@ def test_string_handling(test_name, mappings, expected_result, expected_error):
46
51
@pytest .mark .parametrize (
47
52
"test_name, mappings, expected_error" ,
48
53
[
49
- ("duplicate_keys_same_value" , [{"a" : 1 }, {"a" : 1 }], "Duplicate keys found " ),
50
- ("duplicate_keys_different_value" , [{"a" : 1 }, {"a" : 2 }], "Duplicate keys found " ),
54
+ ("duplicate_keys_same_value" , [{"a" : 1 }, {"a" : 1 }], "duplicate keys detected " ),
55
+ ("duplicate_keys_different_value" , [{"a" : 1 }, {"a" : 2 }], "duplicate keys detected " ),
51
56
(
52
57
"nested_structure_not_allowed" ,
53
58
[{"a" : {"b" : 1 }}, {"a" : {"c" : 2 }}],
54
- "Duplicate keys found " ,
59
+ "duplicate keys detected " ,
55
60
),
56
- ("any_nesting_not_allowed" , [{"a" : {"b" : 1 }}, {"a" : {"d" : 2 }}], "Duplicate keys found " ),
61
+ ("any_nesting_not_allowed" , [{"a" : {"b" : 1 }}, {"a" : {"d" : 2 }}], "duplicate keys detected " ),
57
62
],
58
63
)
59
64
def test_non_body_json_requests (test_name , mappings , expected_error ):
@@ -96,13 +101,13 @@ def test_non_body_json_requests(test_name, mappings, expected_error):
96
101
"nested_conflict" ,
97
102
[{"a" : {"b" : 1 }}, {"a" : {"b" : 2 }}],
98
103
None ,
99
- "Duplicate keys found " ,
104
+ "duplicate keys detected " ,
100
105
),
101
106
(
102
107
"type_conflict" ,
103
108
[{"a" : 1 }, {"a" : {"b" : 2 }}],
104
109
None ,
105
- "Duplicate keys found " ,
110
+ "duplicate keys detected " ,
106
111
),
107
112
],
108
113
)
@@ -113,3 +118,104 @@ def test_body_json_requests(test_name, mappings, expected_result, expected_error
113
118
combine_mappings (mappings , allow_same_value_merge = True )
114
119
else :
115
120
assert combine_mappings (mappings , allow_same_value_merge = True ) == expected_result
121
+
122
+
123
+ @pytest .fixture
124
+ def mock_config () -> dict [str , str ]:
125
+ return {"test" : "config" }
126
+
127
+
128
+ @pytest .mark .parametrize (
129
+ "test_name, option1, option2, should_raise" ,
130
+ [
131
+ (
132
+ "different_fields" ,
133
+ RequestOption (
134
+ field_name = "field1" , inject_into = RequestOptionType .body_json , parameters = {}
135
+ ),
136
+ RequestOption (
137
+ field_name = "field2" , inject_into = RequestOptionType .body_json , parameters = {}
138
+ ),
139
+ False ,
140
+ ),
141
+ (
142
+ "same_field_name_header" ,
143
+ RequestOption (field_name = "field" , inject_into = RequestOptionType .header , parameters = {}),
144
+ RequestOption (field_name = "field" , inject_into = RequestOptionType .header , parameters = {}),
145
+ True ,
146
+ ),
147
+ (
148
+ "different_nested_paths" ,
149
+ RequestOption (
150
+ field_path = ["data" , "query1" , "limit" ],
151
+ inject_into = RequestOptionType .body_json ,
152
+ parameters = {},
153
+ ),
154
+ RequestOption (
155
+ field_path = ["data" , "query2" , "limit" ],
156
+ inject_into = RequestOptionType .body_json ,
157
+ parameters = {},
158
+ ),
159
+ False ,
160
+ ),
161
+ (
162
+ "same_nested_paths" ,
163
+ RequestOption (
164
+ field_path = ["data" , "query" , "limit" ],
165
+ inject_into = RequestOptionType .body_json ,
166
+ parameters = {},
167
+ ),
168
+ RequestOption (
169
+ field_path = ["data" , "query" , "limit" ],
170
+ inject_into = RequestOptionType .body_json ,
171
+ parameters = {},
172
+ ),
173
+ True ,
174
+ ),
175
+ (
176
+ "different_inject_types" ,
177
+ RequestOption (field_name = "field" , inject_into = RequestOptionType .header , parameters = {}),
178
+ RequestOption (
179
+ field_name = "field" , inject_into = RequestOptionType .body_json , parameters = {}
180
+ ),
181
+ False ,
182
+ ),
183
+ ],
184
+ )
185
+ def test_request_option_validation (test_name , option1 , option2 , should_raise , mock_config ):
186
+ """Test various combinations of request option validation"""
187
+ if should_raise :
188
+ with pytest .raises (ValueError , match = "duplicate keys detected" ):
189
+ _validate_component_request_option_paths (mock_config , option1 , option2 )
190
+ else :
191
+ _validate_component_request_option_paths (mock_config , option1 , option2 )
192
+
193
+
194
+ @pytest .mark .parametrize (
195
+ "test_name, options" ,
196
+ [
197
+ (
198
+ "none_options" ,
199
+ [
200
+ None ,
201
+ RequestOption (
202
+ field_name = "field" , inject_into = RequestOptionType .header , parameters = {}
203
+ ),
204
+ None ,
205
+ ],
206
+ ),
207
+ (
208
+ "single_option" ,
209
+ [
210
+ RequestOption (
211
+ field_name = "field" , inject_into = RequestOptionType .header , parameters = {}
212
+ )
213
+ ],
214
+ ),
215
+ ("all_none" , [None , None , None ]),
216
+ ("empty_list" , []),
217
+ ],
218
+ )
219
+ def test_edge_cases (test_name , options , mock_config ):
220
+ """Test edge cases like None values and single options"""
221
+ _validate_component_request_option_paths (mock_config , * options )
0 commit comments