airbyte-cdk 0.72.0__py3-none-any.whl → 6.13.1.dev4106__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (517) hide show
  1. airbyte_cdk/__init__.py +355 -6
  2. airbyte_cdk/cli/__init__.py +1 -0
  3. airbyte_cdk/cli/source_declarative_manifest/__init__.py +5 -0
  4. airbyte_cdk/cli/source_declarative_manifest/_run.py +230 -0
  5. airbyte_cdk/cli/source_declarative_manifest/spec.json +17 -0
  6. airbyte_cdk/config_observation.py +29 -10
  7. airbyte_cdk/connector.py +24 -24
  8. airbyte_cdk/connector_builder/README.md +53 -0
  9. airbyte_cdk/connector_builder/connector_builder_handler.py +37 -11
  10. airbyte_cdk/connector_builder/main.py +45 -13
  11. airbyte_cdk/connector_builder/message_grouper.py +189 -50
  12. airbyte_cdk/connector_builder/models.py +3 -2
  13. airbyte_cdk/destinations/__init__.py +4 -3
  14. airbyte_cdk/destinations/destination.py +54 -20
  15. airbyte_cdk/destinations/vector_db_based/README.md +37 -0
  16. airbyte_cdk/destinations/vector_db_based/config.py +40 -17
  17. airbyte_cdk/destinations/vector_db_based/document_processor.py +56 -17
  18. airbyte_cdk/destinations/vector_db_based/embedder.py +57 -15
  19. airbyte_cdk/destinations/vector_db_based/test_utils.py +14 -4
  20. airbyte_cdk/destinations/vector_db_based/utils.py +8 -2
  21. airbyte_cdk/destinations/vector_db_based/writer.py +24 -5
  22. airbyte_cdk/entrypoint.py +153 -44
  23. airbyte_cdk/exception_handler.py +21 -3
  24. airbyte_cdk/logger.py +30 -44
  25. airbyte_cdk/models/__init__.py +13 -2
  26. airbyte_cdk/models/airbyte_protocol.py +86 -1
  27. airbyte_cdk/models/airbyte_protocol_serializers.py +44 -0
  28. airbyte_cdk/models/file_transfer_record_message.py +13 -0
  29. airbyte_cdk/models/well_known_types.py +1 -1
  30. airbyte_cdk/sources/__init__.py +5 -1
  31. airbyte_cdk/sources/abstract_source.py +125 -79
  32. airbyte_cdk/sources/concurrent_source/__init__.py +7 -2
  33. airbyte_cdk/sources/concurrent_source/concurrent_read_processor.py +102 -36
  34. airbyte_cdk/sources/concurrent_source/concurrent_source.py +29 -36
  35. airbyte_cdk/sources/concurrent_source/concurrent_source_adapter.py +94 -10
  36. airbyte_cdk/sources/concurrent_source/stream_thread_exception.py +25 -0
  37. airbyte_cdk/sources/concurrent_source/thread_pool_manager.py +20 -14
  38. airbyte_cdk/sources/config.py +3 -2
  39. airbyte_cdk/sources/connector_state_manager.py +49 -83
  40. airbyte_cdk/sources/declarative/async_job/job.py +52 -0
  41. airbyte_cdk/sources/declarative/async_job/job_orchestrator.py +497 -0
  42. airbyte_cdk/sources/declarative/async_job/job_tracker.py +75 -0
  43. airbyte_cdk/sources/declarative/async_job/repository.py +35 -0
  44. airbyte_cdk/sources/declarative/async_job/status.py +24 -0
  45. airbyte_cdk/sources/declarative/async_job/timer.py +39 -0
  46. airbyte_cdk/sources/declarative/auth/__init__.py +2 -3
  47. airbyte_cdk/sources/declarative/auth/declarative_authenticator.py +3 -1
  48. airbyte_cdk/sources/declarative/auth/jwt.py +191 -0
  49. airbyte_cdk/sources/declarative/auth/oauth.py +60 -20
  50. airbyte_cdk/sources/declarative/auth/selective_authenticator.py +10 -2
  51. airbyte_cdk/sources/declarative/auth/token.py +28 -10
  52. airbyte_cdk/sources/declarative/auth/token_provider.py +9 -8
  53. airbyte_cdk/sources/declarative/checks/check_stream.py +16 -8
  54. airbyte_cdk/sources/declarative/checks/connection_checker.py +4 -2
  55. airbyte_cdk/sources/declarative/concurrency_level/__init__.py +7 -0
  56. airbyte_cdk/sources/declarative/concurrency_level/concurrency_level.py +50 -0
  57. airbyte_cdk/sources/declarative/concurrent_declarative_source.py +421 -0
  58. airbyte_cdk/sources/declarative/datetime/datetime_parser.py +4 -0
  59. airbyte_cdk/sources/declarative/datetime/min_max_datetime.py +26 -6
  60. airbyte_cdk/sources/declarative/declarative_component_schema.yaml +1213 -88
  61. airbyte_cdk/sources/declarative/declarative_source.py +5 -2
  62. airbyte_cdk/sources/declarative/declarative_stream.py +95 -9
  63. airbyte_cdk/sources/declarative/decoders/__init__.py +23 -2
  64. airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +97 -0
  65. airbyte_cdk/sources/declarative/decoders/decoder.py +11 -4
  66. airbyte_cdk/sources/declarative/decoders/json_decoder.py +92 -5
  67. airbyte_cdk/sources/declarative/decoders/noop_decoder.py +21 -0
  68. airbyte_cdk/sources/declarative/decoders/pagination_decoder_decorator.py +39 -0
  69. airbyte_cdk/sources/declarative/decoders/xml_decoder.py +98 -0
  70. airbyte_cdk/sources/declarative/extractors/__init__.py +12 -1
  71. airbyte_cdk/sources/declarative/extractors/dpath_extractor.py +29 -24
  72. airbyte_cdk/sources/declarative/extractors/http_selector.py +4 -5
  73. airbyte_cdk/sources/declarative/extractors/record_extractor.py +2 -3
  74. airbyte_cdk/sources/declarative/extractors/record_filter.py +65 -8
  75. airbyte_cdk/sources/declarative/extractors/record_selector.py +85 -26
  76. airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py +177 -0
  77. airbyte_cdk/sources/declarative/extractors/type_transformer.py +55 -0
  78. airbyte_cdk/sources/declarative/incremental/__init__.py +25 -3
  79. airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py +156 -48
  80. airbyte_cdk/sources/declarative/incremental/declarative_cursor.py +13 -0
  81. airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py +350 -0
  82. airbyte_cdk/sources/declarative/incremental/per_partition_cursor.py +159 -74
  83. airbyte_cdk/sources/declarative/incremental/per_partition_with_global.py +200 -0
  84. airbyte_cdk/sources/declarative/incremental/resumable_full_refresh_cursor.py +122 -0
  85. airbyte_cdk/sources/declarative/interpolation/filters.py +27 -1
  86. airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py +23 -5
  87. airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py +12 -8
  88. airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py +13 -6
  89. airbyte_cdk/sources/declarative/interpolation/interpolated_string.py +21 -6
  90. airbyte_cdk/sources/declarative/interpolation/interpolation.py +9 -3
  91. airbyte_cdk/sources/declarative/interpolation/jinja.py +72 -37
  92. airbyte_cdk/sources/declarative/interpolation/macros.py +72 -17
  93. airbyte_cdk/sources/declarative/manifest_declarative_source.py +193 -52
  94. airbyte_cdk/sources/declarative/migrations/legacy_to_per_partition_state_migration.py +98 -0
  95. airbyte_cdk/sources/declarative/migrations/state_migration.py +24 -0
  96. airbyte_cdk/sources/declarative/models/__init__.py +1 -1
  97. airbyte_cdk/sources/declarative/models/declarative_component_schema.py +1329 -595
  98. airbyte_cdk/sources/declarative/parsers/custom_exceptions.py +2 -2
  99. airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py +26 -4
  100. airbyte_cdk/sources/declarative/parsers/manifest_reference_resolver.py +26 -15
  101. airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +1699 -226
  102. airbyte_cdk/sources/declarative/partition_routers/__init__.py +24 -4
  103. airbyte_cdk/sources/declarative/partition_routers/async_job_partition_router.py +65 -0
  104. airbyte_cdk/sources/declarative/partition_routers/cartesian_product_stream_slicer.py +176 -0
  105. airbyte_cdk/sources/declarative/partition_routers/list_partition_router.py +39 -9
  106. airbyte_cdk/sources/declarative/partition_routers/partition_router.py +62 -0
  107. airbyte_cdk/sources/declarative/partition_routers/single_partition_router.py +15 -3
  108. airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py +222 -39
  109. airbyte_cdk/sources/declarative/requesters/error_handlers/__init__.py +19 -5
  110. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +3 -1
  111. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/constant_backoff_strategy.py +19 -7
  112. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/exponential_backoff_strategy.py +19 -7
  113. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/header_helper.py +4 -2
  114. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_time_from_header_backoff_strategy.py +41 -9
  115. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_until_time_from_header_backoff_strategy.py +29 -14
  116. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategy.py +5 -13
  117. airbyte_cdk/sources/declarative/requesters/error_handlers/composite_error_handler.py +32 -16
  118. airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py +46 -56
  119. airbyte_cdk/sources/declarative/requesters/error_handlers/default_http_response_filter.py +40 -0
  120. airbyte_cdk/sources/declarative/requesters/error_handlers/error_handler.py +6 -32
  121. airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py +119 -41
  122. airbyte_cdk/sources/declarative/requesters/http_job_repository.py +228 -0
  123. airbyte_cdk/sources/declarative/requesters/http_requester.py +98 -344
  124. airbyte_cdk/sources/declarative/requesters/paginators/__init__.py +14 -3
  125. airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py +105 -46
  126. airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py +14 -8
  127. airbyte_cdk/sources/declarative/requesters/paginators/paginator.py +19 -8
  128. airbyte_cdk/sources/declarative/requesters/paginators/strategies/__init__.py +9 -3
  129. airbyte_cdk/sources/declarative/requesters/paginators/strategies/cursor_pagination_strategy.py +53 -21
  130. airbyte_cdk/sources/declarative/requesters/paginators/strategies/offset_increment.py +42 -19
  131. airbyte_cdk/sources/declarative/requesters/paginators/strategies/page_increment.py +25 -12
  132. airbyte_cdk/sources/declarative/requesters/paginators/strategies/pagination_strategy.py +13 -10
  133. airbyte_cdk/sources/declarative/requesters/paginators/strategies/stop_condition.py +26 -13
  134. airbyte_cdk/sources/declarative/requesters/request_options/__init__.py +15 -2
  135. airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py +91 -0
  136. airbyte_cdk/sources/declarative/requesters/request_options/default_request_options_provider.py +60 -0
  137. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_nested_request_input_provider.py +31 -14
  138. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py +27 -15
  139. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py +63 -10
  140. airbyte_cdk/sources/declarative/requesters/request_options/request_options_provider.py +1 -1
  141. airbyte_cdk/sources/declarative/requesters/requester.py +9 -17
  142. airbyte_cdk/sources/declarative/resolvers/__init__.py +41 -0
  143. airbyte_cdk/sources/declarative/resolvers/components_resolver.py +55 -0
  144. airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py +136 -0
  145. airbyte_cdk/sources/declarative/resolvers/http_components_resolver.py +112 -0
  146. airbyte_cdk/sources/declarative/retrievers/__init__.py +6 -2
  147. airbyte_cdk/sources/declarative/retrievers/async_retriever.py +100 -0
  148. airbyte_cdk/sources/declarative/retrievers/retriever.py +1 -3
  149. airbyte_cdk/sources/declarative/retrievers/simple_retriever.py +228 -72
  150. airbyte_cdk/sources/declarative/schema/__init__.py +14 -1
  151. airbyte_cdk/sources/declarative/schema/default_schema_loader.py +5 -3
  152. airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py +236 -0
  153. airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py +8 -8
  154. airbyte_cdk/sources/declarative/spec/spec.py +12 -5
  155. airbyte_cdk/sources/declarative/stream_slicers/__init__.py +1 -2
  156. airbyte_cdk/sources/declarative/stream_slicers/declarative_partition_generator.py +88 -0
  157. airbyte_cdk/sources/declarative/stream_slicers/stream_slicer.py +9 -14
  158. airbyte_cdk/sources/declarative/transformations/add_fields.py +19 -11
  159. airbyte_cdk/sources/declarative/transformations/flatten_fields.py +52 -0
  160. airbyte_cdk/sources/declarative/transformations/keys_replace_transformation.py +61 -0
  161. airbyte_cdk/sources/declarative/transformations/keys_to_lower_transformation.py +22 -0
  162. airbyte_cdk/sources/declarative/transformations/keys_to_snake_transformation.py +68 -0
  163. airbyte_cdk/sources/declarative/transformations/remove_fields.py +13 -10
  164. airbyte_cdk/sources/declarative/transformations/transformation.py +5 -5
  165. airbyte_cdk/sources/declarative/types.py +19 -110
  166. airbyte_cdk/sources/declarative/yaml_declarative_source.py +31 -10
  167. airbyte_cdk/sources/embedded/base_integration.py +16 -5
  168. airbyte_cdk/sources/embedded/catalog.py +16 -4
  169. airbyte_cdk/sources/embedded/runner.py +19 -3
  170. airbyte_cdk/sources/embedded/tools.py +5 -2
  171. airbyte_cdk/sources/file_based/README.md +152 -0
  172. airbyte_cdk/sources/file_based/__init__.py +24 -0
  173. airbyte_cdk/sources/file_based/availability_strategy/__init__.py +9 -2
  174. airbyte_cdk/sources/file_based/availability_strategy/abstract_file_based_availability_strategy.py +22 -6
  175. airbyte_cdk/sources/file_based/availability_strategy/default_file_based_availability_strategy.py +46 -10
  176. airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py +58 -10
  177. airbyte_cdk/sources/file_based/config/avro_format.py +2 -1
  178. airbyte_cdk/sources/file_based/config/csv_format.py +29 -10
  179. airbyte_cdk/sources/file_based/config/excel_format.py +18 -0
  180. airbyte_cdk/sources/file_based/config/file_based_stream_config.py +16 -4
  181. airbyte_cdk/sources/file_based/config/jsonl_format.py +2 -1
  182. airbyte_cdk/sources/file_based/config/parquet_format.py +2 -1
  183. airbyte_cdk/sources/file_based/config/unstructured_format.py +13 -5
  184. airbyte_cdk/sources/file_based/discovery_policy/__init__.py +6 -2
  185. airbyte_cdk/sources/file_based/discovery_policy/abstract_discovery_policy.py +2 -4
  186. airbyte_cdk/sources/file_based/discovery_policy/default_discovery_policy.py +7 -2
  187. airbyte_cdk/sources/file_based/exceptions.py +52 -15
  188. airbyte_cdk/sources/file_based/file_based_source.py +163 -33
  189. airbyte_cdk/sources/file_based/file_based_stream_reader.py +83 -5
  190. airbyte_cdk/sources/file_based/file_types/__init__.py +14 -1
  191. airbyte_cdk/sources/file_based/file_types/avro_parser.py +75 -24
  192. airbyte_cdk/sources/file_based/file_types/csv_parser.py +116 -34
  193. airbyte_cdk/sources/file_based/file_types/excel_parser.py +196 -0
  194. airbyte_cdk/sources/file_based/file_types/file_transfer.py +37 -0
  195. airbyte_cdk/sources/file_based/file_types/file_type_parser.py +4 -1
  196. airbyte_cdk/sources/file_based/file_types/jsonl_parser.py +24 -8
  197. airbyte_cdk/sources/file_based/file_types/parquet_parser.py +60 -18
  198. airbyte_cdk/sources/file_based/file_types/unstructured_parser.py +145 -41
  199. airbyte_cdk/sources/file_based/remote_file.py +1 -1
  200. airbyte_cdk/sources/file_based/schema_helpers.py +38 -10
  201. airbyte_cdk/sources/file_based/schema_validation_policies/__init__.py +3 -1
  202. airbyte_cdk/sources/file_based/schema_validation_policies/abstract_schema_validation_policy.py +3 -1
  203. airbyte_cdk/sources/file_based/schema_validation_policies/default_schema_validation_policies.py +16 -5
  204. airbyte_cdk/sources/file_based/stream/abstract_file_based_stream.py +50 -13
  205. airbyte_cdk/sources/file_based/stream/concurrent/adapters.py +67 -27
  206. airbyte_cdk/sources/file_based/stream/concurrent/cursor/__init__.py +5 -1
  207. airbyte_cdk/sources/file_based/stream/concurrent/cursor/abstract_concurrent_file_based_cursor.py +14 -23
  208. airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_concurrent_cursor.py +54 -18
  209. airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_final_state_cursor.py +21 -9
  210. airbyte_cdk/sources/file_based/stream/cursor/abstract_file_based_cursor.py +3 -1
  211. airbyte_cdk/sources/file_based/stream/cursor/default_file_based_cursor.py +27 -10
  212. airbyte_cdk/sources/file_based/stream/default_file_based_stream.py +175 -45
  213. airbyte_cdk/sources/http_logger.py +8 -3
  214. airbyte_cdk/sources/message/__init__.py +7 -1
  215. airbyte_cdk/sources/message/repository.py +18 -4
  216. airbyte_cdk/sources/source.py +42 -38
  217. airbyte_cdk/sources/streams/__init__.py +2 -2
  218. airbyte_cdk/sources/streams/availability_strategy.py +54 -3
  219. airbyte_cdk/sources/streams/call_rate.py +64 -21
  220. airbyte_cdk/sources/streams/checkpoint/__init__.py +26 -0
  221. airbyte_cdk/sources/streams/checkpoint/checkpoint_reader.py +335 -0
  222. airbyte_cdk/sources/{declarative/incremental → streams/checkpoint}/cursor.py +17 -14
  223. airbyte_cdk/sources/streams/checkpoint/per_partition_key_serializer.py +22 -0
  224. airbyte_cdk/sources/streams/checkpoint/resumable_full_refresh_cursor.py +51 -0
  225. airbyte_cdk/sources/streams/checkpoint/substream_resumable_full_refresh_cursor.py +110 -0
  226. airbyte_cdk/sources/streams/concurrent/README.md +7 -0
  227. airbyte_cdk/sources/streams/concurrent/abstract_stream.py +7 -2
  228. airbyte_cdk/sources/streams/concurrent/adapters.py +84 -75
  229. airbyte_cdk/sources/streams/concurrent/availability_strategy.py +30 -2
  230. airbyte_cdk/sources/streams/concurrent/cursor.py +298 -42
  231. airbyte_cdk/sources/streams/concurrent/default_stream.py +12 -3
  232. airbyte_cdk/sources/streams/concurrent/exceptions.py +3 -0
  233. airbyte_cdk/sources/streams/concurrent/helpers.py +14 -3
  234. airbyte_cdk/sources/streams/concurrent/partition_enqueuer.py +12 -3
  235. airbyte_cdk/sources/streams/concurrent/partition_reader.py +10 -3
  236. airbyte_cdk/sources/streams/concurrent/partitions/partition.py +1 -16
  237. airbyte_cdk/sources/streams/concurrent/partitions/stream_slicer.py +21 -0
  238. airbyte_cdk/sources/streams/concurrent/partitions/types.py +15 -5
  239. airbyte_cdk/sources/streams/concurrent/state_converters/abstract_stream_state_converter.py +109 -17
  240. airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py +90 -72
  241. airbyte_cdk/sources/streams/core.py +412 -87
  242. airbyte_cdk/sources/streams/http/__init__.py +2 -1
  243. airbyte_cdk/sources/streams/http/availability_strategy.py +12 -101
  244. airbyte_cdk/sources/streams/http/error_handlers/__init__.py +22 -0
  245. airbyte_cdk/sources/streams/http/error_handlers/backoff_strategy.py +28 -0
  246. airbyte_cdk/sources/streams/http/error_handlers/default_backoff_strategy.py +17 -0
  247. airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py +86 -0
  248. airbyte_cdk/sources/streams/http/error_handlers/error_handler.py +42 -0
  249. airbyte_cdk/sources/streams/http/error_handlers/error_message_parser.py +19 -0
  250. airbyte_cdk/sources/streams/http/error_handlers/http_status_error_handler.py +110 -0
  251. airbyte_cdk/sources/streams/http/error_handlers/json_error_message_parser.py +52 -0
  252. airbyte_cdk/sources/streams/http/error_handlers/response_models.py +65 -0
  253. airbyte_cdk/sources/streams/http/exceptions.py +27 -7
  254. airbyte_cdk/sources/streams/http/http.py +369 -246
  255. airbyte_cdk/sources/streams/http/http_client.py +531 -0
  256. airbyte_cdk/sources/streams/http/rate_limiting.py +76 -12
  257. airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +28 -9
  258. airbyte_cdk/sources/streams/http/requests_native_auth/abstract_token.py +2 -1
  259. airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +90 -35
  260. airbyte_cdk/sources/streams/http/requests_native_auth/token.py +13 -3
  261. airbyte_cdk/sources/types.py +154 -0
  262. airbyte_cdk/sources/utils/record_helper.py +36 -21
  263. airbyte_cdk/sources/utils/schema_helpers.py +13 -6
  264. airbyte_cdk/sources/utils/slice_logger.py +4 -1
  265. airbyte_cdk/sources/utils/transform.py +54 -20
  266. airbyte_cdk/sql/_util/hashing.py +34 -0
  267. airbyte_cdk/sql/_util/name_normalizers.py +92 -0
  268. airbyte_cdk/sql/constants.py +32 -0
  269. airbyte_cdk/sql/exceptions.py +235 -0
  270. airbyte_cdk/sql/secrets.py +123 -0
  271. airbyte_cdk/sql/shared/__init__.py +15 -0
  272. airbyte_cdk/sql/shared/catalog_providers.py +145 -0
  273. airbyte_cdk/sql/shared/sql_processor.py +786 -0
  274. airbyte_cdk/sql/types.py +160 -0
  275. airbyte_cdk/test/catalog_builder.py +70 -18
  276. airbyte_cdk/test/entrypoint_wrapper.py +117 -42
  277. airbyte_cdk/test/mock_http/__init__.py +1 -1
  278. airbyte_cdk/test/mock_http/matcher.py +6 -0
  279. airbyte_cdk/test/mock_http/mocker.py +57 -10
  280. airbyte_cdk/test/mock_http/request.py +19 -3
  281. airbyte_cdk/test/mock_http/response.py +3 -1
  282. airbyte_cdk/test/mock_http/response_builder.py +32 -16
  283. airbyte_cdk/test/state_builder.py +18 -10
  284. airbyte_cdk/test/utils/__init__.py +1 -0
  285. airbyte_cdk/test/utils/data.py +24 -0
  286. airbyte_cdk/test/utils/http_mocking.py +16 -0
  287. airbyte_cdk/test/utils/manifest_only_fixtures.py +60 -0
  288. airbyte_cdk/test/utils/reading.py +26 -0
  289. airbyte_cdk/utils/__init__.py +2 -1
  290. airbyte_cdk/utils/airbyte_secrets_utils.py +5 -3
  291. airbyte_cdk/utils/analytics_message.py +10 -2
  292. airbyte_cdk/utils/datetime_format_inferrer.py +4 -1
  293. airbyte_cdk/utils/event_timing.py +10 -10
  294. airbyte_cdk/utils/mapping_helpers.py +3 -1
  295. airbyte_cdk/utils/message_utils.py +20 -11
  296. airbyte_cdk/utils/print_buffer.py +75 -0
  297. airbyte_cdk/utils/schema_inferrer.py +198 -28
  298. airbyte_cdk/utils/slice_hasher.py +30 -0
  299. airbyte_cdk/utils/spec_schema_transformations.py +6 -3
  300. airbyte_cdk/utils/stream_status_utils.py +8 -1
  301. airbyte_cdk/utils/traced_exception.py +61 -21
  302. airbyte_cdk-6.13.1.dev4106.dist-info/METADATA +109 -0
  303. airbyte_cdk-6.13.1.dev4106.dist-info/RECORD +349 -0
  304. {airbyte_cdk-0.72.0.dist-info → airbyte_cdk-6.13.1.dev4106.dist-info}/WHEEL +1 -2
  305. airbyte_cdk-6.13.1.dev4106.dist-info/entry_points.txt +3 -0
  306. airbyte_cdk/sources/declarative/create_partial.py +0 -92
  307. airbyte_cdk/sources/declarative/parsers/class_types_registry.py +0 -102
  308. airbyte_cdk/sources/declarative/parsers/default_implementation_registry.py +0 -64
  309. airbyte_cdk/sources/declarative/requesters/error_handlers/response_action.py +0 -16
  310. airbyte_cdk/sources/declarative/requesters/error_handlers/response_status.py +0 -68
  311. airbyte_cdk/sources/declarative/stream_slicers/cartesian_product_stream_slicer.py +0 -114
  312. airbyte_cdk/sources/deprecated/base_source.py +0 -94
  313. airbyte_cdk/sources/deprecated/client.py +0 -99
  314. airbyte_cdk/sources/singer/__init__.py +0 -8
  315. airbyte_cdk/sources/singer/singer_helpers.py +0 -304
  316. airbyte_cdk/sources/singer/source.py +0 -186
  317. airbyte_cdk/sources/streams/concurrent/partitions/record.py +0 -23
  318. airbyte_cdk/sources/streams/http/auth/__init__.py +0 -17
  319. airbyte_cdk/sources/streams/http/auth/core.py +0 -29
  320. airbyte_cdk/sources/streams/http/auth/oauth.py +0 -113
  321. airbyte_cdk/sources/streams/http/auth/token.py +0 -47
  322. airbyte_cdk/sources/streams/utils/stream_helper.py +0 -40
  323. airbyte_cdk/sources/utils/catalog_helpers.py +0 -22
  324. airbyte_cdk/sources/utils/schema_models.py +0 -84
  325. airbyte_cdk-0.72.0.dist-info/METADATA +0 -243
  326. airbyte_cdk-0.72.0.dist-info/RECORD +0 -466
  327. airbyte_cdk-0.72.0.dist-info/top_level.txt +0 -3
  328. source_declarative_manifest/main.py +0 -29
  329. unit_tests/connector_builder/__init__.py +0 -3
  330. unit_tests/connector_builder/test_connector_builder_handler.py +0 -871
  331. unit_tests/connector_builder/test_message_grouper.py +0 -713
  332. unit_tests/connector_builder/utils.py +0 -27
  333. unit_tests/destinations/test_destination.py +0 -243
  334. unit_tests/singer/test_singer_helpers.py +0 -56
  335. unit_tests/singer/test_singer_source.py +0 -112
  336. unit_tests/sources/__init__.py +0 -0
  337. unit_tests/sources/concurrent_source/__init__.py +0 -3
  338. unit_tests/sources/concurrent_source/test_concurrent_source_adapter.py +0 -106
  339. unit_tests/sources/declarative/__init__.py +0 -3
  340. unit_tests/sources/declarative/auth/__init__.py +0 -3
  341. unit_tests/sources/declarative/auth/test_oauth.py +0 -331
  342. unit_tests/sources/declarative/auth/test_selective_authenticator.py +0 -39
  343. unit_tests/sources/declarative/auth/test_session_token_auth.py +0 -182
  344. unit_tests/sources/declarative/auth/test_token_auth.py +0 -200
  345. unit_tests/sources/declarative/auth/test_token_provider.py +0 -73
  346. unit_tests/sources/declarative/checks/__init__.py +0 -3
  347. unit_tests/sources/declarative/checks/test_check_stream.py +0 -146
  348. unit_tests/sources/declarative/decoders/__init__.py +0 -0
  349. unit_tests/sources/declarative/decoders/test_json_decoder.py +0 -16
  350. unit_tests/sources/declarative/external_component.py +0 -13
  351. unit_tests/sources/declarative/extractors/__init__.py +0 -3
  352. unit_tests/sources/declarative/extractors/test_dpath_extractor.py +0 -55
  353. unit_tests/sources/declarative/extractors/test_record_filter.py +0 -55
  354. unit_tests/sources/declarative/extractors/test_record_selector.py +0 -179
  355. unit_tests/sources/declarative/incremental/__init__.py +0 -0
  356. unit_tests/sources/declarative/incremental/test_datetime_based_cursor.py +0 -860
  357. unit_tests/sources/declarative/incremental/test_per_partition_cursor.py +0 -406
  358. unit_tests/sources/declarative/incremental/test_per_partition_cursor_integration.py +0 -332
  359. unit_tests/sources/declarative/interpolation/__init__.py +0 -3
  360. unit_tests/sources/declarative/interpolation/test_filters.py +0 -80
  361. unit_tests/sources/declarative/interpolation/test_interpolated_boolean.py +0 -40
  362. unit_tests/sources/declarative/interpolation/test_interpolated_mapping.py +0 -35
  363. unit_tests/sources/declarative/interpolation/test_interpolated_nested_mapping.py +0 -45
  364. unit_tests/sources/declarative/interpolation/test_interpolated_string.py +0 -25
  365. unit_tests/sources/declarative/interpolation/test_jinja.py +0 -240
  366. unit_tests/sources/declarative/interpolation/test_macros.py +0 -73
  367. unit_tests/sources/declarative/parsers/__init__.py +0 -3
  368. unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py +0 -406
  369. unit_tests/sources/declarative/parsers/test_manifest_reference_resolver.py +0 -139
  370. unit_tests/sources/declarative/parsers/test_model_to_component_factory.py +0 -1841
  371. unit_tests/sources/declarative/parsers/testing_components.py +0 -36
  372. unit_tests/sources/declarative/partition_routers/__init__.py +0 -3
  373. unit_tests/sources/declarative/partition_routers/test_list_partition_router.py +0 -155
  374. unit_tests/sources/declarative/partition_routers/test_single_partition_router.py +0 -14
  375. unit_tests/sources/declarative/partition_routers/test_substream_partition_router.py +0 -404
  376. unit_tests/sources/declarative/requesters/__init__.py +0 -3
  377. unit_tests/sources/declarative/requesters/error_handlers/__init__.py +0 -3
  378. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +0 -3
  379. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_constant_backoff.py +0 -34
  380. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_exponential_backoff.py +0 -36
  381. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_header_helper.py +0 -38
  382. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_wait_time_from_header.py +0 -35
  383. unit_tests/sources/declarative/requesters/error_handlers/backoff_strategies/test_wait_until_time_from_header.py +0 -64
  384. unit_tests/sources/declarative/requesters/error_handlers/test_composite_error_handler.py +0 -213
  385. unit_tests/sources/declarative/requesters/error_handlers/test_default_error_handler.py +0 -178
  386. unit_tests/sources/declarative/requesters/error_handlers/test_http_response_filter.py +0 -121
  387. unit_tests/sources/declarative/requesters/error_handlers/test_response_status.py +0 -44
  388. unit_tests/sources/declarative/requesters/paginators/__init__.py +0 -3
  389. unit_tests/sources/declarative/requesters/paginators/test_cursor_pagination_strategy.py +0 -64
  390. unit_tests/sources/declarative/requesters/paginators/test_default_paginator.py +0 -313
  391. unit_tests/sources/declarative/requesters/paginators/test_no_paginator.py +0 -12
  392. unit_tests/sources/declarative/requesters/paginators/test_offset_increment.py +0 -58
  393. unit_tests/sources/declarative/requesters/paginators/test_page_increment.py +0 -70
  394. unit_tests/sources/declarative/requesters/paginators/test_request_option.py +0 -43
  395. unit_tests/sources/declarative/requesters/paginators/test_stop_condition.py +0 -105
  396. unit_tests/sources/declarative/requesters/request_options/__init__.py +0 -3
  397. unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py +0 -101
  398. unit_tests/sources/declarative/requesters/test_http_requester.py +0 -974
  399. unit_tests/sources/declarative/requesters/test_interpolated_request_input_provider.py +0 -32
  400. unit_tests/sources/declarative/retrievers/__init__.py +0 -3
  401. unit_tests/sources/declarative/retrievers/test_simple_retriever.py +0 -542
  402. unit_tests/sources/declarative/schema/__init__.py +0 -6
  403. unit_tests/sources/declarative/schema/source_test/SourceTest.py +0 -8
  404. unit_tests/sources/declarative/schema/source_test/__init__.py +0 -3
  405. unit_tests/sources/declarative/schema/test_default_schema_loader.py +0 -32
  406. unit_tests/sources/declarative/schema/test_inline_schema_loader.py +0 -19
  407. unit_tests/sources/declarative/schema/test_json_file_schema_loader.py +0 -26
  408. unit_tests/sources/declarative/states/__init__.py +0 -3
  409. unit_tests/sources/declarative/stream_slicers/__init__.py +0 -3
  410. unit_tests/sources/declarative/stream_slicers/test_cartesian_product_stream_slicer.py +0 -225
  411. unit_tests/sources/declarative/test_create_partial.py +0 -83
  412. unit_tests/sources/declarative/test_declarative_stream.py +0 -103
  413. unit_tests/sources/declarative/test_manifest_declarative_source.py +0 -1260
  414. unit_tests/sources/declarative/test_types.py +0 -39
  415. unit_tests/sources/declarative/test_yaml_declarative_source.py +0 -148
  416. unit_tests/sources/file_based/__init__.py +0 -0
  417. unit_tests/sources/file_based/availability_strategy/__init__.py +0 -0
  418. unit_tests/sources/file_based/availability_strategy/test_default_file_based_availability_strategy.py +0 -100
  419. unit_tests/sources/file_based/config/__init__.py +0 -0
  420. unit_tests/sources/file_based/config/test_abstract_file_based_spec.py +0 -28
  421. unit_tests/sources/file_based/config/test_csv_format.py +0 -34
  422. unit_tests/sources/file_based/config/test_file_based_stream_config.py +0 -84
  423. unit_tests/sources/file_based/discovery_policy/__init__.py +0 -0
  424. unit_tests/sources/file_based/discovery_policy/test_default_discovery_policy.py +0 -31
  425. unit_tests/sources/file_based/file_types/__init__.py +0 -0
  426. unit_tests/sources/file_based/file_types/test_avro_parser.py +0 -243
  427. unit_tests/sources/file_based/file_types/test_csv_parser.py +0 -546
  428. unit_tests/sources/file_based/file_types/test_jsonl_parser.py +0 -158
  429. unit_tests/sources/file_based/file_types/test_parquet_parser.py +0 -274
  430. unit_tests/sources/file_based/file_types/test_unstructured_parser.py +0 -593
  431. unit_tests/sources/file_based/helpers.py +0 -70
  432. unit_tests/sources/file_based/in_memory_files_source.py +0 -211
  433. unit_tests/sources/file_based/scenarios/__init__.py +0 -0
  434. unit_tests/sources/file_based/scenarios/avro_scenarios.py +0 -744
  435. unit_tests/sources/file_based/scenarios/check_scenarios.py +0 -220
  436. unit_tests/sources/file_based/scenarios/concurrent_incremental_scenarios.py +0 -2844
  437. unit_tests/sources/file_based/scenarios/csv_scenarios.py +0 -3105
  438. unit_tests/sources/file_based/scenarios/file_based_source_builder.py +0 -91
  439. unit_tests/sources/file_based/scenarios/incremental_scenarios.py +0 -1926
  440. unit_tests/sources/file_based/scenarios/jsonl_scenarios.py +0 -930
  441. unit_tests/sources/file_based/scenarios/parquet_scenarios.py +0 -754
  442. unit_tests/sources/file_based/scenarios/scenario_builder.py +0 -234
  443. unit_tests/sources/file_based/scenarios/unstructured_scenarios.py +0 -608
  444. unit_tests/sources/file_based/scenarios/user_input_schema_scenarios.py +0 -746
  445. unit_tests/sources/file_based/scenarios/validation_policy_scenarios.py +0 -726
  446. unit_tests/sources/file_based/stream/__init__.py +0 -0
  447. unit_tests/sources/file_based/stream/concurrent/__init__.py +0 -0
  448. unit_tests/sources/file_based/stream/concurrent/test_adapters.py +0 -362
  449. unit_tests/sources/file_based/stream/concurrent/test_file_based_concurrent_cursor.py +0 -458
  450. unit_tests/sources/file_based/stream/test_default_file_based_cursor.py +0 -310
  451. unit_tests/sources/file_based/stream/test_default_file_based_stream.py +0 -244
  452. unit_tests/sources/file_based/test_file_based_scenarios.py +0 -320
  453. unit_tests/sources/file_based/test_file_based_stream_reader.py +0 -272
  454. unit_tests/sources/file_based/test_scenarios.py +0 -253
  455. unit_tests/sources/file_based/test_schema_helpers.py +0 -346
  456. unit_tests/sources/fixtures/__init__.py +0 -3
  457. unit_tests/sources/fixtures/source_test_fixture.py +0 -153
  458. unit_tests/sources/message/__init__.py +0 -0
  459. unit_tests/sources/message/test_repository.py +0 -153
  460. unit_tests/sources/streams/__init__.py +0 -0
  461. unit_tests/sources/streams/concurrent/__init__.py +0 -3
  462. unit_tests/sources/streams/concurrent/scenarios/__init__.py +0 -3
  463. unit_tests/sources/streams/concurrent/scenarios/incremental_scenarios.py +0 -250
  464. unit_tests/sources/streams/concurrent/scenarios/stream_facade_builder.py +0 -140
  465. unit_tests/sources/streams/concurrent/scenarios/stream_facade_scenarios.py +0 -452
  466. unit_tests/sources/streams/concurrent/scenarios/test_concurrent_scenarios.py +0 -76
  467. unit_tests/sources/streams/concurrent/scenarios/thread_based_concurrent_stream_scenarios.py +0 -418
  468. unit_tests/sources/streams/concurrent/scenarios/thread_based_concurrent_stream_source_builder.py +0 -142
  469. unit_tests/sources/streams/concurrent/scenarios/utils.py +0 -55
  470. unit_tests/sources/streams/concurrent/test_adapters.py +0 -380
  471. unit_tests/sources/streams/concurrent/test_concurrent_read_processor.py +0 -684
  472. unit_tests/sources/streams/concurrent/test_cursor.py +0 -139
  473. unit_tests/sources/streams/concurrent/test_datetime_state_converter.py +0 -369
  474. unit_tests/sources/streams/concurrent/test_default_stream.py +0 -197
  475. unit_tests/sources/streams/concurrent/test_partition_enqueuer.py +0 -90
  476. unit_tests/sources/streams/concurrent/test_partition_reader.py +0 -67
  477. unit_tests/sources/streams/concurrent/test_thread_pool_manager.py +0 -106
  478. unit_tests/sources/streams/http/__init__.py +0 -0
  479. unit_tests/sources/streams/http/auth/__init__.py +0 -0
  480. unit_tests/sources/streams/http/auth/test_auth.py +0 -173
  481. unit_tests/sources/streams/http/requests_native_auth/__init__.py +0 -0
  482. unit_tests/sources/streams/http/requests_native_auth/test_requests_native_auth.py +0 -423
  483. unit_tests/sources/streams/http/test_availability_strategy.py +0 -180
  484. unit_tests/sources/streams/http/test_http.py +0 -635
  485. unit_tests/sources/streams/test_availability_strategy.py +0 -70
  486. unit_tests/sources/streams/test_call_rate.py +0 -300
  487. unit_tests/sources/streams/test_stream_read.py +0 -405
  488. unit_tests/sources/streams/test_streams_core.py +0 -184
  489. unit_tests/sources/test_abstract_source.py +0 -1442
  490. unit_tests/sources/test_concurrent_source.py +0 -112
  491. unit_tests/sources/test_config.py +0 -92
  492. unit_tests/sources/test_connector_state_manager.py +0 -482
  493. unit_tests/sources/test_http_logger.py +0 -252
  494. unit_tests/sources/test_integration_source.py +0 -86
  495. unit_tests/sources/test_source.py +0 -684
  496. unit_tests/sources/test_source_read.py +0 -460
  497. unit_tests/test/__init__.py +0 -0
  498. unit_tests/test/mock_http/__init__.py +0 -0
  499. unit_tests/test/mock_http/test_matcher.py +0 -53
  500. unit_tests/test/mock_http/test_mocker.py +0 -214
  501. unit_tests/test/mock_http/test_request.py +0 -117
  502. unit_tests/test/mock_http/test_response_builder.py +0 -177
  503. unit_tests/test/test_entrypoint_wrapper.py +0 -240
  504. unit_tests/utils/__init__.py +0 -0
  505. unit_tests/utils/test_datetime_format_inferrer.py +0 -60
  506. unit_tests/utils/test_mapping_helpers.py +0 -54
  507. unit_tests/utils/test_message_utils.py +0 -91
  508. unit_tests/utils/test_rate_limiting.py +0 -26
  509. unit_tests/utils/test_schema_inferrer.py +0 -202
  510. unit_tests/utils/test_secret_utils.py +0 -135
  511. unit_tests/utils/test_stream_status_utils.py +0 -61
  512. unit_tests/utils/test_traced_exception.py +0 -107
  513. /airbyte_cdk/sources/{deprecated → declarative/async_job}/__init__.py +0 -0
  514. {source_declarative_manifest → airbyte_cdk/sources/declarative/migrations}/__init__.py +0 -0
  515. {unit_tests/destinations → airbyte_cdk/sql}/__init__.py +0 -0
  516. {unit_tests/singer → airbyte_cdk/sql/_util}/__init__.py +0 -0
  517. {airbyte_cdk-0.72.0.dist-info → airbyte_cdk-6.13.1.dev4106.dist-info}/LICENSE.txt +0 -0
