|
1 | 1 | import logging |
| 2 | +from unittest.mock import call |
2 | 3 |
|
3 | 4 | from existing_renamer import ExistingRenamer |
4 | 5 | from pycliarr.api import SonarrCli |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestExistingRenamer: |
8 | | - def test_no_series_returned(self, caplog, mocker) -> None: |
9 | | - mocker.patch.object(SonarrCli, "get_serie").return_value = [] |
| 9 | + def test_no_series_returned(self, get_serie_empty, caplog, mocker) -> None: |
10 | 10 | rename_files = mocker.patch.object(SonarrCli, "rename_files") |
11 | 11 |
|
12 | 12 | with caplog.at_level(logging.DEBUG): |
@@ -56,3 +56,51 @@ def test_when_multiple_episodes_need_renamed( |
56 | 56 | assert "Found episodes to be renamed" in caplog.text |
57 | 57 | assert "Renaming S01E01, S01E02" in caplog.text |
58 | 58 | rename_files.assert_called_once_with([1, 2], 1) |
| 59 | + |
| 60 | + def test_when_disk_scan_enabled_and_analyze_files_is_not( |
| 61 | + self, get_serie_empty, mock_loguru_warning, mocker |
| 62 | + ) -> None: |
| 63 | + mocker.patch.object(SonarrCli, "request_get").return_value = dict( |
| 64 | + enableMediaInfo=False |
| 65 | + ) |
| 66 | + |
| 67 | + ExistingRenamer("test", "test.tld", "test-api-key", True).scan() |
| 68 | + |
| 69 | + mock_loguru_warning.assert_called_once_with( |
| 70 | + "Analyse video files is not enabled, please enable setting, in order to use the reanalyze_files feature" |
| 71 | + ) |
| 72 | + |
| 73 | + def test_when_disk_scan_enabled( |
| 74 | + self, get_serie_empty, mock_loguru_info, mocker |
| 75 | + ) -> None: |
| 76 | + mocker.patch.object(SonarrCli, "request_get").return_value = dict( |
| 77 | + enableMediaInfo=True |
| 78 | + ) |
| 79 | + mocker.patch.object(SonarrCli, "_sendCommand").return_value = dict(id=1) |
| 80 | + mocker.patch.object(SonarrCli, "get_command").return_value = dict( |
| 81 | + status="completed", result="successful" |
| 82 | + ) |
| 83 | + mocker.patch("existing_renamer.sleep").return_value = None |
| 84 | + |
| 85 | + ExistingRenamer("test", "test.tld", "test-api-key", True).scan() |
| 86 | + |
| 87 | + assert call("Initiated disk scan of library") in mock_loguru_info.call_args_list |
| 88 | + assert ( |
| 89 | + call("disk scan finished successfully") in mock_loguru_info.call_args_list |
| 90 | + ) |
| 91 | + |
| 92 | + def test_when_disk_scan_enabled_and_fails( |
| 93 | + self, get_serie_empty, mock_loguru_info, mocker |
| 94 | + ) -> None: |
| 95 | + mocker.patch.object(SonarrCli, "request_get").return_value = dict( |
| 96 | + enableMediaInfo=True |
| 97 | + ) |
| 98 | + mocker.patch.object(SonarrCli, "_sendCommand").return_value = dict(id=1) |
| 99 | + mocker.patch.object(SonarrCli, "get_command").return_value = dict( |
| 100 | + status="completed", result="failed" |
| 101 | + ) |
| 102 | + mocker.patch("existing_renamer.sleep").return_value = None |
| 103 | + |
| 104 | + ExistingRenamer("test", "test.tld", "test-api-key", True).scan() |
| 105 | + |
| 106 | + assert call("disk scan failed") in mock_loguru_info.call_args_list |
0 commit comments