diff --git a/mwclient/page.py b/mwclient/page.py index 7903436d..75b60018 100644 --- a/mwclient/page.py +++ b/mwclient/page.py @@ -45,7 +45,7 @@ def __init__(self, site, name, info=None, extra_properties=None): self.touched = parse_timestamp(info.get('touched')) self.revision = info.get('lastrevid', 0) - self.exists = 'missing' not in info + self.exists = 'missing' not in info and 'invalid' not in info self.length = info.get('length') self.protection = { i['type']: (i['level'], i['expiry']) diff --git a/test/test_page.py b/test/test_page.py index 4469b212..fbf74f11 100644 --- a/test/test_page.py +++ b/test/test_page.py @@ -66,6 +66,26 @@ def test_existing_page(self, mock_site): assert page.exists is True + @mock.patch('mwclient.client.Site') + def test_invalid_title(self, mock_site): + # Check that API page.exists is False for invalid title + + title = '[Test]' + mock_site.get.return_value = { + "query": { + "pages": { + "-1": { + "title": "[Test]", + "invalidreason": "The requested page title contains invalid characters: \"[\".", + "invalid": "" + } + } + } + } + page = Page(mock_site, title) + + assert page.exists is False + @mock.patch('mwclient.client.Site') def test_pageprops(self, mock_site): # Check that variouse page props are read correctly from API response