diff options
| author | Cody Logan <cody@lokken.dev> | 2023-11-06 11:52:50 -0800 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-11-06 11:52:50 -0800 |
| commit | 56dbc899c6bec74cba25483768e855ad7953a432 (patch) | |
| tree | d6a55aae3994f22165b301785281e52f7b12763b /tests/test_dl.py | |
| parent | 934cf599fdbfd5dec9c7ff5797137e1e695fe6da (diff) | |
| download | wikiget-56dbc899c6bec74cba25483768e855ad7953a432.tar.gz wikiget-56dbc899c6bec74cba25483768e855ad7953a432.zip | |
Test that prep_download returns the right File object
Diffstat (limited to 'tests/test_dl.py')
| -rw-r--r-- | tests/test_dl.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/tests/test_dl.py b/tests/test_dl.py index 297c59d..6d0b484 100644 --- a/tests/test_dl.py +++ b/tests/test_dl.py @@ -16,8 +16,11 @@ # along with Wikiget. If not, see <https://www.gnu.org/licenses/>. from pathlib import Path +from unittest.mock import MagicMock, patch import pytest +from mwclient import Site +from mwclient.image import Image from wikiget.dl import prep_download, process_download from wikiget.file import File @@ -25,13 +28,24 @@ from wikiget.wikiget import parse_args class TestPrepDownload: - # TODO: don't hit the actual API when doing tests - @pytest.mark.skip(reason="skip tests that query a live API") - def test_prep_download(self) -> None: - """The prep_download function should create a file object.""" + @patch("wikiget.dl.query_api") + @patch("wikiget.dl.connect_to_site") + def test_prep_download( + self, mock_connect_to_site: MagicMock, mock_query_api: MagicMock + ) -> None: + """The prep_download function should create the expected file object.""" + mock_site = MagicMock(Site) + mock_image = MagicMock(Image) + + mock_connect_to_site.return_value = mock_site + mock_query_api.return_value = mock_image + + expected_file = File(name="Example.jpg") + expected_file.image = mock_image + args = parse_args(["File:Example.jpg"]) file = prep_download(args.FILE, args) - assert file is not None + assert file == expected_file def test_prep_download_with_existing_file(self, tmp_path: Path) -> None: """ |
