@@ -274,8 +274,8 @@ def test_get_article_attachments_with_filename_extractor(self) -> None:
274274 )
275275 assert file_reference .file_size_bytes == file_size
276276
277- def test_get_article_attachments_without_include_files (self ) -> None :
278- """Test that article attachments can be read without including files, it can be opt-out by configured catalog"""
277+ def test_get_article_attachments_with_include_files_false (self ) -> None :
278+ """Test that article attachments can be read with including files False , it can be opt-out by configured catalog"""
279279 include_files = False
280280 with (
281281 HttpMocker () as http_mocker ,
@@ -323,16 +323,52 @@ def test_get_article_attachments_without_include_files(self) -> None:
323323 # Ensure that NoopFileWriter is called to simulate file writing
324324 mock_noop_write .assert_called ()
325325 file_reference = output .records [0 ].record .file_reference
326- assert file_reference
327- assert (
328- file_reference .staging_file_url
329- == "/tmp/airbyte-file-transfer/article_attachments/12138758717583/some_image_name.png"
326+ assert file_reference .file_size_bytes == NoopFileWriter .NOOP_FILE_SIZE
327+
328+ def test_get_article_attachments_without_include_files (self ) -> None :
329+ """Test that article attachments can be read without including files, it can be opt-out by configured catalog"""
330+ with (
331+ HttpMocker () as http_mocker ,
332+ patch (
333+ "airbyte_cdk.sources.declarative.retrievers.file_uploader.noop_file_writer.NoopFileWriter.write"
334+ ) as mock_noop_write ,
335+ patch (
336+ "airbyte_cdk.sources.declarative.retrievers.file_uploader.local_file_system_file_writer.LocalFileSystemFileWriter.write"
337+ ) as mock_file_system_write ,
338+ ):
339+ http_mocker .get (
340+ HttpRequest (url = STREAM_URL ),
341+ HttpResponse (json .dumps (find_template ("file_api/articles" , __file__ )), 200 ),
342+ )
343+ http_mocker .get (
344+ HttpRequest (url = STREAM_ATTACHMENTS_URL ),
345+ HttpResponse (
346+ json .dumps (find_template ("file_api/article_attachments" , __file__ )), 200
347+ ),
348+ )
349+ http_mocker .get (
350+ HttpRequest (url = STREAM_ATTACHMENT_CONTENT_URL ),
351+ HttpResponse (
352+ find_binary_response ("file_api/article_attachment_content.png" , __file__ ), 200
353+ ),
330354 )
331355
332- assert file_reference .source_file_relative_path
333- assert not re .match (
334- r"^article_attachments/[0-9a-fA-F-]{36}$" , file_reference .source_file_relative_path
356+ mock_noop_write .return_value = NoopFileWriter .NOOP_FILE_SIZE
357+
358+ output = read (
359+ self ._config (),
360+ CatalogBuilder ()
361+ .with_stream (ConfiguredAirbyteStreamBuilder ().with_name ("article_attachments" ))
362+ .build (),
363+ yaml_file = "test_file_stream_with_filename_extractor.yaml" ,
335364 )
365+
366+ assert len (output .records ) == 1
367+ # Ensure that LocalFileSystemFileWriter is not called when include_files is False
368+ mock_file_system_write .assert_not_called ()
369+ # Ensure that NoopFileWriter is called to simulate file writing
370+ mock_noop_write .assert_called ()
371+ file_reference = output .records [0 ].record .file_reference
336372 assert file_reference .file_size_bytes == NoopFileWriter .NOOP_FILE_SIZE
337373
338374 def test_get_article_attachments_messages_for_connector_builder (self ) -> None :
0 commit comments