@typespec/http-client-python 0.28.1 → 0.28.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/dist/emitter/code-model.d.ts.map +1 -1
  2. package/dist/emitter/code-model.js +6 -6
  3. package/dist/emitter/code-model.js.map +1 -1
  4. package/dist/emitter/emitter.d.ts.map +1 -1
  5. package/dist/emitter/emitter.js +27 -28
  6. package/dist/emitter/emitter.js.map +1 -1
  7. package/dist/emitter/lib.d.ts +4 -1
  8. package/dist/emitter/lib.d.ts.map +1 -1
  9. package/dist/emitter/lib.js.map +1 -1
  10. package/dist/emitter/system-requirements.js +6 -4
  11. package/dist/emitter/system-requirements.js.map +1 -1
  12. package/dist/emitter/types.d.ts +2 -5
  13. package/dist/emitter/types.d.ts.map +1 -1
  14. package/dist/emitter/types.js +55 -58
  15. package/dist/emitter/types.js.map +1 -1
  16. package/dist/emitter/utils.d.ts.map +1 -1
  17. package/dist/emitter/utils.js +16 -17
  18. package/dist/emitter/utils.js.map +1 -1
  19. package/emitter/src/code-model.ts +6 -13
  20. package/emitter/src/emitter.ts +29 -31
  21. package/emitter/src/lib.ts +4 -0
  22. package/emitter/src/system-requirements.ts +4 -4
  23. package/emitter/src/types.ts +67 -57
  24. package/emitter/src/utils.ts +16 -18
  25. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  26. package/eng/scripts/Build-Packages.ps1 +62 -37
  27. package/eng/scripts/Check-GitChanges.ps1 +30 -3
  28. package/eng/scripts/Functions.ps1 +54 -15
  29. package/eng/scripts/Generate.ps1 +42 -8
  30. package/eng/scripts/Generation.psm1 +44 -15
  31. package/eng/scripts/Initialize-Repository.ps1 +29 -11
  32. package/eng/scripts/Test-Packages.ps1 +47 -31
  33. package/eng/scripts/ci/config/eslint-ci.config.mjs +54 -0
  34. package/eng/scripts/ci/dev_requirements.txt +1 -0
  35. package/eng/scripts/ci/format.ts +232 -2
  36. package/eng/scripts/ci/lint.ts +216 -20
  37. package/eng/scripts/ci/regenerate-common.ts +18 -14
  38. package/eng/scripts/ci/regenerate.ts +305 -68
  39. package/eng/scripts/ci/run-tests.ts +402 -0
  40. package/eng/scripts/ci/run_mypy.py +4 -3
  41. package/eng/scripts/ci/run_pylint.py +4 -3
  42. package/eng/scripts/ci/run_pyright.py +4 -3
  43. package/eng/scripts/ci/typecheck.ts +225 -0
  44. package/eng/scripts/ci/util.py +1 -1
  45. package/eng/scripts/ci/utils.ts +5 -5
  46. package/eng/scripts/setup/__pycache__/package_manager.cpython-311.pyc +0 -0
  47. package/eng/scripts/setup/__pycache__/venvtools.cpython-311.pyc +0 -0
  48. package/eng/scripts/setup/build.ts +1 -1
  49. package/eng/scripts/setup/build_pygen_wheel.py +1 -0
  50. package/eng/scripts/setup/install.py +1 -0
  51. package/eng/scripts/setup/prepare.py +1 -0
  52. package/eng/scripts/setup/prepare.ts +1 -1
  53. package/eng/scripts/setup/run_tsp.py +3 -3
  54. package/eng/scripts/setup/system-requirements.ts +8 -4
  55. package/eng/scripts/setup/venvtools.py +1 -0
  56. package/generator/build/lib/pygen/codegen/models/operation.py +9 -8
  57. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +157 -64
  58. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  59. package/generator/pygen/codegen/models/operation.py +9 -8
  60. package/generator/pygen/codegen/templates/model_base.py.jinja2 +157 -64
  61. package/package.json +48 -42
  62. package/eng/scripts/ci/run-ci.ts +0 -89
  63. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_commonproperties_async.py +0 -94
  64. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_largeheader_async.py +0 -30
  65. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_nonresource_async.py +0 -36
  66. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +0 -205
  67. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_resource_async.py +0 -478
  68. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_access_async.py +0 -101
  69. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_header_async.py +0 -18
  70. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_path_async.py +0 -18
  71. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_query_async.py +0 -18
  72. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_default_value_async.py +0 -46
  73. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +0 -58
  74. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_location_async.py +0 -82
  75. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_deserialize_empty_string_as_null_async.py +0 -20
  76. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py +0 -115
  77. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_hierrarchy_building_async.py +0 -53
  78. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_next_link_verb_async.py +0 -28
  79. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_override_async.py +0 -106
  80. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_usage_async.py +0 -38
  81. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_basic_async.py +0 -76
  82. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_rpc_async.py +0 -22
  83. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_standard_async.py +0 -39
  84. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_model_async.py +0 -33
  85. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_page_async.py +0 -80
  86. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_scalar_async.py +0 -41
  87. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_traits_async.py +0 -87
  88. package/generator/test/azure/mock_api_tests/asynctests/test_azure_encode_duration_async.py +0 -19
  89. package/generator/test/azure/mock_api_tests/asynctests/test_azure_example_basic_async.py +0 -30
  90. package/generator/test/azure/mock_api_tests/asynctests/test_azure_payload_pageable_async.py +0 -19
  91. package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py +0 -248
  92. package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_async.py +0 -110
  93. package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_shared_models_async.py +0 -132
  94. package/generator/test/azure/mock_api_tests/asynctests/test_azure_special_headers_client_request_id_async.py +0 -30
  95. package/generator/test/azure/mock_api_tests/asynctests/test_azure_versioning_previewversion_async.py +0 -53
  96. package/generator/test/azure/mock_api_tests/asynctests/test_client_namespace_async.py +0 -34
  97. package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_async.py +0 -69
  98. package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_enum_conflict_async.py +0 -37
  99. package/generator/test/azure/mock_api_tests/asynctests/test_client_overload_async.py +0 -27
  100. package/generator/test/azure/mock_api_tests/asynctests/test_client_structure_async.py +0 -64
  101. package/generator/test/azure/mock_api_tests/asynctests/test_client_structure_clientoperationgroup_async.py +0 -31
  102. package/generator/test/azure/mock_api_tests/asynctests/test_encode_duration_async.py +0 -63
  103. package/generator/test/azure/mock_api_tests/asynctests/test_encode_numeric_async.py +0 -35
  104. package/generator/test/azure/mock_api_tests/asynctests/test_parameters_basic_async.py +0 -24
  105. package/generator/test/azure/mock_api_tests/asynctests/test_parameters_spread_async.py +0 -76
  106. package/generator/test/azure/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +0 -37
  107. package/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +0 -216
  108. package/generator/test/azure/mock_api_tests/asynctests/test_resiliency_srv_driven_async.py +0 -130
  109. package/generator/test/azure/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +0 -24
  110. package/generator/test/azure/mock_api_tests/asynctests/test_service_multi_service_async.py +0 -31
  111. package/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py +0 -71
  112. package/generator/test/azure/mock_api_tests/conftest.py +0 -207
  113. package/generator/test/azure/mock_api_tests/data/image.jpg +0 -0
  114. package/generator/test/azure/mock_api_tests/data/image.png +0 -0
  115. package/generator/test/azure/mock_api_tests/test_azure_arm_commonproperties.py +0 -89
  116. package/generator/test/azure/mock_api_tests/test_azure_arm_largeheader.py +0 -27
  117. package/generator/test/azure/mock_api_tests/test_azure_arm_nonresource.py +0 -34
  118. package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +0 -180
  119. package/generator/test/azure/mock_api_tests/test_azure_arm_resource.py +0 -436
  120. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_access.py +0 -92
  121. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_header.py +0 -17
  122. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_path.py +0 -17
  123. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_query.py +0 -17
  124. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_default_value.py +0 -42
  125. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +0 -51
  126. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_location.py +0 -70
  127. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_deserialize_empty_string_as_null.py +0 -19
  128. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py +0 -104
  129. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_hierrarchy_building.py +0 -45
  130. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_next_link_verb.py +0 -27
  131. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_override.py +0 -102
  132. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_usage.py +0 -32
  133. package/generator/test/azure/mock_api_tests/test_azure_core_basic.py +0 -70
  134. package/generator/test/azure/mock_api_tests/test_azure_core_lro_rpc.py +0 -20
  135. package/generator/test/azure/mock_api_tests/test_azure_core_lro_standard.py +0 -32
  136. package/generator/test/azure/mock_api_tests/test_azure_core_model.py +0 -30
  137. package/generator/test/azure/mock_api_tests/test_azure_core_page.py +0 -71
  138. package/generator/test/azure/mock_api_tests/test_azure_core_scalar.py +0 -35
  139. package/generator/test/azure/mock_api_tests/test_azure_core_traits.py +0 -85
  140. package/generator/test/azure/mock_api_tests/test_azure_encode_duration.py +0 -18
  141. package/generator/test/azure/mock_api_tests/test_azure_example_basic.py +0 -29
  142. package/generator/test/azure/mock_api_tests/test_azure_payload_pageable.py +0 -18
  143. package/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py +0 -235
  144. package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service.py +0 -104
  145. package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_shared_models.py +0 -128
  146. package/generator/test/azure/mock_api_tests/test_azure_special_headers_client_request_id.py +0 -29
  147. package/generator/test/azure/mock_api_tests/test_azure_versioning_previewversion.py +0 -50
  148. package/generator/test/azure/mock_api_tests/test_clear_output_folder.py +0 -23
  149. package/generator/test/azure/mock_api_tests/test_client_namespace.py +0 -32
  150. package/generator/test/azure/mock_api_tests/test_client_naming.py +0 -57
  151. package/generator/test/azure/mock_api_tests/test_client_naming_enum_conflict.py +0 -35
  152. package/generator/test/azure/mock_api_tests/test_client_overload.py +0 -25
  153. package/generator/test/azure/mock_api_tests/test_client_structure.py +0 -60
  154. package/generator/test/azure/mock_api_tests/test_client_structure_clientoperationgroup.py +0 -29
  155. package/generator/test/azure/mock_api_tests/test_encode_duration.py +0 -60
  156. package/generator/test/azure/mock_api_tests/test_encode_numeric.py +0 -31
  157. package/generator/test/azure/mock_api_tests/test_model_base_flatten_compatibility.py +0 -251
  158. package/generator/test/azure/mock_api_tests/test_parameters_basic.py +0 -22
  159. package/generator/test/azure/mock_api_tests/test_parameters_spread.py +0 -66
  160. package/generator/test/azure/mock_api_tests/test_payload_content_negotiation.py +0 -33
  161. package/generator/test/azure/mock_api_tests/test_payload_multipart.py +0 -198
  162. package/generator/test/azure/mock_api_tests/test_resiliency_srv_driven.py +0 -124
  163. package/generator/test/azure/mock_api_tests/test_serialization_encoded_name_json.py +0 -21
  164. package/generator/test/azure/mock_api_tests/test_service_multi_service.py +0 -29
  165. package/generator/test/azure/mock_api_tests/test_special_words.py +0 -63
  166. package/generator/test/azure/requirements.txt +0 -125
  167. package/generator/test/azure/tox.ini +0 -64
  168. package/generator/test/data/image.jpg +0 -0
  169. package/generator/test/data/image.png +0 -0
  170. package/generator/test/dev_requirements.txt +0 -8
  171. package/generator/test/generic_mock_api_tests/asynctests/test_authentication_async.py +0 -140
  172. package/generator/test/generic_mock_api_tests/asynctests/test_encode_array_async.py +0 -139
  173. package/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +0 -132
  174. package/generator/test/generic_mock_api_tests/asynctests/test_encode_datetime_async.py +0 -127
  175. package/generator/test/generic_mock_api_tests/asynctests/test_headasboolean_async.py +0 -35
  176. package/generator/test/generic_mock_api_tests/asynctests/test_parameters_body_optionality_async.py +0 -30
  177. package/generator/test/generic_mock_api_tests/asynctests/test_parameters_collection_format_async.py +0 -38
  178. package/generator/test/generic_mock_api_tests/asynctests/test_parameters_path_async.py +0 -24
  179. package/generator/test/generic_mock_api_tests/asynctests/test_parameters_query_async.py +0 -18
  180. package/generator/test/generic_mock_api_tests/asynctests/test_payload_json_merge_patch_async.py +0 -98
  181. package/generator/test/generic_mock_api_tests/asynctests/test_payload_media_type_async.py +0 -27
  182. package/generator/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py +0 -134
  183. package/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py +0 -150
  184. package/generator/test/generic_mock_api_tests/asynctests/test_response_status_code_range_async.py +0 -38
  185. package/generator/test/generic_mock_api_tests/asynctests/test_routes_async.py +0 -331
  186. package/generator/test/generic_mock_api_tests/asynctests/test_server_endpoint_not_defined_async.py +0 -18
  187. package/generator/test/generic_mock_api_tests/asynctests/test_server_path_multiple_async.py +0 -25
  188. package/generator/test/generic_mock_api_tests/asynctests/test_server_path_single_async.py +0 -18
  189. package/generator/test/generic_mock_api_tests/asynctests/test_server_versions_not_versioned_async.py +0 -28
  190. package/generator/test/generic_mock_api_tests/asynctests/test_server_versions_versioned_async.py +0 -34
  191. package/generator/test/generic_mock_api_tests/asynctests/test_special_headers_conditional_request_async.py +0 -38
  192. package/generator/test/generic_mock_api_tests/asynctests/test_special_headers_repeatability_async.py +0 -19
  193. package/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py +0 -59
  194. package/generator/test/generic_mock_api_tests/asynctests/test_streaming_jsonl_async.py +0 -27
  195. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py +0 -127
  196. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py +0 -98
  197. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py +0 -25
  198. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +0 -27
  199. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_file_async.py +0 -59
  200. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py +0 -32
  201. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py +0 -70
  202. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py +0 -85
  203. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py +0 -34
  204. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py +0 -34
  205. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py +0 -67
  206. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py +0 -32
  207. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py +0 -47
  208. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py +0 -353
  209. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py +0 -110
  210. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py +0 -197
  211. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py +0 -315
  212. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py +0 -60
  213. package/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py +0 -90
  214. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_added_async.py +0 -36
  215. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_made_optional_async.py +0 -21
  216. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_removed_async.py +0 -39
  217. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_renamed_from_async.py +0 -29
  218. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_return_type_changed_from_async.py +0 -18
  219. package/generator/test/generic_mock_api_tests/asynctests/test_versioning_type_changed_from_async.py +0 -22
  220. package/generator/test/generic_mock_api_tests/conftest.py +0 -75
  221. package/generator/test/generic_mock_api_tests/data/image.jpg +0 -0
  222. package/generator/test/generic_mock_api_tests/data/image.png +0 -0
  223. package/generator/test/generic_mock_api_tests/test_authentication.py +0 -130
  224. package/generator/test/generic_mock_api_tests/test_encode_array.py +0 -126
  225. package/generator/test/generic_mock_api_tests/test_encode_bytes.py +0 -128
  226. package/generator/test/generic_mock_api_tests/test_encode_datetime.py +0 -123
  227. package/generator/test/generic_mock_api_tests/test_headasboolean.py +0 -33
  228. package/generator/test/generic_mock_api_tests/test_parameters_body_optionality.py +0 -27
  229. package/generator/test/generic_mock_api_tests/test_parameters_collection_format.py +0 -33
  230. package/generator/test/generic_mock_api_tests/test_parameters_path.py +0 -22
  231. package/generator/test/generic_mock_api_tests/test_parameters_query.py +0 -17
  232. package/generator/test/generic_mock_api_tests/test_payload_json_merge_patch.py +0 -93
  233. package/generator/test/generic_mock_api_tests/test_payload_media_type.py +0 -25
  234. package/generator/test/generic_mock_api_tests/test_payload_pageable.py +0 -99
  235. package/generator/test/generic_mock_api_tests/test_payload_xml.py +0 -135
  236. package/generator/test/generic_mock_api_tests/test_response_status_code_range.py +0 -36
  237. package/generator/test/generic_mock_api_tests/test_routes.py +0 -285
  238. package/generator/test/generic_mock_api_tests/test_server_endpoint_not_defined.py +0 -17
  239. package/generator/test/generic_mock_api_tests/test_server_path_multiple.py +0 -21
  240. package/generator/test/generic_mock_api_tests/test_server_path_single.py +0 -17
  241. package/generator/test/generic_mock_api_tests/test_server_versions_not_versioned.py +0 -25
  242. package/generator/test/generic_mock_api_tests/test_server_versions_versioned.py +0 -30
  243. package/generator/test/generic_mock_api_tests/test_special_headers_conditional_request.py +0 -34
  244. package/generator/test/generic_mock_api_tests/test_special_headers_repeatability.py +0 -18
  245. package/generator/test/generic_mock_api_tests/test_specs_documentation.py +0 -51
  246. package/generator/test/generic_mock_api_tests/test_streaming_jsonl.py +0 -25
  247. package/generator/test/generic_mock_api_tests/test_typetest_array.py +0 -111
  248. package/generator/test/generic_mock_api_tests/test_typetest_dictionary.py +0 -86
  249. package/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py +0 -23
  250. package/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py +0 -25
  251. package/generator/test/generic_mock_api_tests/test_typetest_file.py +0 -52
  252. package/generator/test/generic_mock_api_tests/test_typetest_model_empty.py +0 -29
  253. package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py +0 -58
  254. package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py +0 -79
  255. package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py +0 -31
  256. package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py +0 -32
  257. package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py +0 -60
  258. package/generator/test/generic_mock_api_tests/test_typetest_model_usage.py +0 -28
  259. package/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py +0 -40
  260. package/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py +0 -314
  261. package/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py +0 -102
  262. package/generator/test/generic_mock_api_tests/test_typetest_property_optional.py +0 -174
  263. package/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py +0 -286
  264. package/generator/test/generic_mock_api_tests/test_typetest_scalar.py +0 -53
  265. package/generator/test/generic_mock_api_tests/test_typetest_union.py +0 -80
  266. package/generator/test/generic_mock_api_tests/test_typetest_union_discriminated.py +0 -290
  267. package/generator/test/generic_mock_api_tests/test_versioning_added.py +0 -33
  268. package/generator/test/generic_mock_api_tests/test_versioning_made_optional.py +0 -20
  269. package/generator/test/generic_mock_api_tests/test_versioning_removed.py +0 -37
  270. package/generator/test/generic_mock_api_tests/test_versioning_renamed_from.py +0 -27
  271. package/generator/test/generic_mock_api_tests/test_versioning_return_type_changed_from.py +0 -17
  272. package/generator/test/generic_mock_api_tests/test_versioning_type_changed_from.py +0 -21
  273. package/generator/test/unbranded/mock_api_tests/asynctests/test_auth_flow_async.py +0 -19
  274. package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_duration_async.py +0 -63
  275. package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_numeric_async.py +0 -35
  276. package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_basic_async.py +0 -24
  277. package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_spread_async.py +0 -76
  278. package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +0 -37
  279. package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +0 -218
  280. package/generator/test/unbranded/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +0 -24
  281. package/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py +0 -73
  282. package/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py +0 -24
  283. package/generator/test/unbranded/mock_api_tests/conftest.py +0 -91
  284. package/generator/test/unbranded/mock_api_tests/data/image.jpg +0 -0
  285. package/generator/test/unbranded/mock_api_tests/data/image.png +0 -0
  286. package/generator/test/unbranded/mock_api_tests/test_auth_flow.py +0 -17
  287. package/generator/test/unbranded/mock_api_tests/test_encode_duration.py +0 -60
  288. package/generator/test/unbranded/mock_api_tests/test_encode_numeric.py +0 -32
  289. package/generator/test/unbranded/mock_api_tests/test_parameters_basic.py +0 -22
  290. package/generator/test/unbranded/mock_api_tests/test_parameters_spread.py +0 -66
  291. package/generator/test/unbranded/mock_api_tests/test_payload_content_negotiation.py +0 -33
  292. package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +0 -200
  293. package/generator/test/unbranded/mock_api_tests/test_serialization_encoded_name_json.py +0 -22
  294. package/generator/test/unbranded/mock_api_tests/test_special_words.py +0 -66
  295. package/generator/test/unbranded/mock_api_tests/test_unbranded.py +0 -65
  296. package/generator/test/unbranded/requirements.txt +0 -69
  297. package/generator/test/unbranded/tox.ini +0 -64
  298. package/generator/test/unittests/conftest.py +0 -15
  299. package/generator/test/unittests/requirements.txt +0 -3
  300. package/generator/test/unittests/test_enums.py +0 -89
  301. package/generator/test/unittests/test_model_base_serialization.py +0 -4906
  302. package/generator/test/unittests/test_model_base_xml_serialization.py +0 -1239
  303. package/generator/test/unittests/test_name_converter.py +0 -35
  304. package/generator/test/unittests/test_optional_return_type.py +0 -268
  305. package/generator/test/unittests/test_parameter_ordering.py +0 -104
  306. package/generator/test/unittests/test_sort_schema.py +0 -93
  307. package/generator/test/unittests/tox.ini +0 -5
  308. /package/eng/scripts/ci/{mypy.ini → config/mypy.ini} +0 -0
  309. /package/eng/scripts/ci/{pylintrc → config/pylintrc} +0 -0
  310. /package/eng/scripts/ci/{pyproject.toml → config/pyproject.toml} +0 -0
  311. /package/eng/scripts/ci/{pyrightconfig.json → config/pyrightconfig.json} +0 -0
