diff options
| author | Cody Logan <cody@lokken.dev> | 2023-11-01 11:32:53 -0700 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-11-01 11:32:53 -0700 |
| commit | 8b923f0cee8fed90d6eef313429eb593877e0f2d (patch) | |
| tree | 97c26a95bf0d7ced6a5254d6b68b86a9104d9312 /tests/test_client.py | |
| parent | 23df17b97e61fec8e4df4506a45cb257dfd33b93 (diff) | |
| download | wikiget-8b923f0cee8fed90d6eef313429eb593877e0f2d.tar.gz wikiget-8b923f0cee8fed90d6eef313429eb593877e0f2d.zip | |
Test connect_to_site using mocking
Diffstat (limited to 'tests/test_client.py')
| -rw-r--r-- | tests/test_client.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index 41ce948..832bf21 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -16,6 +16,7 @@ # along with Wikiget. If not, see <https://www.gnu.org/licenses/>. import logging +from unittest.mock import MagicMock, patch import pytest @@ -25,15 +26,19 @@ from wikiget.wikiget import construct_parser # TODO: don't hit the actual API when doing tests -@pytest.mark.skip(reason="skip tests that query a live API") class TestQueryApi: - args = construct_parser().parse_args(["File:Example.jpg"]) - - def test_connect_to_site(self, caplog: pytest.LogCaptureFixture) -> None: + @patch("mwclient.Site.__new__") + def test_connect_to_site( + self, mock_site: MagicMock, caplog: pytest.LogCaptureFixture + ) -> None: caplog.set_level(logging.DEBUG) - _ = connect_to_site("commons.wikimedia.org", self.args) + mock_site.return_value = MagicMock() + args = construct_parser().parse_args(["File:Example.jpg"]) + _ = connect_to_site("commons.wikimedia.org", args) + assert mock_site.called assert "Connecting to commons.wikimedia.org" in caplog.text + @pytest.mark.skip(reason="skip tests that query a live API") def test_query_api(self, caplog: pytest.LogCaptureFixture) -> None: caplog.set_level(logging.DEBUG) site = connect_to_site("commons.wikimedia.org", self.args) |
