aboutsummaryrefslogtreecommitdiff
path: root/tests/test_client.py
diff options
context:
space:
mode:
authorCody Logan <cody@lokken.dev>2023-11-01 11:55:44 -0700
committerGitHub <noreply@github.com>2023-11-01 11:55:44 -0700
commit15ffefbd0ca80f240b5468b4ab5cea5e9800ad83 (patch)
treec0b5bd30f23183cd81f67622c3534e0ee5417bee /tests/test_client.py
parente11e6ec4fc6180f2ffc4905b2561ecc385a29e5d (diff)
parent823171ba0bf42766446509f0143b95078285a1f0 (diff)
downloadwikiget-15ffefbd0ca80f240b5468b4ab5cea5e9800ad83.tar.gz
wikiget-15ffefbd0ca80f240b5468b4ab5cea5e9800ad83.zip
Merge pull request #11 from clpo13/add-tests
Add and improve some tests
Diffstat (limited to 'tests/test_client.py')
-rw-r--r--tests/test_client.py26
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