@@ -1,1239 +0,0 @@
1
- # ------------------------------------
2
- # Copyright (c) Microsoft Corporation.
3
- # Licensed under the MIT License.
4
- # ------------------------------------
5
- import xml.etree.ElementTree as ET
6
-
7
- from typing import Literal, Optional
8
-
9
- from specialwords._utils.model_base import (
10
- _get_element,
11
- Model,
12
- rest_field,
13
- rest_discriminator,
14
- _deserialize_xml,
15
- )
16
-
17
-
18
- def assert_xml_equals(x1, x2):
19
- ET.dump(x1)
20
- ET.dump(x2)
21
-
22
- assert x1.tag == x2.tag
23
- assert (x1.text or "").strip() == (x2.text or "").strip()
24
- # assert x1.tail == x2.tail # Swagger does not change tail
25
- assert x1.attrib == x2.attrib
26
- assert len(x1) == len(x2)
27
- for c1, c2 in zip(x1, x2):
28
- assert_xml_equals(c1, c2)
29
-
30
-
31
- class TestXmlDeserialization:
32
- def test_basic(self):
33
- """Test an ultra basic XML."""
34
- basic_xml = """<?xml version="1.0"?>
35
- <Data country="france">
36
- <Int>12</Int>
37
- <EmptyInt/>
38
- <Float>12.34</Float>
39
- <EmptyFloat/>
40
- <Bool>true</Bool>
41
- <EmptyBool/>
42
- <String>test</String>
43
- <EmptyString/>
44
- </Data>"""
45
-
46
- class XmlModel(Model):
47
- int_field: int = rest_field(name="int", xml={"name": "Int"})
48
- empty_int: int = rest_field(name="empty_int", xml={"name": "EmptyInt"})
49
- float_field: float = rest_field(name="float", xml={"name": "Float"})
50
- empty_float: float = rest_field(name="empty_float", xml={"name": "EmptyFloat"})
51
- bool_field: bool = rest_field(name="bool", xml={"name": "Bool"})
52
- empty_bool: bool = rest_field(name="empty_bool", xml={"name": "EmptyBool"})
53
- string: str = rest_field(name="string", xml={"name": "String"})
54
- empty_string: str = rest_field(name="empty_string", xml={"name": "EmptyString"})
55
- not_set: str = rest_field(name="not_set", xml={"name": "NotSet"})
56
- country: str = rest_field(name="country", xml={"name": "country", "attribute": True})
57
-
58
- def __init__(self, *args, **kwargs):
59
- super().__init__(*args, **kwargs)
60
-
61
- _xml = {"name": "Data"}
62
-
63
- result = _deserialize_xml(XmlModel, basic_xml)
64
-
65
- assert result.int_field == 12
66
- assert result.empty_int is None
67
- assert result.float_field == 12.34
68
- assert result.empty_float is None
69
- assert result.bool_field is True
70
- assert result.empty_bool is None
71
- assert result.string == "test"
72
- assert result.country == "france"
73
- assert result.empty_string == ""
74
- assert result.not_set is None
75
-
76
- def test_basic_unicode(self):
77
- """Test a XML with unicode."""
78
- basic_xml = """<?xml version="1.0" encoding="utf-8"?>
79
- <Data language="français"/>"""
80
-
81
- class XmlModel(Model):
82
- language: str = rest_field(name="language", xml={"name": "language", "attribute": True})
83
-
84
- def __init__(self, *args, **kwargs):
85
- super().__init__(*args, **kwargs)
86
-
87
- _xml = {"name": "Data"}
88
-
89
- result = _deserialize_xml(XmlModel, basic_xml)
90
-
91
- assert result.language == "français"
92
-
93
- def test_basic_text(self):
94
- """Test a XML with unicode."""
95
- basic_xml = """<?xml version="1.0" encoding="utf-8"?>
96
- <Data language="english">I am text</Data>"""
97
-
98
- class XmlModel(Model):
99
- language: str = rest_field(name="language", xml={"name": "language", "attribute": True})
100
- content: str = rest_field(name="content", xml={"name": "content", "text": True})
101
-
102
- def __init__(self, *args, **kwargs):
103
- super().__init__(*args, **kwargs)
104
-
105
- _xml = {"name": "Data"}
106
-
107
- result = _deserialize_xml(XmlModel, basic_xml)
108
-
109
- assert result.language == "english"
110
- assert result.content == "I am text"
111
-
112
- def test_dict_type(self):
113
- """Test dict type."""
114
- basic_xml = """<?xml version="1.0"?>
115
- <Data>
116
- <Metadata>
117
- <Key1>value1</Key1>
118
- <Key2>value2</Key2>
119
- </Metadata>
120
- </Data>"""
121
-
122
- class XmlModel(Model):
123
- metadata: dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"})
124
-
125
- def __init__(self, *args, **kwargs):
126
- super().__init__(*args, **kwargs)
127
-
128
- _xml = {"name": "Data"}
129
-
130
- result = _deserialize_xml(XmlModel, basic_xml)
131
-
132
- assert len(result.metadata) == 2
133
- assert result.metadata["Key1"] == "value1"
134
- assert result.metadata["Key2"] == "value2"
135
-
136
- def test_basic_empty_list(self):
137
- """Test an basic XML with an empty node."""
138
- basic_xml = """<?xml version="1.0"?>
139
- <Data>
140
- <Age/>
141
- </Data>"""
142
-
143
- class XmlModel(Model):
144
- age: list[str] = rest_field(name="age", xml={"name": "Age"})
145
-
146
- def __init__(self, *args, **kwargs):
147
- super().__init__(*args, **kwargs)
148
-
149
- _xml = {"name": "Data"}
150
-
151
- result = _deserialize_xml(XmlModel, basic_xml)
152
- assert result.age == []
153
-
154
- def test_basic_empty_list_unwrapped(self):
155
- """Test an basic XML with an empty node."""
156
- basic_xml = """<?xml version="1.0"?>
157
- <Data/>"""
158
-
159
- class XmlModel(Model):
160
- age: list[str] = rest_field(name="age", xml={"name": "Age", "unwrapped": True})
161
-
162
- def __init__(self, *args, **kwargs):
163
- super().__init__(*args, **kwargs)
164
-
165
- _xml = {"name": "Data"}
166
-
167
- result = _deserialize_xml(XmlModel, basic_xml)
168
- assert result.age == []
169
-
170
- def test_list_wrapped_items_name_basic_types(self):
171
- """Test XML list and wrap, items is basic type and there is itemsName."""
172
-
173
- basic_xml = """<?xml version="1.0"?>
174
- <AppleBarrel>
175
- <GoodApples>
176
- <Apple>granny</Apple>
177
- <Apple>fuji</Apple>
178
- </GoodApples>
179
- </AppleBarrel>"""
180
-
181
- class AppleBarrel(Model):
182
- good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"})
183
-
184
- def __init__(self, *args, **kwargs):
185
- super().__init__(*args, **kwargs)
186
-
187
- _xml = {"name": "AppleBarrel"}
188
-
189
- result = _deserialize_xml(AppleBarrel, basic_xml)
190
- assert result.good_apples == ["granny", "fuji"]
191
-
192
- def test_list_not_wrapped_items_name_basic_types(self):
193
- """Test XML list and no wrap, items is basic type and there is itemsName."""
194
-
195
- basic_xml = """<?xml version="1.0"?>
196
- <AppleBarrel>
197
- <Apple>granny</Apple>
198
- <Apple>fuji</Apple>
199
- </AppleBarrel>"""
200
-
201
- class AppleBarrel(Model):
202
- good_apples: list[str] = rest_field(
203
- name="GoodApples",
204
- xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
205
- )
206
-
207
- def __init__(self, *args, **kwargs):
208
- super().__init__(*args, **kwargs)
209
-
210
- _xml = {"name": "AppleBarrel"}
211
-
212
- result = _deserialize_xml(AppleBarrel, basic_xml)
213
- assert result.good_apples == ["granny", "fuji"]
214
-
215
- def test_list_wrapped_items_name_complex_types(self):
216
- """Test XML list and wrap, items is ref and there is itemsName."""
217
-
218
- basic_xml = """<?xml version="1.0"?>
219
- <AppleBarrel>
220
- <GoodApples>
221
- <Apple name="granny"/>
222
- <Apple name="fuji"/>
223
- </GoodApples>
224
- </AppleBarrel>"""
225
-
226
- class Apple(Model):
227
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
228
-
229
- def __init__(self, *args, **kwargs):
230
- super().__init__(*args, **kwargs)
231
-
232
- _xml = {"name": "Apple"}
233
-
234
- class AppleBarrel(Model):
235
- good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"})
236
-
237
- def __init__(self, *args, **kwargs):
238
- super().__init__(*args, **kwargs)
239
-
240
- _xml = {"name": "AppleBarrel"}
241
-
242
- result = _deserialize_xml(AppleBarrel, basic_xml)
243
- assert [apple.name for apple in result.good_apples] == ["granny", "fuji"]
244
-
245
- def test_list_not_wrapped_items_name_complex_types(self):
246
- """Test XML list and wrap, items is ref and there is itemsName."""
247
-
248
- basic_xml = """<?xml version="1.0"?>
249
- <AppleBarrel>
250
- <Apple name="granny"/>
251
- <Apple name="fuji"/>
252
- </AppleBarrel>"""
253
-
254
- class Apple(Model):
255
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
256
-
257
- def __init__(self, *args, **kwargs):
258
- super().__init__(*args, **kwargs)
259
-
260
- _xml = {"name": "Apple"}
261
-
262
- class AppleBarrel(Model):
263
- good_apples: list[Apple] = rest_field(
264
- name="GoodApples",
265
- xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
266
- )
267
-
268
- def __init__(self, *args, **kwargs):
269
- super().__init__(*args, **kwargs)
270
-
271
- _xml = {"name": "AppleBarrel"}
272
-
273
- result = _deserialize_xml(AppleBarrel, basic_xml)
274
- assert [apple.name for apple in result.good_apples] == ["granny", "fuji"]
275
-
276
- def test_list_not_wrapped_items_name_complex_types(self):
277
- """Test XML list and wrap, items is ref and there is itemsName."""
278
-
279
- basic_xml = """<?xml version="1.0"?>
280
- <AppleBarrel>
281
- <Apple name="granny"/>
282
- <Apple name="fuji"/>
283
- </AppleBarrel>"""
284
-
285
- class Apple(Model):
286
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
287
-
288
- def __init__(self, *args, **kwargs):
289
- super().__init__(*args, **kwargs)
290
-
291
- _xml = {"name": "Apple"}
292
-
293
- class AppleBarrel(Model):
294
- good_apples: list[Apple] = rest_field(
295
- name="GoodApples",
296
- xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
297
- )
298
-
299
- def __init__(self, *args, **kwargs):
300
- super().__init__(*args, **kwargs)
301
-
302
- _xml = {"name": "AppleBarrel"}
303
-
304
- result = _deserialize_xml(AppleBarrel, basic_xml)
305
- assert [apple.name for apple in result.good_apples] == ["granny", "fuji"]
306
-
307
- def test_basic_additional_properties(self):
308
- """Test additional properties."""
309
- basic_xml = """<?xml version="1.0"?>
310
- <Data>
311
- <add1>text</add1>
312
- <add2>
313
- <add2>a</add2>
314
- <add2>b</add2>
315
- <add2>c</add2>
316
- </add2>
317
- <add3>
318
- <a>a</a>
319
- <b>b</b>
320
- </add3>
321
- </Data>"""
322
-
323
- class XmlModel(Model):
324
- name: str = rest_field(name="name", xml={"name": "Name"})
325
-
326
- def __init__(self, *args, **kwargs):
327
- super().__init__(*args, **kwargs)
328
-
329
- _xml = {"name": "Data"}
330
-
331
- result = _deserialize_xml(XmlModel, basic_xml)
332
-
333
- assert result.name is None
334
- assert result["add1"] == "text"
335
- assert result["add2"] == ["a", "b", "c"]
336
- assert result["add3"] == {"a": "a", "b": "b"}
337
-
338
- def test_basic_namespace(self):
339
- """Test an ultra basic XML."""
340
- basic_xml = """<?xml version="1.0"?>
341
- <Data xmlns:fictional="http://characters.example.com">
342
- <fictional:Age>37</fictional:Age>
343
- </Data>"""
344
-
345
- class XmlModel(Model):
346
- age: int = rest_field(
347
- name="age",
348
- xml={
349
- "name": "Age",
350
- "prefix": "fictional",
351
- "ns": "http://characters.example.com",
352
- },
353
- )
354
-
355
- def __init__(self, *args, **kwargs):
356
- super().__init__(*args, **kwargs)
357
-
358
- _xml = {"name": "Data"}
359
-
360
- result = _deserialize_xml(XmlModel, basic_xml)
361
- assert result.age == 37
362
-
363
- def test_complex_namespace(self):
364
- """Test recursive namespace."""
365
- basic_xml = """<?xml version="1.0"?>
366
- <entry xmlns="http://www.w3.org/2005/Atom" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
367
- <author>
368
- <name>lmazuel</name>
369
- </author>
370
- <AuthorizationRules xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
371
- <AuthorizationRule i:type="SharedAccessAuthorizationRule">
372
- <KeyName>testpolicy</KeyName>
373
- </AuthorizationRule>
374
- </AuthorizationRules>
375
- <MessageCountDetails xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
376
- <d2p1:ActiveMessageCount xmlns:d2p1="http://schemas.microsoft.com/netservices/2011/06/servicebus">12</d2p1:ActiveMessageCount>
377
- </MessageCountDetails>
378
- </entry>"""
379
-
380
- class QueueDescriptionResponseAuthor(Model):
381
- name: str = rest_field(name="name", xml={"ns": "http://www.w3.org/2005/Atom"})
382
-
383
- def __init__(self, *args, **kwargs):
384
- super().__init__(*args, **kwargs)
385
-
386
- _xml = {"ns": "http://www.w3.org/2005/Atom"}
387
-
388
- class AuthorizationRule(Model):
389
- type: str = rest_field(
390
- name="type",
391
- xml={
392
- "attribute": True,
393
- "prefix": "i",
394
- "ns": "http://www.w3.org/2001/XMLSchema-instance",
395
- },
396
- )
397
- key_name: str = rest_field(
398
- name="KeyName",
399
- xml={"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"},
400
- )
401
-
402
- def __init__(self, *args, **kwargs):
403
- super().__init__(*args, **kwargs)
404
-
405
- _xml = {"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"}
406
-
407
- class MessageCountDetails(Model):
408
- active_message_count: int = rest_field(
409
- name="ActiveMessageCount",
410
- xml={
411
- "prefix": "d2p1",
412
- "ns": "http://schemas.microsoft.com/netservices/2011/06/servicebus",
413
- },
414
- )
415
-
416
- def __init__(self, *args, **kwargs):
417
- super().__init__(*args, **kwargs)
418
-
419
- _xml = {
420
- "name": "CountDetails",
421
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
422
- }
423
-
424
- class XmlRoot(Model):
425
- author: QueueDescriptionResponseAuthor = rest_field(name="author")
426
- authorization_rules: list[AuthorizationRule] = rest_field(
427
- name="AuthorizationRules",
428
- xml={
429
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
430
- },
431
- )
432
- message_count_details: MessageCountDetails = rest_field(
433
- name="MessageCountDetails",
434
- xml={
435
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
436
- },
437
- )
438
-
439
- def __init__(self, *args, **kwargs):
440
- super().__init__(*args, **kwargs)
441
-
442
- _xml = {"name": "entry", "ns": "http://www.w3.org/2005/Atom"}
443
-
444
- result = _deserialize_xml(XmlRoot, basic_xml)
445
-
446
- assert result.author.name == "lmazuel"
447
- assert result.authorization_rules[0].key_name == "testpolicy"
448
- assert result.authorization_rules[0].type == "SharedAccessAuthorizationRule"
449
- assert result.message_count_details.active_message_count == 12
450
-
451
- def test_polymorphic_deserialization(self):
452
- basic_xml = """<?xml version="1.0"?>
453
- <entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
454
- <Filter xsi:type="CorrelationFilter">
455
- <CorrelationId>12</CorrelationId>
456
- </Filter>
457
- </entry>"""
458
-
459
- class RuleFilter(Model):
460
- __mapping__: dict[str, Model] = {}
461
- type: Literal[None] = rest_discriminator(
462
- name="type",
463
- xml={
464
- "attribute": True,
465
- "prefix": "xsi",
466
- "ns": "http://www.w3.org/2001/XMLSchema-instance",
467
- },
468
- )
469
-
470
- def __init__(self, *args, **kwargs):
471
- super().__init__(*args, **kwargs)
472
- self.type: Literal[None] = None
473
-
474
- _xml = {"name": "Filter"}
475
-
476
- class CorrelationFilter(RuleFilter):
477
- type: Literal["CorrelationFilter"] = rest_discriminator(
478
- name="type",
479
- xml={
480
- "attribute": True,
481
- "prefix": "xsi",
482
- "ns": "http://www.w3.org/2001/XMLSchema-instance",
483
- },
484
- )
485
- correlation_id: int = rest_field(name="CorrelationId")
486
-
487
- def __init__(self, *args, **kwargs):
488
- super().__init__(*args, **kwargs)
489
- self.type: Literal["CorrelationFilter"] = "CorrelationFilter"
490
-
491
- class SqlFilter(RuleFilter):
492
- type: Literal["SqlFilter"] = rest_discriminator(
493
- name="type",
494
- xml={
495
- "attribute": True,
496
- "prefix": "xsi",
497
- "ns": "http://www.w3.org/2001/XMLSchema-instance",
498
- },
499
- )
500
-
501
- def __init__(self, *args, **kwargs):
502
- super().__init__(*args, **kwargs)
503
- self.type: Literal["SqlFilter"] = "SqlFilter"
504
-
505
- class XmlRoot(Model):
506
- filter: RuleFilter = rest_field(name="Filter")
507
-
508
- def __init__(self, *args, **kwargs):
509
- super().__init__(*args, **kwargs)
510
-
511
- _xml = {"name": "entry"}
512
-
513
- result = _deserialize_xml(XmlRoot, basic_xml)
514
-
515
- assert isinstance(result.filter, CorrelationFilter)
516
- assert result.filter.correlation_id == 12
517
-
518
- def test_enumeration_results(self):
519
- """Test deserializing an Azure Blob Storage EnumerationResults XML payload."""
520
- xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="my-container-108f32e8"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
521
-
522
- class EnumerationResults(Model):
523
- service_endpoint: str = rest_field(
524
- name="ServiceEndpoint", xml={"name": "ServiceEndpoint", "attribute": True}
525
- )
526
- container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
527
- delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
528
- blobs: list[str] = rest_field(name="Blobs", xml={"name": "Blobs"})
529
- next_marker: str = rest_field(name="NextMarker", xml={"name": "NextMarker"})
530
-
531
- def __init__(self, *args, **kwargs):
532
- super().__init__(*args, **kwargs)
533
-
534
- _xml = {"name": "EnumerationResults"}
535
-
536
- result = _deserialize_xml(EnumerationResults, xml_payload)
537
-
538
- assert result.service_endpoint == "https://service.blob.core.windows.net/"
539
- assert result.container_name == "my-container-108f32e8"
540
- assert result.delimiter == "/"
541
- assert result.blobs == []
542
- assert result.next_marker == ""
543
-
544
- def test_enumeration_results_nested_empty_list(self):
545
- """Test deserializing XML where a container element holds a nested empty list (e.g. Blobs/BlobPrefixes)."""
546
- xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="my-container"><Delimiter>/</Delimiter><Blobs><BlobPrefixes /></Blobs><NextMarker /></EnumerationResults>'
547
-
548
- class BlobPrefix(Model):
549
- name: str = rest_field(name="Name", xml={"name": "Name"})
550
-
551
- def __init__(self, *args, **kwargs):
552
- super().__init__(*args, **kwargs)
553
-
554
- _xml = {"name": "BlobPrefix"}
555
-
556
- class BlobsSegment(Model):
557
- blob_prefixes: list[BlobPrefix] = rest_field(
558
- name="BlobPrefixes", xml={"name": "BlobPrefixes", "itemsName": "BlobPrefix"}
559
- )
560
-
561
- def __init__(self, *args, **kwargs):
562
- super().__init__(*args, **kwargs)
563
-
564
- _xml = {"name": "Blobs"}
565
-
566
- class EnumerationResults(Model):
567
- service_endpoint: str = rest_field(
568
- name="ServiceEndpoint", xml={"name": "ServiceEndpoint", "attribute": True}
569
- )
570
- container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
571
- delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
572
- blobs: BlobsSegment = rest_field(name="Blobs", xml={"name": "Blobs"})
573
- next_marker: str = rest_field(name="NextMarker", xml={"name": "NextMarker"})
574
-
575
- def __init__(self, *args, **kwargs):
576
- super().__init__(*args, **kwargs)
577
-
578
- _xml = {"name": "EnumerationResults"}
579
-
580
- result = _deserialize_xml(EnumerationResults, xml_payload)
581
-
582
- assert result.service_endpoint == "https://service.blob.core.windows.net/"
583
- assert result.container_name == "my-container"
584
- assert result.delimiter == "/"
585
- assert result.blobs.blob_prefixes == []
586
- assert result.next_marker == ""
587
-
588
- def test_enumeration_results_azure_sdk_pattern(self):
589
- """Test the real Azure SDK model pattern where BlobsSegment has two unwrapped list fields."""
590
- # Both blob_prefixes and blob_items are unwrapped lists (items appear directly in <Blobs>).
591
- # With <Blobs />, no matching children are found so both are None.
592
- xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="my-container"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
593
-
594
- class BlobPrefix(Model):
595
- name: str = rest_field(name="Name", xml={"name": "Name"})
596
-
597
- def __init__(self, *args, **kwargs):
598
- super().__init__(*args, **kwargs)
599
-
600
- _xml = {"name": "BlobPrefix"}
601
-
602
- class BlobItem(Model):
603
- name: str = rest_field(name="Name", xml={"name": "Name"})
604
-
605
- def __init__(self, *args, **kwargs):
606
- super().__init__(*args, **kwargs)
607
-
608
- _xml = {"name": "Blob"}
609
-
610
- class BlobsSegment(Model):
611
- blob_prefixes: list[BlobPrefix] = rest_field(
612
- name="blob_prefixes", xml={"name": "BlobPrefix", "unwrapped": True}
613
- )
614
- blob_items: list[BlobItem] = rest_field(name="blob_items", xml={"name": "Blob", "unwrapped": True})
615
-
616
- def __init__(self, *args, **kwargs):
617
- super().__init__(*args, **kwargs)
618
-
619
- _xml = {"name": "Blobs"}
620
-
621
- class EnumerationResults(Model):
622
- service_endpoint: str = rest_field(
623
- name="ServiceEndpoint", xml={"name": "ServiceEndpoint", "attribute": True}
624
- )
625
- container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
626
- delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
627
- blobs: BlobsSegment = rest_field(name="Blobs", xml={"name": "Blobs"})
628
- next_marker: str = rest_field(name="NextMarker", xml={"name": "NextMarker"})
629
-
630
- def __init__(self, *args, **kwargs):
631
- super().__init__(*args, **kwargs)
632
-
633
- _xml = {"name": "EnumerationResults"}
634
-
635
- result = _deserialize_xml(EnumerationResults, xml_payload)
636
-
637
- assert result.service_endpoint == "https://service.blob.core.windows.net/"
638
- assert result.container_name == "my-container"
639
- assert result.delimiter == "/"
640
- assert isinstance(result.blobs, BlobsSegment)
641
- # With <Blobs />, no <BlobPrefix> or <Blob> children exist → unwrapped non-optional lists default to []
642
- assert result.blobs.blob_prefixes == []
643
- assert result.blobs.blob_items == []
644
- assert result.next_marker == ""
645
-
646
- def test_enumeration_results_azure_sdk_pattern_optional(self):
647
- """Test the Azure SDK pattern where unwrapped list fields are Optional[list[X]].
648
-
649
- When the type is Optional[list[X]], empty unwrapped lists should stay None
650
- (the element is absent, and None is a valid value for the optional type).
651
- """
652
- xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="my-container"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
653
-
654
- class BlobPrefix(Model):
655
- name: str = rest_field(name="Name", xml={"name": "Name"})
656
-
657
- def __init__(self, *args, **kwargs):
658
- super().__init__(*args, **kwargs)
659
-
660
- _xml = {"name": "BlobPrefix"}
661
-
662
- class BlobItem(Model):
663
- name: str = rest_field(name="Name", xml={"name": "Name"})
664
-
665
- def __init__(self, *args, **kwargs):
666
- super().__init__(*args, **kwargs)
667
-
668
- _xml = {"name": "Blob"}
669
-
670
- class BlobsSegment(Model):
671
- blob_prefixes: Optional[list[BlobPrefix]] = rest_field(
672
- name="blob_prefixes", xml={"name": "BlobPrefix", "unwrapped": True}
673
- )
674
- blob_items: Optional[list[BlobItem]] = rest_field(
675
- name="blob_items", xml={"name": "Blob", "unwrapped": True}
676
- )
677
-
678
- def __init__(self, *args, **kwargs):
679
- super().__init__(*args, **kwargs)
680
-
681
- _xml = {"name": "Blobs"}
682
-
683
- class EnumerationResults(Model):
684
- service_endpoint: str = rest_field(
685
- name="ServiceEndpoint", xml={"name": "ServiceEndpoint", "attribute": True}
686
- )
687
- container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
688
- delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
689
- blobs: BlobsSegment = rest_field(name="Blobs", xml={"name": "Blobs"})
690
- next_marker: str = rest_field(name="NextMarker", xml={"name": "NextMarker"})
691
-
692
- def __init__(self, *args, **kwargs):
693
- super().__init__(*args, **kwargs)
694
-
695
- _xml = {"name": "EnumerationResults"}
696
-
697
- result = _deserialize_xml(EnumerationResults, xml_payload)
698
-
699
- assert result.service_endpoint == "https://service.blob.core.windows.net/"
700
- assert result.container_name == "my-container"
701
- assert result.delimiter == "/"
702
- assert isinstance(result.blobs, BlobsSegment)
703
- # With <Blobs />, no <BlobPrefix> or <Blob> children exist → Optional lists stay None
704
- assert result.blobs.blob_prefixes is None
705
- assert result.blobs.blob_items is None
706
- assert result.next_marker == ""
707
-
708
- def test_enumeration_results_blobs_unwrapped(self):
709
- """Test what happens when the blobs field itself is declared with unwrapped=True."""
710
- # When a non-list model field uses unwrapped=True, the matching XML elements are collected
711
- # as a list and stored as-is (the field receives a list of ET.Element objects).
712
- xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="my-container"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
713
-
714
- class BlobPrefix(Model):
715
- name: str = rest_field(name="Name", xml={"name": "Name"})
716
-
717
- def __init__(self, *args, **kwargs):
718
- super().__init__(*args, **kwargs)
719
-
720
- _xml = {"name": "BlobPrefix"}
721
-
722
- class BlobsSegment(Model):
723
- blob_prefixes: list[BlobPrefix] = rest_field(
724
- name="BlobPrefixes", xml={"name": "BlobPrefixes", "itemsName": "BlobPrefix"}
725
- )
726
-
727
- def __init__(self, *args, **kwargs):
728
- super().__init__(*args, **kwargs)
729
-
730
- _xml = {"name": "Blobs"}
731
-
732
- class EnumerationResults(Model):
733
- service_endpoint: str = rest_field(
734
- name="ServiceEndpoint", xml={"name": "ServiceEndpoint", "attribute": True}
735
- )
736
- container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
737
- delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
738
- # unwrapped=True on a model-typed field: the deserialization collects matching XML
739
- # elements as a list (rather than deserializing them into the model).
740
- blobs: BlobsSegment = rest_field(name="Blobs", xml={"name": "Blobs", "unwrapped": True})
741
- next_marker: str = rest_field(name="NextMarker", xml={"name": "NextMarker"})
742
-
743
- def __init__(self, *args, **kwargs):
744
- super().__init__(*args, **kwargs)
745
-
746
- _xml = {"name": "EnumerationResults"}
747
-
748
- result = _deserialize_xml(EnumerationResults, xml_payload)
749
-
750
- assert result.service_endpoint == "https://service.blob.core.windows.net/"
751
- assert result.container_name == "my-container"
752
- assert result.delimiter == "/"
753
- # unwrapped=True on a model field collects matching elements; <Blobs /> is found so it
754
- # returns a list containing the raw ET.Element instead of a deserialized BlobsSegment.
755
- assert isinstance(result.blobs, list)
756
- assert len(result.blobs) == 1
757
- assert isinstance(result.blobs[0], ET.Element)
758
- assert result.next_marker == ""
759
-
760
-
761
- class TestXmlSerialization:
762
- def test_basic(self):
763
- """Test an ultra basic XML."""
764
- basic_xml = ET.fromstring(
765
- """<?xml version="1.0"?>
766
- <Data country="france">
767
- <Age>37</Age>
768
- </Data>"""
769
- )
770
-
771
- class XmlModel(Model):
772
- age: int = rest_field(xml={"name": "Age"})
773
- country: str = rest_field(xml={"name": "country", "attribute": True})
774
-
775
- def __init__(self, *args, **kwargs):
776
- super().__init__(*args, **kwargs)
777
-
778
- _xml = {"name": "Data"}
779
-
780
- xml_model = XmlModel(age=37, country="france")
781
- assert_xml_equals(_get_element(xml_model), basic_xml)
782
-
783
- def test_basic_unicode(self):
784
- """Test a XML with unicode."""
785
- basic_xml = ET.fromstring(
786
- """<?xml version="1.0" encoding="utf-8"?>
787
- <Data language="français"/>""".encode(
788
- "utf-8"
789
- )
790
- )
791
-
792
- class XmlModel(Model):
793
- language: str = rest_field(xml={"name": "language", "attribute": True})
794
-
795
- def __init__(self, *args, **kwargs):
796
- super().__init__(*args, **kwargs)
797
-
798
- _xml = {"name": "Data"}
799
-
800
- xml_model = XmlModel(language="français")
801
- assert_xml_equals(_get_element(xml_model), basic_xml)
802
-
803
- def test_nested_unicode(self):
804
- class XmlModel(Model):
805
- message_text: str = rest_field(name="MessageText", xml={"name": "MessageText"})
806
-
807
- def __init__(self, *args, **kwargs):
808
- super().__init__(*args, **kwargs)
809
-
810
- _xml = {"name": "Message"}
811
-
812
- xml_model_no_unicode = XmlModel(message_text="message1")
813
- xml_element = _get_element(xml_model_no_unicode)
814
- xml_content = ET.tostring(xml_element, encoding="utf8")
815
- assert (
816
- xml_content
817
- == b"<?xml version='1.0' encoding='utf8'?>\n<Message><MessageText>message1</MessageText></Message>"
818
- )
819
-
820
- xml_model_with_unicode = XmlModel(message_text="message1㚈")
821
- xml_element = _get_element(xml_model_with_unicode)
822
- xml_content = ET.tostring(xml_element, encoding="utf8")
823
- assert (
824
- xml_content
825
- == b"<?xml version='1.0' encoding='utf8'?>\n<Message><MessageText>message1\xe3\x9a\x88</MessageText></Message>"
826
- )
827
-
828
- def test_type_basic(self):
829
- """Test basic types."""
830
- basic_xml = ET.fromstring(
831
- """<?xml version="1.0"?>
832
- <Data>
833
- <Age>37</Age>
834
- <Enabled>true</Enabled>
835
- </Data>"""
836
- )
837
-
838
- class XmlModel(Model):
839
- age: int = rest_field(name="age", xml={"name": "Age"})
840
- enabled: bool = rest_field(name="enabled", xml={"name": "Enabled"})
841
-
842
- def __init__(self, *args, **kwargs):
843
- super().__init__(*args, **kwargs)
844
-
845
- _xml = {"name": "Data"}
846
-
847
- xml_model = XmlModel(age=37, enabled=True)
848
- assert_xml_equals(_get_element(xml_model), basic_xml)
849
-
850
- def test_basic_text(self):
851
- """Test a XML with unicode."""
852
- basic_xml = ET.fromstring(
853
- """<?xml version="1.0" encoding="utf-8"?>
854
- <Data language="english">I am text</Data>"""
855
- )
856
-
857
- class XmlModel(Model):
858
- language: str = rest_field(name="language", xml={"name": "language", "attribute": True})
859
- content: str = rest_field(name="content", xml={"text": True})
860
-
861
- def __init__(self, *args, **kwargs):
862
- super().__init__(*args, **kwargs)
863
-
864
- _xml = {"name": "Data"}
865
-
866
- xml_model = XmlModel(language="english", content="I am text")
867
- assert_xml_equals(_get_element(xml_model), basic_xml)
868
-
869
- def test_dict_type(self):
870
- """Test dict type."""
871
- basic_xml = ET.fromstring(
872
- """<?xml version="1.0"?>
873
- <Data>
874
- <Metadata>
875
- <Key1>value1</Key1>
876
- <Key2>value2</Key2>
877
- </Metadata>
878
- </Data>"""
879
- )
880
-
881
- class XmlModel(Model):
882
- metadata: dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"})
883
-
884
- def __init__(self, *args, **kwargs):
885
- super().__init__(*args, **kwargs)
886
-
887
- _xml = {"name": "Data"}
888
-
889
- xml_model = XmlModel(
890
- metadata={
891
- "Key1": "value1",
892
- "Key2": "value2",
893
- }
894
- )
895
- assert_xml_equals(_get_element(xml_model), basic_xml)
896
-
897
- def test_additional_properties(self):
898
- """Test additional properties."""
899
- basic_xml = ET.fromstring(
900
- """<?xml version="1.0"?>
901
- <Data>
902
- <Name>test</Name>
903
- <add1>text</add1>
904
- <add2>
905
- <add2>a</add2>
906
- <add2>b</add2>
907
- <add2>c</add2>
908
- </add2>
909
- <add3>
910
- <a>a</a>
911
- <b>b</b>
912
- </add3>
913
- </Data>"""
914
- )
915
-
916
- class XmlModel(Model):
917
- name: str = rest_field(name="name", xml={"name": "Name"})
918
-
919
- def __init__(self, *args, **kwargs):
920
- super().__init__(*args, **kwargs)
921
-
922
- _xml = {"name": "Data"}
923
-
924
- xml_model = XmlModel(
925
- {
926
- "name": "test",
927
- "add1": "text",
928
- "add2": ["a", "b", "c"],
929
- "add3": {"a": "a", "b": "b"},
930
- }
931
- )
932
- assert_xml_equals(_get_element(xml_model), basic_xml)
933
-
934
- def test_list_wrapped_basic_types(self):
935
- """Test XML list and wrap, items is basic type and there is no itemsName."""
936
-
937
- basic_xml = ET.fromstring(
938
- """<?xml version="1.0"?>
939
- <AppleBarrel>
940
- <GoodApples>
941
- <GoodApples>granny</GoodApples>
942
- <GoodApples>fuji</GoodApples>
943
- </GoodApples>
944
- </AppleBarrel>"""
945
- )
946
-
947
- class AppleBarrel(Model):
948
- good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples"})
949
-
950
- def __init__(self, *args, **kwargs):
951
- super().__init__(*args, **kwargs)
952
-
953
- _xml = {"name": "AppleBarrel"}
954
-
955
- xml_model = AppleBarrel(good_apples=["granny", "fuji"])
956
- assert_xml_equals(_get_element(xml_model), basic_xml)
957
-
958
- def test_list_not_wrapped_basic_types(self):
959
- """Test XML list and no wrap, items is basic type and there is no itemsName."""
960
-
961
- basic_xml = ET.fromstring(
962
- """<?xml version="1.0"?>
963
- <AppleBarrel>
964
- <GoodApples>granny</GoodApples>
965
- <GoodApples>fuji</GoodApples>
966
- </AppleBarrel>"""
967
- )
968
-
969
- class AppleBarrel(Model):
970
- good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True})
971
-
972
- def __init__(self, *args, **kwargs):
973
- super().__init__(*args, **kwargs)
974
-
975
- _xml = {"name": "AppleBarrel"}
976
-
977
- xml_model = AppleBarrel(good_apples=["granny", "fuji"])
978
- assert_xml_equals(_get_element(xml_model), basic_xml)
979
-
980
- def test_list_wrapped_basic_types_items_name(self):
981
- """Test XML list and wrap, items is basic type and itemsName."""
982
-
983
- basic_xml = ET.fromstring(
984
- """<?xml version="1.0"?>
985
- <AppleBarrel>
986
- <GoodApples>
987
- <string>granny</string>
988
- <string>fuji</string>
989
- </GoodApples>
990
- </AppleBarrel>"""
991
- )
992
-
993
- class AppleBarrel(Model):
994
- good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "string"})
995
-
996
- def __init__(self, *args, **kwargs):
997
- super().__init__(*args, **kwargs)
998
-
999
- _xml = {"name": "AppleBarrel"}
1000
-
1001
- xml_model = AppleBarrel(good_apples=["granny", "fuji"])
1002
- assert_xml_equals(_get_element(xml_model), basic_xml)
1003
-
1004
- def test_list_not_wrapped_basic_types_items_name(self):
1005
- """Test XML list and no wrap, items is basic type and itemsName."""
1006
-
1007
- basic_xml = ET.fromstring(
1008
- """<?xml version="1.0"?>
1009
- <AppleBarrel>
1010
- <string>granny</string>
1011
- <string>fuji</string>
1012
- </AppleBarrel>"""
1013
- )
1014
-
1015
- class AppleBarrel(Model):
1016
- good_apples: list[str] = rest_field(
1017
- name="GoodApples",
1018
- xml={"name": "GoodApples", "unwrapped": True, "itemsName": "string"},
1019
- )
1020
-
1021
- def __init__(self, *args, **kwargs):
1022
- super().__init__(*args, **kwargs)
1023
-
1024
- _xml = {"name": "AppleBarrel"}
1025
-
1026
- xml_model = AppleBarrel(good_apples=["granny", "fuji"])
1027
- assert_xml_equals(_get_element(xml_model), basic_xml)
1028
-
1029
- def test_list_wrapped_complex_types(self):
1030
- """Test XML list and wrap, items is ref."""
1031
-
1032
- basic_xml = ET.fromstring(
1033
- """<?xml version="1.0"?>
1034
- <AppleBarrel>
1035
- <GoodApples>
1036
- <Apple name="granny"/>
1037
- <Apple name="fuji"/>
1038
- </GoodApples>
1039
- </AppleBarrel>"""
1040
- )
1041
-
1042
- class Apple(Model):
1043
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
1044
-
1045
- def __init__(self, *args, **kwargs):
1046
- super().__init__(*args, **kwargs)
1047
-
1048
- _xml = {"name": "Apple"}
1049
-
1050
- class AppleBarrel(Model):
1051
- good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples"})
1052
-
1053
- def __init__(self, *args, **kwargs):
1054
- super().__init__(*args, **kwargs)
1055
-
1056
- _xml = {"name": "AppleBarrel"}
1057
-
1058
- test = AppleBarrel({"GoodApples": [{"name": "granny"}, {"name": "fuji"}]})
1059
- xml_model = AppleBarrel(good_apples=[Apple(name="granny"), Apple(name="fuji")])
1060
- assert_xml_equals(_get_element(xml_model), basic_xml)
1061
-
1062
- def test_list_not_wrapped_complex_types(self):
1063
- """Test XML list and wrap, items is ref."""
1064
-
1065
- basic_xml = ET.fromstring(
1066
- """<?xml version="1.0"?>
1067
- <AppleBarrel>
1068
- <Apple name="granny"/>
1069
- <Apple name="fuji"/>
1070
- </AppleBarrel>"""
1071
- )
1072
-
1073
- class Apple(Model):
1074
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
1075
-
1076
- def __init__(self, *args, **kwargs):
1077
- super().__init__(*args, **kwargs)
1078
-
1079
- _xml = {"name": "Apple"}
1080
-
1081
- class AppleBarrel(Model):
1082
- good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True})
1083
-
1084
- def __init__(self, *args, **kwargs):
1085
- super().__init__(*args, **kwargs)
1086
-
1087
- xml_model = AppleBarrel(good_apples=[Apple(name="granny"), Apple(name="fuji")])
1088
- assert_xml_equals(_get_element(xml_model), basic_xml)
1089
-
1090
- def test_two_complex_same_type(self):
1091
- """Two different attribute are same type"""
1092
-
1093
- basic_xml = ET.fromstring(
1094
- """<?xml version="1.0"?>
1095
- <AppleBarrel>
1096
- <EuropeanApple name="granny"/>
1097
- <USAApple name="fuji"/>
1098
- </AppleBarrel>"""
1099
- )
1100
-
1101
- class Apple(Model):
1102
- name: str = rest_field(name="name", xml={"name": "name", "attribute": True})
1103
-
1104
- def __init__(self, *args, **kwargs):
1105
- super().__init__(*args, **kwargs)
1106
-
1107
- _xml = {"name": "Apple"}
1108
-
1109
- class AppleBarrel(Model):
1110
- eu_apple: Apple = rest_field(name="EuropeanApple", xml={"name": "EuropeanApple"})
1111
- us_apple: Apple = rest_field(name="USAApple", xml={"name": "USAApple"})
1112
-
1113
- def __init__(self, *args, **kwargs):
1114
- super().__init__(*args, **kwargs)
1115
-
1116
- xml_model = AppleBarrel(
1117
- eu_apple=Apple(name="granny"),
1118
- us_apple=Apple(name="fuji"),
1119
- )
1120
- assert_xml_equals(_get_element(xml_model), basic_xml)
1121
-
1122
- def test_basic_namespace(self):
1123
- """Test an ultra basic XML."""
1124
- basic_xml = ET.fromstring(
1125
- """<?xml version="1.0"?>
1126
- <Data xmlns:fictional="http://characters.example.com">
1127
- <fictional:Age>37</fictional:Age>
1128
- </Data>"""
1129
- )
1130
-
1131
- class XmlModel(Model):
1132
- age: int = rest_field(
1133
- name="age",
1134
- xml={
1135
- "name": "Age",
1136
- "prefix": "fictional",
1137
- "ns": "http://characters.example.com",
1138
- },
1139
- )
1140
-
1141
- def __init__(self, *args, **kwargs):
1142
- super().__init__(*args, **kwargs)
1143
-
1144
- _xml = {"name": "Data"}
1145
-
1146
- xml_model = XmlModel(
1147
- age=37,
1148
- )
1149
- assert_xml_equals(_get_element(xml_model), basic_xml)
1150
-
1151
- def test_complex_namespace(self):
1152
- """Test recursive namespace."""
1153
- basic_xml = ET.fromstring(
1154
- """<?xml version="1.0"?>
1155
- <entry xmlns="http://www.w3.org/2005/Atom" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1156
- <author>
1157
- <name>lmazuel</name>
1158
- </author>
1159
- <AuthorizationRules xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
1160
- <AuthorizationRule i:type="SharedAccessAuthorizationRule">
1161
- <KeyName>testpolicy</KeyName>
1162
- </AuthorizationRule>
1163
- </AuthorizationRules>
1164
- <MessageCountDetails xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
1165
- <d2p1:ActiveMessageCount xmlns:d2p1="http://schemas.microsoft.com/netservices/2011/06/servicebus">12</d2p1:ActiveMessageCount>
1166
- </MessageCountDetails>
1167
- </entry>"""
1168
- )
1169
-
1170
- class QueueDescriptionResponseAuthor(Model):
1171
- name: str = rest_field(name="name", xml={"ns": "http://www.w3.org/2005/Atom"})
1172
-
1173
- def __init__(self, *args, **kwargs):
1174
- super().__init__(*args, **kwargs)
1175
-
1176
- _xml = {"ns": "http://www.w3.org/2005/Atom"}
1177
-
1178
- class AuthorizationRule(Model):
1179
- type: str = rest_field(
1180
- name="type",
1181
- xml={
1182
- "attribute": True,
1183
- "prefix": "i",
1184
- "ns": "http://www.w3.org/2001/XMLSchema-instance",
1185
- },
1186
- )
1187
- key_name: str = rest_field(
1188
- name="KeyName",
1189
- xml={"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"},
1190
- )
1191
-
1192
- def __init__(self, *args, **kwargs):
1193
- super().__init__(*args, **kwargs)
1194
-
1195
- _xml = {"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"}
1196
-
1197
- class MessageCountDetails(Model):
1198
- active_message_count: int = rest_field(
1199
- name="ActiveMessageCount",
1200
- xml={
1201
- "prefix": "d2p1",
1202
- "ns": "http://schemas.microsoft.com/netservices/2011/06/servicebus",
1203
- },
1204
- )
1205
-
1206
- def __init__(self, *args, **kwargs):
1207
- super().__init__(*args, **kwargs)
1208
-
1209
- _xml = {
1210
- "name": "CountDetails",
1211
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
1212
- }
1213
-
1214
- class XmlRoot(Model):
1215
- author: QueueDescriptionResponseAuthor = rest_field(name="author")
1216
- authorization_rules: list[AuthorizationRule] = rest_field(
1217
- name="AuthorizationRules",
1218
- xml={
1219
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
1220
- },
1221
- )
1222
- message_count_details: MessageCountDetails = rest_field(
1223
- name="MessageCountDetails",
1224
- xml={
1225
- "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
1226
- },
1227
- )
1228
-
1229
- def __init__(self, *args, **kwargs):
1230
- super().__init__(*args, **kwargs)
1231
-
1232
- _xml = {"name": "entry", "ns": "http://www.w3.org/2005/Atom"}
1233
-
1234
- xml_model = XmlRoot(
1235
- author=QueueDescriptionResponseAuthor(name="lmazuel"),
1236
- authorization_rules=[AuthorizationRule(type="SharedAccessAuthorizationRule", key_name="testpolicy")],
1237
- message_count_details=MessageCountDetails(active_message_count=12),
1238
- )
1239
- assert_xml_equals(_get_element(xml_model), basic_xml)