Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mwclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WebU
shared
mwclient
Commits
bb1178e1
Commit
bb1178e1
authored
10 years ago
by
Dan Michael O. Heggø
Browse files
Options
Downloads
Patches
Plain Diff
Add the first Page tests, and add some docstrings
parent
a8709c0e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_client.py
+5
-0
5 additions, 0 deletions
tests/test_client.py
tests/test_page.py
+151
-0
151 additions, 0 deletions
tests/test_page.py
with
156 additions
and
0 deletions
tests/test_client.py
+
5
−
0
View file @
bb1178e1
...
...
@@ -26,6 +26,7 @@ class TestClient(unittest.TestCase):
pass
def
testVersion
(
self
):
# The version specified in setup.py should equal the one specified in client.py
version
=
pkg_resources
.
require
(
"
mwclient
"
)[
0
].
version
assert
version
==
mwclient
.
__ver__
...
...
@@ -46,6 +47,7 @@ class TestClient(unittest.TestCase):
@responses.activate
def
test_http_as_default
(
self
):
# 'http' should be the default scheme (for historical reasons)
self
.
httpShouldReturn
(
self
.
makeMetaResponse
(),
scheme
=
'
http
'
)
...
...
@@ -56,6 +58,7 @@ class TestClient(unittest.TestCase):
@responses.activate
def
test_headers
(
self
):
# Content-type should be 'application/x-www-form-urlencoded'
self
.
httpShouldReturn
(
self
.
makeMetaResponse
(),
scheme
=
'
http
'
)
...
...
@@ -67,6 +70,7 @@ class TestClient(unittest.TestCase):
@responses.activate
def
test_force_https
(
self
):
# Setting https should work
self
.
httpShouldReturn
(
self
.
makeMetaResponse
(),
scheme
=
'
https
'
)
...
...
@@ -76,6 +80,7 @@ class TestClient(unittest.TestCase):
@responses.activate
def
test_user_agent_is_sent
(
self
):
# User specified user agent should be sent sent to server
self
.
httpShouldReturn
(
self
.
makeMetaResponse
())
...
...
This diff is collapsed.
Click to expand it.
tests/test_page.py
0 → 100644
+
151
−
0
View file @
bb1178e1
# encoding=utf-8
if
__name__
==
"
__main__
"
:
print
print
"
Note: Running in stand-alone mode. Consult the README
"
print
"
(section
'
Contributing
'
) for advice on running tests.
"
print
import
unittest
import
pytest
import
logging
import
requests
import
responses
import
mock
from
mwclient.page
import
Page
try
:
import
json
except
ImportError
:
import
simplejson
as
json
class
TestPage
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_api_call_on_page_init
(
self
,
mock_site
):
# Check that site.api() is called once on Page init
title
=
'
Some page
'
mock_site
.
api
.
return_value
=
{
'
query
'
:
{
'
pages
'
:
{
'
1
'
:
{}}}
}
page
=
Page
(
mock_site
,
title
)
# test that Page called site.api with the right parameters
mock_site
.
api
.
assert_called_once_with
(
'
query
'
,
inprop
=
'
protection
'
,
titles
=
title
,
prop
=
'
info
'
)
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_nonexisting_page
(
self
,
mock_site
):
# Check that API response results in page.exists being set to False
title
=
'
Some nonexisting page
'
mock_site
.
api
.
return_value
=
{
'
query
'
:
{
'
pages
'
:
{
'
-1
'
:
{
'
missing
'
:
''
}}}
}
page
=
Page
(
mock_site
,
title
)
assert
page
.
exists
is
False
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_existing_page
(
self
,
mock_site
):
# Check that API response results in page.exists being set to True
title
=
'
Norge
'
mock_site
.
api
.
return_value
=
{
'
query
'
:
{
'
pages
'
:
{
'
728
'
:
{}}}
}
page
=
Page
(
mock_site
,
title
)
assert
page
.
exists
is
True
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_pageprops
(
self
,
mock_site
):
# Check that variouse page props are read correctly from API response
title
=
'
Some page
'
mock_site
.
api
.
return_value
=
{
'
query
'
:
{
'
pages
'
:
{
'
728
'
:
{
'
contentmodel
'
:
'
wikitext
'
,
'
counter
'
:
''
,
'
lastrevid
'
:
13355471
,
'
length
'
:
58487
,
'
ns
'
:
0
,
'
pageid
'
:
728
,
'
pagelanguage
'
:
'
nb
'
,
'
protection
'
:
[
{
'
expiry
'
:
'
infinity
'
,
'
level
'
:
'
autoconfirmed
'
,
'
type
'
:
'
edit
'
},
{
'
expiry
'
:
'
infinity
'
,
'
level
'
:
'
sysop
'
,
'
type
'
:
'
move
'
}
],
'
title
'
:
title
,
'
touched
'
:
'
2014-09-14T21:11:52Z
'
}
},
'
userinfo
'
:
{
'
anon
'
:
''
,
'
id
'
:
0
,
'
name
'
:
'
1.2.3.4
'
}
}
}
page
=
Page
(
mock_site
,
title
)
assert
page
.
exists
is
True
assert
page
.
redirect
is
False
assert
page
.
revision
==
13355471
assert
page
.
length
==
58487
assert
page
.
namespace
==
0
assert
page
.
name
==
title
assert
page
.
page_title
==
title
assert
page
.
protection
==
{
'
edit
'
:
(
'
autoconfirmed
'
,
'
infinity
'
),
'
move
'
:
(
'
sysop
'
,
'
infinity
'
)}
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_redirect
(
self
,
mock_site
):
# Check that page.redirect is set correctly
title
=
'
Some redirect page
'
mock_site
.
api
.
return_value
=
{
"
query
"
:
{
"
pages
"
:
{
"
796917
"
:
{
"
contentmodel
"
:
"
wikitext
"
,
"
counter
"
:
""
,
"
lastrevid
"
:
9342494
,
"
length
"
:
70
,
"
ns
"
:
0
,
"
pageid
"
:
796917
,
"
pagelanguage
"
:
"
nb
"
,
"
protection
"
:
[],
"
redirect
"
:
""
,
"
title
"
:
title
,
"
touched
"
:
"
2014-08-29T22:25:15Z
"
}
},
"
userinfo
"
:
{
"
anon
"
:
""
,
"
id
"
:
0
,
"
name
"
:
"
84.211.75.214
"
}
}
}
page
=
Page
(
mock_site
,
title
)
assert
page
.
exists
is
True
assert
page
.
redirect
is
True
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment