Skip to content

Commit

Permalink
[#183] Fix Page.exists for invalid page title
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Jan 14, 2018
1 parent 2ec57dd commit 27998bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mwclient/page.py
Expand Up @@ -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'])
Expand Down
20 changes: 20 additions & 0 deletions test/test_page.py
Expand Up @@ -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
Expand Down

0 comments on commit 27998bc

Please sign in to comment.