@@ -445,6 +445,61 @@ def __init__(self, *args, **kwargs):
445
445
)
446
446
assert record_data ["file_size_bytes" ] == file_reference .file_size_bytes
447
447
448
+ def test_get_article_attachments_messages_for_connector_builder (self ) -> None :
449
+ with HttpMocker () as http_mocker :
450
+ http_mocker .get (
451
+ HttpRequest (url = STREAM_URL ),
452
+ HttpResponse (json .dumps (find_template ("file_api/articles" , __file__ )), 200 ),
453
+ )
454
+ http_mocker .get (
455
+ HttpRequest (url = STREAM_ATTACHMENTS_URL ),
456
+ HttpResponse (
457
+ json .dumps (find_template ("file_api/article_attachments" , __file__ )), 200
458
+ ),
459
+ )
460
+ http_mocker .get (
461
+ HttpRequest (url = STREAM_ATTACHMENT_CONTENT_URL ),
462
+ HttpResponse (
463
+ find_binary_response ("file_api/article_attachment_content.png" , __file__ ), 200
464
+ ),
465
+ )
466
+
467
+ # Define a mock factory that forces emit_connector_builder_messages=True
468
+ class MockModelToComponentFactory (OriginalModelToComponentFactory ):
469
+ def __init__ (self , * args , ** kwargs ):
470
+ kwargs ["emit_connector_builder_messages" ] = True
471
+ super ().__init__ (* args , ** kwargs )
472
+
473
+ # Patch the factory class where ConcurrentDeclarativeSource (parent of YamlDeclarativeSource) imports it
474
+ with patch (
475
+ "airbyte_cdk.sources.declarative.concurrent_declarative_source.ModelToComponentFactory" ,
476
+ new = MockModelToComponentFactory ,
477
+ ):
478
+ output = read (
479
+ self ._config (),
480
+ CatalogBuilder ()
481
+ .with_stream (ConfiguredAirbyteStreamBuilder ().with_name ("article_attachments" ))
482
+ .build (),
483
+ yaml_file = "test_file_stream_with_filename_extractor.yaml" ,
484
+ )
485
+
486
+ assert len (output .records ) == 1
487
+ file_reference = output .records [0 ].record .file_reference
488
+ assert file_reference
489
+ assert file_reference .staging_file_url
490
+ assert file_reference .source_file_relative_path
491
+ # because we didn't write the file, the size is NOOP_FILE_SIZE
492
+ assert file_reference .file_size_bytes == NoopFileWriter .NOOP_FILE_SIZE
493
+
494
+ # Assert file reference fields are copied to record data
495
+ record_data = output .records [0 ].record .data
496
+ assert record_data ["staging_file_url" ] == file_reference .staging_file_url
497
+ assert (
498
+ record_data ["source_file_relative_path" ]
499
+ == file_reference .source_file_relative_path
500
+ )
501
+ assert record_data ["file_size_bytes" ] == file_reference .file_size_bytes
502
+
448
503
def test_discover_article_attachments (self ) -> None :
449
504
output = discover (self ._config ())
450
505
0 commit comments