@@ -673,7 +673,11 @@ async def test_agents_delete_not_existing(
673
673
backup_id = "ef34ab12"
674
674
675
675
setup_dsm_with_filestation .file .delete_file = AsyncMock (
676
- side_effect = SynologyDSMAPIErrorException ("api" , "404" , "not found" )
676
+ side_effect = SynologyDSMAPIErrorException (
677
+ "api" ,
678
+ "900" ,
679
+ [{"code" : 408 , "path" : f"/ha_backup/my_backup_path/{ backup_id } .tar" }],
680
+ )
677
681
)
678
682
679
683
await client .send_json_auto_id (
@@ -685,26 +689,40 @@ async def test_agents_delete_not_existing(
685
689
response = await client .receive_json ()
686
690
687
691
assert response ["success" ]
688
- assert response ["result" ] == {
689
- "agent_errors" : {
690
- "synology_dsm.mocked_syno_dsm_entry" : "Failed to delete the backup"
691
- }
692
- }
692
+ assert response ["result" ] == {"agent_errors" : {}}
693
693
694
694
695
+ @pytest .mark .parametrize (
696
+ ("error" , "expected_log" ),
697
+ [
698
+ (
699
+ SynologyDSMAPIErrorException ("api" , "100" , "Unknown error" ),
700
+ "{'api': 'api', 'code': '100', 'reason': 'Unknown', 'details': 'Unknown error'}" ,
701
+ ),
702
+ (
703
+ SynologyDSMAPIErrorException ("api" , "900" , [{"code" : 407 }]),
704
+ "{'api': 'api', 'code': '900', 'reason': 'Unknown', 'details': [{'code': 407}]" ,
705
+ ),
706
+ (
707
+ SynologyDSMAPIErrorException ("api" , "900" , [{"code" : 417 }]),
708
+ "{'api': 'api', 'code': '900', 'reason': 'Unknown', 'details': [{'code': 417}]" ,
709
+ ),
710
+ ],
711
+ )
695
712
async def test_agents_delete_error (
696
713
hass : HomeAssistant ,
697
714
hass_ws_client : WebSocketGenerator ,
715
+ caplog : pytest .LogCaptureFixture ,
698
716
setup_dsm_with_filestation : MagicMock ,
717
+ error : SynologyDSMAPIErrorException ,
718
+ expected_log : str ,
699
719
) -> None :
700
720
"""Test error while delete backup."""
701
721
client = await hass_ws_client (hass )
702
722
703
723
# error while delete
704
724
backup_id = "abcd12ef"
705
- setup_dsm_with_filestation .file .delete_file .side_effect = (
706
- SynologyDSMAPIErrorException ("api" , "404" , "not found" )
707
- )
725
+ setup_dsm_with_filestation .file .delete_file .side_effect = error
708
726
await client .send_json_auto_id (
709
727
{
710
728
"type" : "backup/delete" ,
@@ -716,9 +734,10 @@ async def test_agents_delete_error(
716
734
assert response ["success" ]
717
735
assert response ["result" ] == {
718
736
"agent_errors" : {
719
- "synology_dsm.mocked_syno_dsm_entry" : "Failed to delete the backup"
737
+ "synology_dsm.mocked_syno_dsm_entry" : "Failed to delete backup"
720
738
}
721
739
}
740
+ assert f"Failed to delete backup: { expected_log } " in caplog .text
722
741
mock : AsyncMock = setup_dsm_with_filestation .file .delete_file
723
742
assert len (mock .mock_calls ) == 1
724
743
assert mock .call_args_list [0 ].kwargs ["filename" ] == "abcd12ef.tar"
0 commit comments