diff options
Diffstat (limited to 'tests/test_client.py')
| -rw-r--r-- | tests/test_client.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index 41ce948..cf6e29c 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,17 +26,30 @@ 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: + """ + The connect_to_site function should create a debug log message recording the + name of the site we're connecting to. + """ 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: + """ + The query_api function should create a debug log message containing the user + agent we're sending to the API. + """ caplog.set_level(logging.DEBUG) - site = connect_to_site("commons.wikimedia.org", self.args) + args = construct_parser().parse_args(["File:Example.jpg"]) + site = connect_to_site("commons.wikimedia.org", args) _ = query_api("Example.jpg", site) assert USER_AGENT in caplog.text |
