7171 _write_json_file ,
7272 _write_text_file ,
7373 _copy_readme_to_docs ,
74+ _create_new_changelog_for_library ,
7475 handle_build ,
7576 handle_configure ,
7677 handle_generate ,
@@ -293,6 +294,7 @@ def test_handle_configure_success(mock_configure_request_file, mocker):
293294 mock_prepare_config = mocker .patch (
294295 "cli._prepare_new_library_config" , return_value = {"id" : "prepared" }
295296 )
297+ mock_create_changelog = mocker .patch ("cli._create_new_changelog_for_library" )
296298
297299 handle_configure ()
298300
@@ -310,6 +312,28 @@ def test_handle_configure_no_new_library(mocker):
310312 with pytest .raises (ValueError , match = "Configuring a new library failed." ):
311313 handle_configure ()
312314
315+ def test_create_new_changelog_for_library (mocker ):
316+ """Tests that the changelog files are created correctly."""
317+ library_id = "google-cloud-language"
318+ output = "output"
319+ mock_makedirs = mocker .patch ("os.makedirs" )
320+ mock_write_text_file = mocker .patch ("cli._write_text_file" )
321+
322+ _create_new_changelog_for_library (library_id , output )
323+
324+ package_changelog_path = f"{ output } /packages/{ library_id } /CHANGELOG.md"
325+ docs_changelog_path = f"{ output } /packages/{ library_id } /docs/CHANGELOG.md"
326+
327+ # Check that makedirs was called for both parent directories
328+ mock_makedirs .assert_any_call (os .path .dirname (package_changelog_path ), exist_ok = True )
329+ mock_makedirs .assert_any_call (os .path .dirname (docs_changelog_path ), exist_ok = True )
330+ assert mock_makedirs .call_count == 2
331+
332+ # Check that the files were "written" with the correct content
333+ mock_write_text_file .assert_any_call (package_changelog_path , "# Changelog\n " )
334+ mock_write_text_file .assert_any_call (docs_changelog_path , "# Changelog\n " )
335+ assert mock_write_text_file .call_count == 2
336+
313337
314338def test_get_new_library_config_found (mock_configure_request_data ):
315339 """Tests that the new library configuration is returned when found."""
0 commit comments