@@ -1,1442 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- import copy
6
- import datetime
7
- import logging
8
- from collections import defaultdict
9
- from typing import Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Optional, Tuple, Union
10
- from unittest.mock import Mock, call
11
-
12
- import pytest
13
- from airbyte_cdk.models import (
14
- AirbyteCatalog,
15
- AirbyteConnectionStatus,
16
- AirbyteErrorTraceMessage,
17
- AirbyteLogMessage,
18
- AirbyteMessage,
19
- AirbyteRecordMessage,
20
- AirbyteStateBlob,
21
- AirbyteStateMessage,
22
- AirbyteStateType,
23
- AirbyteStream,
24
- AirbyteStreamState,
25
- AirbyteStreamStatus,
26
- AirbyteStreamStatusTraceMessage,
27
- AirbyteTraceMessage,
28
- ConfiguredAirbyteCatalog,
29
- ConfiguredAirbyteStream,
30
- DestinationSyncMode,
31
- FailureType,
32
- Level,
33
- Status,
34
- StreamDescriptor,
35
- SyncMode,
36
- TraceType,
37
- )
38
- from airbyte_cdk.models import Type
39
- from airbyte_cdk.models import Type as MessageType
40
- from airbyte_cdk.sources import AbstractSource
41
- from airbyte_cdk.sources.connector_state_manager import ConnectorStateManager
42
- from airbyte_cdk.sources.message import MessageRepository
43
- from airbyte_cdk.sources.streams import IncrementalMixin, Stream
44
- from airbyte_cdk.sources.utils.record_helper import stream_data_to_airbyte_message
45
- from airbyte_cdk.utils.airbyte_secrets_utils import update_secrets
46
- from airbyte_cdk.utils.traced_exception import AirbyteTracedException
47
- from pytest import fixture
48
-
49
- logger = logging.getLogger("airbyte")
50
-
51
-
52
- class MockSource(AbstractSource):
53
- def __init__(
54
- self,
55
- check_lambda: Callable[[], Tuple[bool, Optional[Any]]] = None,
56
- streams: List[Stream] = None,
57
- message_repository: MessageRepository = None,
58
- exception_on_missing_stream: bool = True,
59
- stop_sync_on_stream_failure: bool = False,
60
- ):
61
- self._streams = streams
62
- self.check_lambda = check_lambda
63
- self.exception_on_missing_stream = exception_on_missing_stream
64
- self._message_repository = message_repository
65
- self._stop_sync_on_stream_failure = stop_sync_on_stream_failure
66
-
67
- def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
68
- if self.check_lambda:
69
- return self.check_lambda()
70
- return False, "Missing callable."
71
-
72
- def streams(self, config: Mapping[str, Any]) -> List[Stream]:
73
- if not self._streams:
74
- raise Exception("Stream is not set")
75
- return self._streams
76
-
77
- @property
78
- def raise_exception_on_missing_stream(self) -> bool:
79
- return self.exception_on_missing_stream
80
-
81
- @property
82
- def per_stream_state_enabled(self) -> bool:
83
- return self.per_stream
84
-
85
- @property
86
- def message_repository(self):
87
- return self._message_repository
88
-
89
-
90
- class MockSourceWithStopSyncFalseOverride(MockSource):
91
- @property
92
- def stop_sync_on_stream_failure(self) -> bool:
93
- return False
94
-
95
-
96
- class StreamNoStateMethod(Stream):
97
- name = "managers"
98
- primary_key = None
99
-
100
- def read_records(self, *args, **kwargs) -> Iterable[Mapping[str, Any]]:
101
- return {}
102
-
103
-
104
- class MockStreamOverridesStateMethod(Stream, IncrementalMixin):
105
- name = "teams"
106
- primary_key = None
107
- cursor_field = "updated_at"
108
- _cursor_value = ""
109
- start_date = "1984-12-12"
110
-
111
- def read_records(self, *args, **kwargs) -> Iterable[Mapping[str, Any]]:
112
- return {}
113
-
114
- @property
115
- def state(self) -> MutableMapping[str, Any]:
116
- return {self.cursor_field: self._cursor_value} if self._cursor_value else {}
117
-
118
- @state.setter
119
- def state(self, value: MutableMapping[str, Any]):
120
- self._cursor_value = value.get(self.cursor_field, self.start_date)
121
-
122
-
123
- class StreamRaisesException(Stream):
124
- name = "lamentations"
125
- primary_key = None
126
-
127
- def __init__(self, exception_to_raise):
128
- self._exception_to_raise = exception_to_raise
129
-
130
- def read_records(self, *args, **kwargs) -> Iterable[Mapping[str, Any]]:
131
- raise self._exception_to_raise
132
-
133
-
134
- MESSAGE_FROM_REPOSITORY = Mock()
135
-
136
-
137
- @fixture
138
- def message_repository():
139
- message_repository = Mock(spec=MessageRepository)
140
- message_repository.consume_queue.return_value = [message for message in [MESSAGE_FROM_REPOSITORY]]
141
- return message_repository
142
-
143
-
144
- def test_successful_check():
145
- """Tests that if a source returns TRUE for the connection check the appropriate connectionStatus success message is returned"""
146
- expected = AirbyteConnectionStatus(status=Status.SUCCEEDED)
147
- assert expected == MockSource(check_lambda=lambda: (True, None)).check(logger, {})
148
-
149
-
150
- def test_failed_check():
151
- """Tests that if a source returns FALSE for the connection check the appropriate connectionStatus failure message is returned"""
152
- expected = AirbyteConnectionStatus(status=Status.FAILED, message="'womp womp'")
153
- assert expected == MockSource(check_lambda=lambda: (False, "womp womp")).check(logger, {})
154
-
155
-
156
- def test_raising_check(mocker):
157
- """Tests that if a source raises an unexpected exception the appropriate connectionStatus failure message is returned."""
158
- check_lambda = mocker.Mock(side_effect=BaseException("this should fail"))
159
- with pytest.raises(BaseException):
160
- MockSource(check_lambda=check_lambda).check(logger, {})
161
-
162
-
163
- class MockStream(Stream):
164
- def __init__(
165
- self,
166
- inputs_and_mocked_outputs: List[Tuple[Mapping[str, Any], Iterable[Mapping[str, Any]]]] = None,
167
- name: str = None,
168
- ):
169
- self._inputs_and_mocked_outputs = inputs_and_mocked_outputs
170
- self._name = name
171
-
172
- @property
173
- def name(self):
174
- return self._name
175
-
176
- def read_records(self, **kwargs) -> Iterable[Mapping[str, Any]]: # type: ignore
177
- # Remove None values
178
- kwargs = {k: v for k, v in kwargs.items() if v is not None}
179
- if self._inputs_and_mocked_outputs:
180
- for _input, output in self._inputs_and_mocked_outputs:
181
- if kwargs == _input:
182
- return output
183
-
184
- raise Exception(f"No mocked output supplied for input: {kwargs}. Mocked inputs/outputs: {self._inputs_and_mocked_outputs}")
185
-
186
- @property
187
- def primary_key(self) -> Optional[Union[str, List[str], List[List[str]]]]:
188
- return "pk"
189
-
190
-
191
- class MockStreamWithState(MockStream):
192
- cursor_field = "cursor"
193
-
194
- def __init__(self, inputs_and_mocked_outputs: List[Tuple[Mapping[str, Any], Iterable[Mapping[str, Any]]]], name: str, state=None):
195
- super().__init__(inputs_and_mocked_outputs, name)
196
- self._state = state
197
-
198
- @property
199
- def state(self):
200
- return self._state
201
-
202
- @state.setter
203
- def state(self, value):
204
- pass
205
-
206
-
207
- class MockStreamEmittingAirbyteMessages(MockStreamWithState):
208
- def __init__(
209
- self, inputs_and_mocked_outputs: List[Tuple[Mapping[str, Any], Iterable[AirbyteMessage]]] = None, name: str = None, state=None
210
- ):
211
- super().__init__(inputs_and_mocked_outputs, name, state)
212
- self._inputs_and_mocked_outputs = inputs_and_mocked_outputs
213
- self._name = name
214
-
215
- @property
216
- def name(self):
217
- return self._name
218
-
219
- @property
220
- def primary_key(self) -> Optional[Union[str, List[str], List[List[str]]]]:
221
- return "pk"
222
-
223
- @property
224
- def state(self) -> MutableMapping[str, Any]:
225
- return {self.cursor_field: self._cursor_value} if self._cursor_value else {}
226
-
227
- @state.setter
228
- def state(self, value: MutableMapping[str, Any]):
229
- self._cursor_value = value.get(self.cursor_field, self.start_date)
230
-
231
-
232
- def test_discover(mocker):
233
- """Tests that the appropriate AirbyteCatalog is returned from the discover method"""
234
- airbyte_stream1 = AirbyteStream(
235
- name="1",
236
- json_schema={},
237
- supported_sync_modes=[SyncMode.full_refresh, SyncMode.incremental],
238
- default_cursor_field=["cursor"],
239
- source_defined_cursor=True,
240
- source_defined_primary_key=[["pk"]],
241
- )
242
- airbyte_stream2 = AirbyteStream(name="2", json_schema={}, supported_sync_modes=[SyncMode.full_refresh])
243
-
244
- stream1 = MockStream()
245
- stream2 = MockStream()
246
- mocker.patch.object(stream1, "as_airbyte_stream", return_value=airbyte_stream1)
247
- mocker.patch.object(stream2, "as_airbyte_stream", return_value=airbyte_stream2)
248
-
249
- expected = AirbyteCatalog(streams=[airbyte_stream1, airbyte_stream2])
250
- src = MockSource(check_lambda=lambda: (True, None), streams=[stream1, stream2])
251
-
252
- assert expected == src.discover(logger, {})
253
-
254
-
255
- def test_read_nonexistent_stream_raises_exception(mocker):
256
- """Tests that attempting to sync a stream which the source does not return from the `streams` method raises an exception"""
257
- s1 = MockStream(name="s1")
258
- s2 = MockStream(name="this_stream_doesnt_exist_in_the_source")
259
-
260
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
261
-
262
- src = MockSource(streams=[s1])
263
- catalog = ConfiguredAirbyteCatalog(streams=[_configured_stream(s2, SyncMode.full_refresh)])
264
- with pytest.raises(KeyError):
265
- list(src.read(logger, {}, catalog))
266
-
267
-
268
- def test_read_nonexistent_stream_without_raises_exception(mocker):
269
- """Tests that attempting to sync a stream which the source does not return from the `streams` method raises an exception"""
270
- s1 = MockStream(name="s1")
271
- s2 = MockStream(name="this_stream_doesnt_exist_in_the_source")
272
-
273
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
274
-
275
- src = MockSource(streams=[s1], exception_on_missing_stream=False)
276
-
277
- catalog = ConfiguredAirbyteCatalog(streams=[_configured_stream(s2, SyncMode.full_refresh)])
278
- messages = list(src.read(logger, {}, catalog))
279
-
280
- assert messages == []
281
-
282
-
283
- def test_read_stream_emits_repository_message_before_record(mocker, message_repository):
284
- stream = MockStream(name="my_stream")
285
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
286
- mocker.patch.object(MockStream, "read_records", side_effect=[[{"a record": "a value"}, {"another record": "another value"}]])
287
- message_repository.consume_queue.side_effect = [[message for message in [MESSAGE_FROM_REPOSITORY]], [], []]
288
-
289
- source = MockSource(streams=[stream], message_repository=message_repository)
290
-
291
- messages = list(source.read(logger, {}, ConfiguredAirbyteCatalog(streams=[_configured_stream(stream, SyncMode.full_refresh)])))
292
-
293
- assert messages.count(MESSAGE_FROM_REPOSITORY) == 1
294
- record_messages = (message for message in messages if message.type == Type.RECORD)
295
- assert all(messages.index(MESSAGE_FROM_REPOSITORY) < messages.index(record) for record in record_messages)
296
-
297
-
298
- def test_read_stream_emits_repository_message_on_error(mocker, message_repository):
299
- stream = MockStream(name="my_stream")
300
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
301
- mocker.patch.object(MockStream, "read_records", side_effect=RuntimeError("error"))
302
- message_repository.consume_queue.return_value = [message for message in [MESSAGE_FROM_REPOSITORY]]
303
-
304
- source = MockSource(streams=[stream], message_repository=message_repository)
305
-
306
- with pytest.raises(AirbyteTracedException):
307
- messages = list(source.read(logger, {}, ConfiguredAirbyteCatalog(streams=[_configured_stream(stream, SyncMode.full_refresh)])))
308
- assert MESSAGE_FROM_REPOSITORY in messages
309
-
310
-
311
- def test_read_stream_with_error_gets_display_message(mocker):
312
- stream = MockStream(name="my_stream")
313
-
314
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
315
- mocker.patch.object(MockStream, "read_records", side_effect=RuntimeError("oh no!"))
316
-
317
- source = MockSource(streams=[stream])
318
- catalog = ConfiguredAirbyteCatalog(streams=[_configured_stream(stream, SyncMode.full_refresh)])
319
-
320
- # without get_error_display_message
321
- with pytest.raises(AirbyteTracedException):
322
- list(source.read(logger, {}, catalog))
323
-
324
- mocker.patch.object(MockStream, "get_error_display_message", return_value="my message")
325
-
326
- with pytest.raises(AirbyteTracedException) as exc:
327
- list(source.read(logger, {}, catalog))
328
- assert "oh no!" in exc.value.message
329
-
330
-
331
- GLOBAL_EMITTED_AT = 1
332
-
333
-
334
- def _as_record(stream: str, data: Dict[str, Any]) -> AirbyteMessage:
335
- return AirbyteMessage(
336
- type=Type.RECORD,
337
- record=AirbyteRecordMessage(stream=stream, data=data, emitted_at=GLOBAL_EMITTED_AT),
338
- )
339
-
340
-
341
- def _as_records(stream: str, data: List[Dict[str, Any]]) -> List[AirbyteMessage]:
342
- return [_as_record(stream, datum) for datum in data]
343
-
344
-
345
- def _as_stream_status(stream: str, status: AirbyteStreamStatus) -> AirbyteMessage:
346
- trace_message = AirbyteTraceMessage(
347
- emitted_at=datetime.datetime.now().timestamp() * 1000.0,
348
- type=TraceType.STREAM_STATUS,
349
- stream_status=AirbyteStreamStatusTraceMessage(
350
- stream_descriptor=StreamDescriptor(name=stream),
351
- status=status,
352
- ),
353
- )
354
-
355
- return AirbyteMessage(type=MessageType.TRACE, trace=trace_message)
356
-
357
-
358
- def _as_state(stream_name: str = "", per_stream_state: Dict[str, Any] = None):
359
- return AirbyteMessage(
360
- type=Type.STATE,
361
- state=AirbyteStateMessage(
362
- type=AirbyteStateType.STREAM,
363
- stream=AirbyteStreamState(
364
- stream_descriptor=StreamDescriptor(name=stream_name), stream_state=AirbyteStateBlob.parse_obj(per_stream_state)
365
- ),
366
- ),
367
- )
368
-
369
-
370
- def _as_error_trace(
371
- stream: str, error_message: str, internal_message: Optional[str], failure_type: Optional[FailureType], stack_trace: Optional[str]
372
- ) -> AirbyteMessage:
373
- trace_message = AirbyteTraceMessage(
374
- emitted_at=datetime.datetime.now().timestamp() * 1000.0,
375
- type=TraceType.ERROR,
376
- error=AirbyteErrorTraceMessage(
377
- stream_descriptor=StreamDescriptor(name=stream),
378
- message=error_message,
379
- internal_message=internal_message,
380
- failure_type=failure_type,
381
- stack_trace=stack_trace,
382
- ),
383
- )
384
-
385
- return AirbyteMessage(type=MessageType.TRACE, trace=trace_message)
386
-
387
-
388
- def _configured_stream(stream: Stream, sync_mode: SyncMode):
389
- return ConfiguredAirbyteStream(
390
- stream=stream.as_airbyte_stream(),
391
- sync_mode=sync_mode,
392
- destination_sync_mode=DestinationSyncMode.overwrite,
393
- )
394
-
395
-
396
- def _fix_emitted_at(messages: List[AirbyteMessage]) -> List[AirbyteMessage]:
397
- for msg in messages:
398
- if msg.type == Type.RECORD and msg.record:
399
- msg.record.emitted_at = GLOBAL_EMITTED_AT
400
- if msg.type == Type.TRACE and msg.trace:
401
- msg.trace.emitted_at = GLOBAL_EMITTED_AT
402
- return messages
403
-
404
-
405
- def test_valid_full_refresh_read_no_slices(mocker):
406
- """Tests that running a full refresh sync on streams which don't specify slices produces the expected AirbyteMessages"""
407
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
408
- s1 = MockStream([({"stream_state": {}, "sync_mode": SyncMode.full_refresh}, stream_output)], name="s1")
409
- s2 = MockStream([({"stream_state": {}, "sync_mode": SyncMode.full_refresh}, stream_output)], name="s2")
410
-
411
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
412
-
413
- src = MockSource(streams=[s1, s2])
414
- catalog = ConfiguredAirbyteCatalog(
415
- streams=[
416
- _configured_stream(s1, SyncMode.full_refresh),
417
- _configured_stream(s2, SyncMode.full_refresh),
418
- ]
419
- )
420
-
421
- expected = _fix_emitted_at(
422
- [
423
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
424
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
425
- *_as_records("s1", stream_output),
426
- _as_state("s1", {"__ab_full_refresh_state_message": True}),
427
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
428
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
429
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
430
- *_as_records("s2", stream_output),
431
- _as_state("s2", {"__ab_full_refresh_state_message": True}),
432
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
433
- ]
434
- )
435
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog)))
436
-
437
- assert expected == messages
438
-
439
-
440
- def test_valid_full_refresh_read_with_slices(mocker):
441
- """Tests that running a full refresh sync on streams which use slices produces the expected AirbyteMessages"""
442
- slices = [{"1": "1"}, {"2": "2"}]
443
- # When attempting to sync a slice, just output that slice as a record
444
- s1 = MockStream(
445
- [({"stream_state": {}, "sync_mode": SyncMode.full_refresh, "stream_slice": s}, [s]) for s in slices],
446
- name="s1",
447
- )
448
- s2 = MockStream(
449
- [({"stream_state": {}, "sync_mode": SyncMode.full_refresh, "stream_slice": s}, [s]) for s in slices],
450
- name="s2",
451
- )
452
-
453
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
454
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
455
-
456
- src = MockSource(streams=[s1, s2])
457
- catalog = ConfiguredAirbyteCatalog(
458
- streams=[
459
- _configured_stream(s1, SyncMode.full_refresh),
460
- _configured_stream(s2, SyncMode.full_refresh),
461
- ]
462
- )
463
-
464
- expected = _fix_emitted_at(
465
- [
466
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
467
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
468
- *_as_records("s1", slices),
469
- _as_state("s1", {"__ab_full_refresh_state_message": True}),
470
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
471
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
472
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
473
- *_as_records("s2", slices),
474
- _as_state("s2", {"__ab_full_refresh_state_message": True}),
475
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
476
- ]
477
- )
478
-
479
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog)))
480
-
481
- assert expected == messages
482
-
483
-
484
- def test_full_refresh_does_not_use_incoming_state(mocker):
485
- """Tests that running a full refresh sync does not use an incoming state message from the platform"""
486
- slices = [{"1": "1"}, {"2": "2"}]
487
- # When attempting to sync a slice, just output that slice as a record
488
- s1 = MockStream(
489
- [({"stream_state": {}, "sync_mode": SyncMode.full_refresh, "stream_slice": s}, [s]) for s in slices],
490
- name="s1",
491
- )
492
- s2 = MockStream(
493
- [({"stream_state": {}, "sync_mode": SyncMode.full_refresh, "stream_slice": s}, [s]) for s in slices],
494
- name="s2",
495
- )
496
-
497
- def stream_slices_side_effect(stream_state: Mapping[str, Any], **kwargs) -> List[Mapping[str, Any]]:
498
- if stream_state:
499
- return slices[1:]
500
- else:
501
- return slices
502
-
503
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
504
- mocker.patch.object(MockStream, "stream_slices", side_effect=stream_slices_side_effect)
505
-
506
- state = [
507
- AirbyteStateMessage(
508
- type=AirbyteStateType.STREAM,
509
- stream=AirbyteStreamState(
510
- stream_descriptor=StreamDescriptor(name="s1"),
511
- stream_state=AirbyteStateBlob.parse_obj({"created_at": "2024-01-31"}),
512
- ),
513
- ),
514
- AirbyteStateMessage(
515
- type=AirbyteStateType.STREAM,
516
- stream=AirbyteStreamState(
517
- stream_descriptor=StreamDescriptor(name="s2"),
518
- stream_state=AirbyteStateBlob.parse_obj({"__ab_full_refresh_state_message": True}),
519
- ),
520
- ),
521
- ]
522
-
523
- src = MockSource(streams=[s1, s2])
524
- catalog = ConfiguredAirbyteCatalog(
525
- streams=[
526
- _configured_stream(s1, SyncMode.full_refresh),
527
- _configured_stream(s2, SyncMode.full_refresh),
528
- ]
529
- )
530
-
531
- expected = _fix_emitted_at(
532
- [
533
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
534
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
535
- *_as_records("s1", slices),
536
- _as_state("s1", {"__ab_full_refresh_state_message": True}),
537
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
538
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
539
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
540
- *_as_records("s2", slices),
541
- _as_state("s2", {"__ab_full_refresh_state_message": True}),
542
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
543
- ]
544
- )
545
-
546
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state)))
547
-
548
- assert messages == expected
549
-
550
-
551
- @pytest.mark.parametrize(
552
- "slices",
553
- [[{"1": "1"}, {"2": "2"}], [{"date": datetime.date(year=2023, month=1, day=1)}, {"date": datetime.date(year=2023, month=1, day=1)}]],
554
- )
555
- def test_read_full_refresh_with_slices_sends_slice_messages(mocker, slices):
556
- """Given the logger is debug and a full refresh, AirbyteMessages are sent for slices"""
557
- debug_logger = logging.getLogger("airbyte.debug")
558
- debug_logger.setLevel(logging.DEBUG)
559
- stream = MockStream(
560
- [({"stream_state": {}, "sync_mode": SyncMode.full_refresh, "stream_slice": s}, [s]) for s in slices],
561
- name="s1",
562
- )
563
-
564
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
565
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
566
-
567
- src = MockSource(streams=[stream])
568
- catalog = ConfiguredAirbyteCatalog(
569
- streams=[
570
- _configured_stream(stream, SyncMode.full_refresh),
571
- ]
572
- )
573
-
574
- messages = src.read(debug_logger, {}, catalog)
575
-
576
- assert 2 == len(list(filter(lambda message: message.log and message.log.message.startswith("slice:"), messages)))
577
-
578
-
579
- def test_read_incremental_with_slices_sends_slice_messages(mocker):
580
- """Given the logger is debug and a incremental, AirbyteMessages are sent for slices"""
581
- debug_logger = logging.getLogger("airbyte.debug")
582
- debug_logger.setLevel(logging.DEBUG)
583
- slices = [{"1": "1"}, {"2": "2"}]
584
- stream = MockStream(
585
- [({"sync_mode": SyncMode.incremental, "stream_slice": s, "stream_state": {}}, [s]) for s in slices],
586
- name="s1",
587
- )
588
-
589
- MockStream.supports_incremental = mocker.PropertyMock(return_value=True)
590
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
591
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
592
-
593
- src = MockSource(streams=[stream])
594
- catalog = ConfiguredAirbyteCatalog(
595
- streams=[
596
- _configured_stream(stream, SyncMode.incremental),
597
- ]
598
- )
599
-
600
- messages = src.read(debug_logger, {}, catalog)
601
-
602
- assert 2 == len(list(filter(lambda message: message.log and message.log.message.startswith("slice:"), messages)))
603
-
604
-
605
- class TestIncrementalRead:
606
- @pytest.mark.parametrize(
607
- "use_legacy",
608
- [
609
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
610
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
611
- ],
612
- )
613
- def test_with_state_attribute(self, mocker, use_legacy):
614
- """Test correct state passing for the streams that have a state attribute"""
615
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
616
- old_state = {"cursor": "old_value"}
617
- if use_legacy:
618
- input_state = {"s1": old_state}
619
- else:
620
- input_state = [
621
- AirbyteStateMessage(
622
- type=AirbyteStateType.STREAM,
623
- stream=AirbyteStreamState(
624
- stream_descriptor=StreamDescriptor(name="s1"), stream_state=AirbyteStateBlob.parse_obj(old_state)
625
- ),
626
- ),
627
- ]
628
- new_state_from_connector = {"cursor": "new_value"}
629
-
630
- stream_1 = MockStreamWithState(
631
- [
632
- (
633
- {"sync_mode": SyncMode.incremental, "stream_state": old_state},
634
- stream_output,
635
- )
636
- ],
637
- name="s1",
638
- )
639
- stream_2 = MockStreamWithState(
640
- [({"sync_mode": SyncMode.incremental, "stream_state": {}}, stream_output)],
641
- name="s2",
642
- )
643
- mocker.patch.object(MockStreamWithState, "get_updated_state", return_value={})
644
- state_property = mocker.patch.object(
645
- MockStreamWithState,
646
- "state",
647
- new_callable=mocker.PropertyMock,
648
- return_value=new_state_from_connector,
649
- )
650
- mocker.patch.object(MockStreamWithState, "get_json_schema", return_value={})
651
- src = MockSource(streams=[stream_1, stream_2])
652
- catalog = ConfiguredAirbyteCatalog(
653
- streams=[
654
- _configured_stream(stream_1, SyncMode.incremental),
655
- _configured_stream(stream_2, SyncMode.incremental),
656
- ]
657
- )
658
-
659
- expected = _fix_emitted_at(
660
- [
661
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
662
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
663
- _as_record("s1", stream_output[0]),
664
- _as_record("s1", stream_output[1]),
665
- _as_state("s1", new_state_from_connector),
666
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
667
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
668
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
669
- _as_record("s2", stream_output[0]),
670
- _as_record("s2", stream_output[1]),
671
- _as_state("s2", new_state_from_connector),
672
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
673
- ]
674
- )
675
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
676
-
677
- assert messages == expected
678
- assert state_property.mock_calls == [
679
- call(old_state), # set state for s1
680
- call(), # get state in the end of slice for s1
681
- call(), # get state in the end of slice for s2
682
- ]
683
-
684
- @pytest.mark.parametrize(
685
- "use_legacy",
686
- [
687
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
688
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
689
- ],
690
- )
691
- def test_with_checkpoint_interval(self, mocker, use_legacy):
692
- """Tests that an incremental read which doesn't specify a checkpoint interval outputs a STATE message
693
- after reading N records within a stream.
694
- """
695
- if use_legacy:
696
- input_state = defaultdict(dict)
697
- else:
698
- input_state = []
699
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
700
-
701
- stream_1 = MockStream(
702
- [({"sync_mode": SyncMode.incremental, "stream_state": {}}, stream_output)],
703
- name="s1",
704
- )
705
- stream_2 = MockStream(
706
- [({"sync_mode": SyncMode.incremental, "stream_state": {}}, stream_output)],
707
- name="s2",
708
- )
709
- state = {"cursor": "value"}
710
- mocker.patch.object(MockStream, "get_updated_state", return_value=state)
711
- mocker.patch.object(MockStream, "supports_incremental", return_value=True)
712
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
713
- # Tell the source to output one state message per record
714
- mocker.patch.object(
715
- MockStream,
716
- "state_checkpoint_interval",
717
- new_callable=mocker.PropertyMock,
718
- return_value=1,
719
- )
720
-
721
- src = MockSource(streams=[stream_1, stream_2])
722
- catalog = ConfiguredAirbyteCatalog(
723
- streams=[
724
- _configured_stream(stream_1, SyncMode.incremental),
725
- _configured_stream(stream_2, SyncMode.incremental),
726
- ]
727
- )
728
-
729
- expected = _fix_emitted_at(
730
- [
731
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
732
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
733
- _as_record("s1", stream_output[0]),
734
- _as_state("s1", state),
735
- _as_record("s1", stream_output[1]),
736
- _as_state("s1", state),
737
- _as_state("s1", state),
738
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
739
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
740
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
741
- _as_record("s2", stream_output[0]),
742
- _as_state("s2", state),
743
- _as_record("s2", stream_output[1]),
744
- _as_state("s2", state),
745
- _as_state("s2", state),
746
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
747
- ]
748
- )
749
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
750
-
751
- assert expected == messages
752
-
753
- @pytest.mark.parametrize(
754
- "use_legacy",
755
- [
756
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
757
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
758
- ],
759
- )
760
- def test_with_no_interval(self, mocker, use_legacy):
761
- """Tests that an incremental read which doesn't specify a checkpoint interval outputs
762
- a STATE message only after fully reading the stream and does not output any STATE messages during syncing the stream.
763
- """
764
- if use_legacy:
765
- input_state = defaultdict(dict)
766
- else:
767
- input_state = []
768
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
769
-
770
- stream_1 = MockStream(
771
- [({"sync_mode": SyncMode.incremental, "stream_state": {}}, stream_output)],
772
- name="s1",
773
- )
774
- stream_2 = MockStream(
775
- [({"sync_mode": SyncMode.incremental, "stream_state": {}}, stream_output)],
776
- name="s2",
777
- )
778
- state = {"cursor": "value"}
779
- mocker.patch.object(MockStream, "get_updated_state", return_value=state)
780
- mocker.patch.object(MockStream, "supports_incremental", return_value=True)
781
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
782
-
783
- src = MockSource(streams=[stream_1, stream_2])
784
- catalog = ConfiguredAirbyteCatalog(
785
- streams=[
786
- _configured_stream(stream_1, SyncMode.incremental),
787
- _configured_stream(stream_2, SyncMode.incremental),
788
- ]
789
- )
790
-
791
- expected = _fix_emitted_at(
792
- [
793
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
794
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
795
- *_as_records("s1", stream_output),
796
- _as_state("s1", state),
797
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
798
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
799
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
800
- *_as_records("s2", stream_output),
801
- _as_state("s2", state),
802
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
803
- ]
804
- )
805
-
806
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
807
-
808
- assert expected == messages
809
-
810
- @pytest.mark.parametrize(
811
- "use_legacy",
812
- [
813
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
814
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
815
- ],
816
- )
817
- def test_with_slices(self, mocker, use_legacy):
818
- """Tests that an incremental read which uses slices outputs each record in the slice followed by a STATE message, for each slice"""
819
- if use_legacy:
820
- input_state = defaultdict(dict)
821
- else:
822
- input_state = []
823
- slices = [{"1": "1"}, {"2": "2"}]
824
- stream_output = [{"k1": "v1"}, {"k2": "v2"}, {"k3": "v3"}]
825
-
826
- stream_1 = MockStream(
827
- [
828
- (
829
- {
830
- "sync_mode": SyncMode.incremental,
831
- "stream_slice": s,
832
- "stream_state": mocker.ANY,
833
- },
834
- stream_output,
835
- )
836
- for s in slices
837
- ],
838
- name="s1",
839
- )
840
- stream_2 = MockStream(
841
- [
842
- (
843
- {
844
- "sync_mode": SyncMode.incremental,
845
- "stream_slice": s,
846
- "stream_state": mocker.ANY,
847
- },
848
- stream_output,
849
- )
850
- for s in slices
851
- ],
852
- name="s2",
853
- )
854
- state = {"cursor": "value"}
855
- mocker.patch.object(MockStream, "get_updated_state", return_value=state)
856
- mocker.patch.object(MockStream, "supports_incremental", return_value=True)
857
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
858
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
859
-
860
- src = MockSource(streams=[stream_1, stream_2])
861
- catalog = ConfiguredAirbyteCatalog(
862
- streams=[
863
- _configured_stream(stream_1, SyncMode.incremental),
864
- _configured_stream(stream_2, SyncMode.incremental),
865
- ]
866
- )
867
-
868
- expected = _fix_emitted_at(
869
- [
870
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
871
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
872
- # stream 1 slice 1
873
- *_as_records("s1", stream_output),
874
- _as_state("s1", state),
875
- # stream 1 slice 2
876
- *_as_records("s1", stream_output),
877
- _as_state("s1", state),
878
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
879
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
880
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
881
- # stream 2 slice 1
882
- *_as_records("s2", stream_output),
883
- _as_state("s2", state),
884
- # stream 2 slice 2
885
- *_as_records("s2", stream_output),
886
- _as_state("s2", state),
887
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
888
- ]
889
- )
890
-
891
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
892
-
893
- assert expected == messages
894
-
895
- @pytest.mark.parametrize(
896
- "use_legacy",
897
- [
898
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
899
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
900
- ],
901
- )
902
- @pytest.mark.parametrize("slices", [pytest.param([], id="test_slices_as_list"), pytest.param(iter([]), id="test_slices_as_iterator")])
903
- def test_no_slices(self, mocker, use_legacy, slices):
904
- """
905
- Tests that an incremental read returns at least one state messages even if no records were read:
906
- 1. outputs a state message after reading the entire stream
907
- """
908
- if use_legacy:
909
- input_state = defaultdict(dict)
910
- else:
911
- input_state = []
912
-
913
- stream_output = [{"k1": "v1"}, {"k2": "v2"}, {"k3": "v3"}]
914
- state = {"cursor": "value"}
915
- stream_1 = MockStreamWithState(
916
- [
917
- (
918
- {
919
- "sync_mode": SyncMode.incremental,
920
- "stream_slice": s,
921
- "stream_state": mocker.ANY,
922
- },
923
- stream_output,
924
- )
925
- for s in slices
926
- ],
927
- name="s1",
928
- state=state,
929
- )
930
- stream_2 = MockStreamWithState(
931
- [
932
- (
933
- {
934
- "sync_mode": SyncMode.incremental,
935
- "stream_slice": s,
936
- "stream_state": mocker.ANY,
937
- },
938
- stream_output,
939
- )
940
- for s in slices
941
- ],
942
- name="s2",
943
- state=state,
944
- )
945
-
946
- mocker.patch.object(MockStreamWithState, "supports_incremental", return_value=True)
947
- mocker.patch.object(MockStreamWithState, "get_json_schema", return_value={})
948
- mocker.patch.object(MockStreamWithState, "stream_slices", return_value=slices)
949
- mocker.patch.object(
950
- MockStreamWithState,
951
- "state_checkpoint_interval",
952
- new_callable=mocker.PropertyMock,
953
- return_value=2,
954
- )
955
-
956
- src = MockSource(streams=[stream_1, stream_2])
957
- catalog = ConfiguredAirbyteCatalog(
958
- streams=[
959
- _configured_stream(stream_1, SyncMode.incremental),
960
- _configured_stream(stream_2, SyncMode.incremental),
961
- ]
962
- )
963
-
964
- expected = _fix_emitted_at(
965
- [
966
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
967
- _as_state("s1", state),
968
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
969
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
970
- _as_state("s2", state),
971
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
972
- ]
973
- )
974
-
975
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
976
-
977
- assert expected == messages
978
-
979
- @pytest.mark.parametrize(
980
- "use_legacy",
981
- [
982
- pytest.param(True, id="test_incoming_stream_state_as_legacy_format"),
983
- pytest.param(False, id="test_incoming_stream_state_as_per_stream_format"),
984
- ],
985
- )
986
- def test_with_slices_and_interval(self, mocker, use_legacy):
987
- """
988
- Tests that an incremental read which uses slices and a checkpoint interval:
989
- 1. outputs all records
990
- 2. outputs a state message every N records (N=checkpoint_interval)
991
- 3. outputs a state message after reading the entire slice
992
- """
993
- if use_legacy:
994
- input_state = defaultdict(dict)
995
- else:
996
- input_state = []
997
- slices = [{"1": "1"}, {"2": "2"}]
998
- stream_output = [{"k1": "v1"}, {"k2": "v2"}, {"k3": "v3"}]
999
- stream_1 = MockStream(
1000
- [
1001
- (
1002
- {
1003
- "sync_mode": SyncMode.incremental,
1004
- "stream_slice": s,
1005
- "stream_state": mocker.ANY,
1006
- },
1007
- stream_output,
1008
- )
1009
- for s in slices
1010
- ],
1011
- name="s1",
1012
- )
1013
- stream_2 = MockStream(
1014
- [
1015
- (
1016
- {
1017
- "sync_mode": SyncMode.incremental,
1018
- "stream_slice": s,
1019
- "stream_state": mocker.ANY,
1020
- },
1021
- stream_output,
1022
- )
1023
- for s in slices
1024
- ],
1025
- name="s2",
1026
- )
1027
- state = {"cursor": "value"}
1028
- mocker.patch.object(MockStream, "get_updated_state", return_value=state)
1029
- mocker.patch.object(MockStream, "supports_incremental", return_value=True)
1030
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1031
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
1032
- mocker.patch.object(
1033
- MockStream,
1034
- "state_checkpoint_interval",
1035
- new_callable=mocker.PropertyMock,
1036
- return_value=2,
1037
- )
1038
-
1039
- src = MockSource(streams=[stream_1, stream_2])
1040
- catalog = ConfiguredAirbyteCatalog(
1041
- streams=[
1042
- _configured_stream(stream_1, SyncMode.incremental),
1043
- _configured_stream(stream_2, SyncMode.incremental),
1044
- ]
1045
- )
1046
-
1047
- expected = _fix_emitted_at(
1048
- [
1049
- # stream 1 slice 1
1050
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1051
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1052
- _as_record("s1", stream_output[0]),
1053
- _as_record("s1", stream_output[1]),
1054
- _as_state("s1", state),
1055
- _as_record("s1", stream_output[2]),
1056
- _as_state("s1", state),
1057
- # stream 1 slice 2
1058
- _as_record("s1", stream_output[0]),
1059
- _as_state("s1", state),
1060
- _as_record("s1", stream_output[1]),
1061
- _as_record("s1", stream_output[2]),
1062
- _as_state("s1", state),
1063
- _as_state("s1", state),
1064
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1065
- # stream 2 slice 1
1066
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
1067
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
1068
- _as_record("s2", stream_output[0]),
1069
- _as_record("s2", stream_output[1]),
1070
- _as_state("s2", state),
1071
- _as_record("s2", stream_output[2]),
1072
- _as_state("s2", state),
1073
- # stream 2 slice 2
1074
- _as_record("s2", stream_output[0]),
1075
- _as_state("s2", state),
1076
- _as_record("s2", stream_output[1]),
1077
- _as_record("s2", stream_output[2]),
1078
- _as_state("s2", state),
1079
- _as_state("s2", state),
1080
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
1081
- ]
1082
- )
1083
-
1084
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
1085
-
1086
- assert messages == expected
1087
-
1088
- def test_emit_non_records(self, mocker):
1089
- """
1090
- Tests that an incremental read which uses slices and a checkpoint interval:
1091
- 1. outputs all records
1092
- 2. outputs a state message every N records (N=checkpoint_interval)
1093
- 3. outputs a state message after reading the entire slice
1094
- """
1095
-
1096
- input_state = []
1097
- slices = [{"1": "1"}, {"2": "2"}]
1098
- stream_output = [
1099
- {"k1": "v1"},
1100
- AirbyteLogMessage(level=Level.INFO, message="HELLO"),
1101
- {"k2": "v2"},
1102
- {"k3": "v3"},
1103
- ]
1104
- stream_1 = MockStreamEmittingAirbyteMessages(
1105
- [
1106
- (
1107
- {
1108
- "sync_mode": SyncMode.incremental,
1109
- "stream_slice": s,
1110
- "stream_state": mocker.ANY,
1111
- },
1112
- stream_output,
1113
- )
1114
- for s in slices
1115
- ],
1116
- name="s1",
1117
- state=copy.deepcopy(input_state),
1118
- )
1119
- stream_2 = MockStreamEmittingAirbyteMessages(
1120
- [
1121
- (
1122
- {
1123
- "sync_mode": SyncMode.incremental,
1124
- "stream_slice": s,
1125
- "stream_state": mocker.ANY,
1126
- },
1127
- stream_output,
1128
- )
1129
- for s in slices
1130
- ],
1131
- name="s2",
1132
- state=copy.deepcopy(input_state),
1133
- )
1134
- state = {"cursor": "value"}
1135
- mocker.patch.object(MockStream, "get_updated_state", return_value=state)
1136
- mocker.patch.object(MockStream, "supports_incremental", return_value=True)
1137
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1138
- mocker.patch.object(MockStream, "stream_slices", return_value=slices)
1139
- mocker.patch.object(
1140
- MockStream,
1141
- "state_checkpoint_interval",
1142
- new_callable=mocker.PropertyMock,
1143
- return_value=2,
1144
- )
1145
-
1146
- src = MockSource(streams=[stream_1, stream_2])
1147
- catalog = ConfiguredAirbyteCatalog(
1148
- streams=[
1149
- _configured_stream(stream_1, SyncMode.incremental),
1150
- _configured_stream(stream_2, SyncMode.incremental),
1151
- ]
1152
- )
1153
-
1154
- expected = _fix_emitted_at(
1155
- [
1156
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1157
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1158
- # stream 1 slice 1
1159
- stream_data_to_airbyte_message("s1", stream_output[0]),
1160
- stream_data_to_airbyte_message("s1", stream_output[1]),
1161
- stream_data_to_airbyte_message("s1", stream_output[2]),
1162
- _as_state("s1", state),
1163
- stream_data_to_airbyte_message("s1", stream_output[3]),
1164
- _as_state("s1", state),
1165
- # stream 1 slice 2
1166
- stream_data_to_airbyte_message("s1", stream_output[0]),
1167
- _as_state("s1", state),
1168
- stream_data_to_airbyte_message("s1", stream_output[1]),
1169
- stream_data_to_airbyte_message("s1", stream_output[2]),
1170
- stream_data_to_airbyte_message("s1", stream_output[3]),
1171
- _as_state("s1", state),
1172
- _as_state("s1", state),
1173
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1174
- # stream 2 slice 1
1175
- _as_stream_status("s2", AirbyteStreamStatus.STARTED),
1176
- _as_stream_status("s2", AirbyteStreamStatus.RUNNING),
1177
- stream_data_to_airbyte_message("s2", stream_output[0]),
1178
- stream_data_to_airbyte_message("s2", stream_output[1]),
1179
- stream_data_to_airbyte_message("s2", stream_output[2]),
1180
- _as_state("s2", state),
1181
- stream_data_to_airbyte_message("s2", stream_output[3]),
1182
- _as_state("s2", state),
1183
- # stream 2 slice 2
1184
- stream_data_to_airbyte_message("s2", stream_output[0]),
1185
- _as_state("s2", state),
1186
- stream_data_to_airbyte_message("s2", stream_output[1]),
1187
- stream_data_to_airbyte_message("s2", stream_output[2]),
1188
- stream_data_to_airbyte_message("s2", stream_output[3]),
1189
- _as_state("s2", state),
1190
- _as_state("s2", state),
1191
- _as_stream_status("s2", AirbyteStreamStatus.COMPLETE),
1192
- ]
1193
- )
1194
-
1195
- messages = _fix_emitted_at(list(src.read(logger, {}, catalog, state=input_state)))
1196
-
1197
- assert messages == expected
1198
-
1199
-
1200
- def test_checkpoint_state_from_stream_instance():
1201
- teams_stream = MockStreamOverridesStateMethod()
1202
- managers_stream = StreamNoStateMethod()
1203
- state_manager = ConnectorStateManager(
1204
- {
1205
- "teams": AirbyteStream(
1206
- name="teams", namespace="", json_schema={}, supported_sync_modes=[SyncMode.full_refresh, SyncMode.incremental]
1207
- ),
1208
- "managers": AirbyteStream(
1209
- name="managers", namespace="", json_schema={}, supported_sync_modes=[SyncMode.full_refresh, SyncMode.incremental]
1210
- ),
1211
- },
1212
- [],
1213
- )
1214
-
1215
- # The stream_state passed to checkpoint_state() should be ignored since stream implements state function
1216
- teams_stream.state = {"updated_at": "2022-09-11"}
1217
- actual_message = teams_stream._checkpoint_state({"ignored": "state"}, state_manager)
1218
- assert actual_message == _as_state("teams", {"updated_at": "2022-09-11"})
1219
-
1220
- # The stream_state passed to checkpoint_state() should be used since the stream does not implement state function
1221
- actual_message = managers_stream._checkpoint_state({"updated": "expected_here"}, state_manager)
1222
- assert actual_message == _as_state("managers", {"updated": "expected_here"})
1223
-
1224
-
1225
- @pytest.mark.parametrize(
1226
- "exception_to_raise,expected_error_message,expected_internal_message",
1227
- [
1228
- pytest.param(
1229
- AirbyteTracedException(message="I was born only to crash like Icarus"),
1230
- "I was born only to crash like Icarus",
1231
- None,
1232
- id="test_raises_traced_exception",
1233
- ),
1234
- pytest.param(
1235
- Exception("Generic connector error message"),
1236
- "Something went wrong in the connector. See the logs for more details.",
1237
- "Generic connector error message",
1238
- id="test_raises_generic_exception",
1239
- ),
1240
- ],
1241
- )
1242
- def test_continue_sync_with_failed_streams(mocker, exception_to_raise, expected_error_message, expected_internal_message):
1243
- """
1244
- Tests that running a sync for a connector with multiple streams will continue syncing when one stream fails
1245
- with an error. This source does not override the default behavior defined in the AbstractSource class.
1246
- """
1247
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
1248
- s1 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s1")
1249
- s2 = StreamRaisesException(exception_to_raise=exception_to_raise)
1250
- s3 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s3")
1251
-
1252
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1253
- mocker.patch.object(StreamRaisesException, "get_json_schema", return_value={})
1254
-
1255
- src = MockSource(streams=[s1, s2, s3])
1256
- catalog = ConfiguredAirbyteCatalog(
1257
- streams=[
1258
- _configured_stream(s1, SyncMode.full_refresh),
1259
- _configured_stream(s2, SyncMode.full_refresh),
1260
- _configured_stream(s3, SyncMode.full_refresh),
1261
- ]
1262
- )
1263
-
1264
- expected = _fix_emitted_at(
1265
- [
1266
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1267
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1268
- *_as_records("s1", stream_output),
1269
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1270
- _as_stream_status("lamentations", AirbyteStreamStatus.STARTED),
1271
- _as_stream_status("lamentations", AirbyteStreamStatus.INCOMPLETE),
1272
- _as_error_trace("lamentations", expected_error_message, expected_internal_message, FailureType.system_error, None),
1273
- _as_stream_status("s3", AirbyteStreamStatus.STARTED),
1274
- _as_stream_status("s3", AirbyteStreamStatus.RUNNING),
1275
- *_as_records("s3", stream_output),
1276
- _as_stream_status("s3", AirbyteStreamStatus.COMPLETE),
1277
- ]
1278
- )
1279
-
1280
- with pytest.raises(AirbyteTracedException) as exc:
1281
- messages = [_remove_stack_trace(message) for message in src.read(logger, {}, catalog)]
1282
- messages = _fix_emitted_at(messages)
1283
-
1284
- assert expected == messages
1285
-
1286
- assert "lamentations" in exc.value.message
1287
- assert exc.value.failure_type == FailureType.config_error
1288
-
1289
-
1290
- def test_continue_sync_source_override_false(mocker):
1291
- """
1292
- Tests that running a sync for a connector explicitly overriding the default AbstractSource.stop_sync_on_stream_failure
1293
- property to be False which will continue syncing stream even if one encountered an exception.
1294
- """
1295
- update_secrets(["API_KEY_VALUE"])
1296
-
1297
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
1298
- s1 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s1")
1299
- s2 = StreamRaisesException(exception_to_raise=AirbyteTracedException(message="I was born only to crash like Icarus"))
1300
- s3 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s3")
1301
-
1302
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1303
- mocker.patch.object(StreamRaisesException, "get_json_schema", return_value={})
1304
-
1305
- src = MockSourceWithStopSyncFalseOverride(streams=[s1, s2, s3])
1306
- catalog = ConfiguredAirbyteCatalog(
1307
- streams=[
1308
- _configured_stream(s1, SyncMode.full_refresh),
1309
- _configured_stream(s2, SyncMode.full_refresh),
1310
- _configured_stream(s3, SyncMode.full_refresh),
1311
- ]
1312
- )
1313
-
1314
- expected = _fix_emitted_at(
1315
- [
1316
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1317
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1318
- *_as_records("s1", stream_output),
1319
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1320
- _as_stream_status("lamentations", AirbyteStreamStatus.STARTED),
1321
- _as_stream_status("lamentations", AirbyteStreamStatus.INCOMPLETE),
1322
- _as_error_trace("lamentations", "I was born only to crash like Icarus", None, FailureType.system_error, None),
1323
- _as_stream_status("s3", AirbyteStreamStatus.STARTED),
1324
- _as_stream_status("s3", AirbyteStreamStatus.RUNNING),
1325
- *_as_records("s3", stream_output),
1326
- _as_stream_status("s3", AirbyteStreamStatus.COMPLETE),
1327
- ]
1328
- )
1329
-
1330
- with pytest.raises(AirbyteTracedException) as exc:
1331
- messages = [_remove_stack_trace(message) for message in src.read(logger, {}, catalog)]
1332
- messages = _fix_emitted_at(messages)
1333
-
1334
- assert expected == messages
1335
-
1336
- assert "lamentations" in exc.value.message
1337
- assert exc.value.failure_type == FailureType.config_error
1338
-
1339
-
1340
- def test_sync_error_trace_messages_obfuscate_secrets(mocker):
1341
- """
1342
- Tests that exceptions emitted as trace messages by a source have secrets properly sanitized
1343
- """
1344
- update_secrets(["API_KEY_VALUE"])
1345
-
1346
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
1347
- s1 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s1")
1348
- s2 = StreamRaisesException(
1349
- exception_to_raise=AirbyteTracedException(message="My api_key value API_KEY_VALUE flew too close to the sun.")
1350
- )
1351
- s3 = MockStream([({"sync_mode": SyncMode.full_refresh}, stream_output)], name="s3")
1352
-
1353
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1354
- mocker.patch.object(StreamRaisesException, "get_json_schema", return_value={})
1355
-
1356
- src = MockSource(streams=[s1, s2, s3])
1357
- catalog = ConfiguredAirbyteCatalog(
1358
- streams=[
1359
- _configured_stream(s1, SyncMode.full_refresh),
1360
- _configured_stream(s2, SyncMode.full_refresh),
1361
- _configured_stream(s3, SyncMode.full_refresh),
1362
- ]
1363
- )
1364
-
1365
- expected = _fix_emitted_at(
1366
- [
1367
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1368
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1369
- *_as_records("s1", stream_output),
1370
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1371
- _as_stream_status("lamentations", AirbyteStreamStatus.STARTED),
1372
- _as_stream_status("lamentations", AirbyteStreamStatus.INCOMPLETE),
1373
- _as_error_trace("lamentations", "My api_key value **** flew too close to the sun.", None, FailureType.system_error, None),
1374
- _as_stream_status("s3", AirbyteStreamStatus.STARTED),
1375
- _as_stream_status("s3", AirbyteStreamStatus.RUNNING),
1376
- *_as_records("s3", stream_output),
1377
- _as_stream_status("s3", AirbyteStreamStatus.COMPLETE),
1378
- ]
1379
- )
1380
-
1381
- with pytest.raises(AirbyteTracedException) as exc:
1382
- messages = [_remove_stack_trace(message) for message in src.read(logger, {}, catalog)]
1383
- messages = _fix_emitted_at(messages)
1384
-
1385
- assert expected == messages
1386
-
1387
- assert "lamentations" in exc.value.message
1388
- assert exc.value.failure_type == FailureType.config_error
1389
-
1390
-
1391
- def test_continue_sync_with_failed_streams_with_override_false(mocker):
1392
- """
1393
- Tests that running a sync for a connector with multiple streams and stop_sync_on_stream_failure enabled stops
1394
- the sync when one stream fails with an error.
1395
- """
1396
- stream_output = [{"k1": "v1"}, {"k2": "v2"}]
1397
- s1 = MockStream([({"stream_state": {}, "sync_mode": SyncMode.full_refresh}, stream_output)], name="s1")
1398
- s2 = StreamRaisesException(AirbyteTracedException(message="I was born only to crash like Icarus"))
1399
- s3 = MockStream([({"stream_state": {}, "sync_mode": SyncMode.full_refresh}, stream_output)], name="s3")
1400
-
1401
- mocker.patch.object(MockStream, "get_json_schema", return_value={})
1402
- mocker.patch.object(StreamRaisesException, "get_json_schema", return_value={})
1403
-
1404
- src = MockSource(streams=[s1, s2, s3])
1405
- mocker.patch.object(MockSource, "stop_sync_on_stream_failure", return_value=True)
1406
- catalog = ConfiguredAirbyteCatalog(
1407
- streams=[
1408
- _configured_stream(s1, SyncMode.full_refresh),
1409
- _configured_stream(s2, SyncMode.full_refresh),
1410
- _configured_stream(s3, SyncMode.full_refresh),
1411
- ]
1412
- )
1413
-
1414
- expected = _fix_emitted_at(
1415
- [
1416
- _as_stream_status("s1", AirbyteStreamStatus.STARTED),
1417
- _as_stream_status("s1", AirbyteStreamStatus.RUNNING),
1418
- *_as_records("s1", stream_output),
1419
- _as_stream_status("s1", AirbyteStreamStatus.COMPLETE),
1420
- _as_stream_status("lamentations", AirbyteStreamStatus.STARTED),
1421
- _as_stream_status("lamentations", AirbyteStreamStatus.INCOMPLETE),
1422
- _as_error_trace("lamentations", "I was born only to crash like Icarus", None, FailureType.system_error, None),
1423
- ]
1424
- )
1425
-
1426
- with pytest.raises(AirbyteTracedException) as exc:
1427
- messages = [_remove_stack_trace(message) for message in src.read(logger, {}, catalog)]
1428
- messages = _fix_emitted_at(messages)
1429
-
1430
- assert expected == messages
1431
-
1432
- assert "lamentations" in exc.value.message
1433
- assert exc.value.failure_type == FailureType.config_error
1434
-
1435
-
1436
- def _remove_stack_trace(message: AirbyteMessage) -> AirbyteMessage:
1437
- """
1438
- Helper method that removes the stack trace from Airbyte trace messages to make asserting against expected records easier
1439
- """
1440
- if message.trace and message.trace.error and message.trace.error.stack_trace:
1441
- message.trace.error.stack_trace = None
1442
- return message