|
11 | 11 | INCLUDE, |
12 | 12 | RAISE, |
13 | 13 | Schema, |
14 | | - missing, |
15 | 14 | pre_load, |
16 | 15 | validates_schema, |
17 | 16 | ) |
@@ -1119,21 +1118,30 @@ class ZeroTuple(fields.DelimitedTuple): |
1119 | 1118 | assert parsed["ids"] == (1, 0, 3) |
1120 | 1119 |
|
1121 | 1120 |
|
1122 | | -def test_delimited_list_using_missing_for_empty(web_request, parser): |
1123 | | - # this is "future" because we plan to make this the default for webargs v9.0 |
1124 | | - class FutureList(fields.DelimitedList): |
1125 | | - empty_value = missing |
1126 | | - |
| 1121 | +def test_delimited_list_missing_element_defaults_to_load_default(web_request, parser): |
1127 | 1122 | web_request.json = {"ids": "foo,,bar"} |
1128 | 1123 | schema_cls = Schema.from_dict( |
1129 | | - {"ids": FutureList(fields.String(load_default="nil"))} |
| 1124 | + {"ids": fields.DelimitedList(fields.String(load_default="nil"))} |
1130 | 1125 | ) |
1131 | 1126 | schema = schema_cls() |
1132 | 1127 |
|
1133 | 1128 | parsed = parser.parse(schema, web_request) |
1134 | 1129 | assert parsed["ids"] == ["foo", "nil", "bar"] |
1135 | 1130 |
|
1136 | 1131 |
|
| 1132 | +def test_delimited_list_using_empty_string_for_empty(web_request, parser): |
| 1133 | + # this is "past" because it was the default for webargs v8.x |
| 1134 | + class PastList(fields.DelimitedList): |
| 1135 | + empty_value = "" |
| 1136 | + |
| 1137 | + web_request.json = {"ids": "foo,,bar"} |
| 1138 | + schema_cls = Schema.from_dict({"ids": PastList(fields.String(load_default="nil"))}) |
| 1139 | + schema = schema_cls() |
| 1140 | + |
| 1141 | + parsed = parser.parse(schema, web_request) |
| 1142 | + assert parsed["ids"] == ["foo", "", "bar"] |
| 1143 | + |
| 1144 | + |
1137 | 1145 | def test_missing_list_argument_not_in_parsed_result(web_request, parser): |
1138 | 1146 | # arg missing in request |
1139 | 1147 | web_request.json = {} |
|
0 commit comments