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
c4de7069
Commit
c4de7069
authored
8 years ago
by
Dan Michael O. Heggø
Browse files
Options
Downloads
Patches
Plain Diff
Add test that would have caught #135
parent
503dd65e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_listing.py
+116
-0
116 additions, 0 deletions
tests/test_listing.py
with
116 additions
and
0 deletions
tests/test_listing.py
0 → 100644
+
116
−
0
View file @
c4de7069
# encoding=utf-8
from
__future__
import
print_function
import
unittest
import
pytest
import
logging
import
requests
import
responses
import
mock
import
mwclient
from
mwclient.listing
import
List
,
GeneratorList
try
:
import
json
except
ImportError
:
import
simplejson
as
json
if
__name__
==
"
__main__
"
:
print
()
print
(
"
Note: Running in stand-alone mode. Consult the README
"
)
print
(
"
(section
'
Contributing
'
) for advice on running tests.
"
)
print
()
class
TestList
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
def
setupDummyResponses
(
self
,
mock_site
,
result_member
,
ns
=
None
):
if
ns
is
None
:
ns
=
[
0
,
0
,
0
]
mock_site
.
api
.
side_effect
=
[
{
'
continue
'
:
{
'
apcontinue
'
:
'
Kre_Mbaye
'
,
'
continue
'
:
'
-||
'
},
'
query
'
:
{
result_member
:
[
{
"
pageid
"
:
19839654
,
"
ns
"
:
ns
[
0
],
"
title
"
:
"
Kre
'
fey
"
,
},
{
"
pageid
"
:
19839654
,
"
ns
"
:
ns
[
1
],
"
title
"
:
"
Kre-O
"
,
}
]
}
},
{
'
query
'
:
{
result_member
:
[
{
"
pageid
"
:
30955295
,
"
ns
"
:
ns
[
2
],
"
title
"
:
"
Kre-O Transformers
"
,
}
]
}
},
]
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_list_continuation
(
self
,
mock_site
):
# Test that the list fetches all three responses
# and yields dicts when return_values not set
lst
=
List
(
mock_site
,
'
allpages
'
,
'
ap
'
,
limit
=
2
)
self
.
setupDummyResponses
(
mock_site
,
'
allpages
'
)
vals
=
[
x
for
x
in
lst
]
assert
len
(
vals
)
==
3
assert
type
(
vals
[
0
])
==
dict
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_list_with_str_return_value
(
self
,
mock_site
):
# Test that the List yields strings when return_values is string
lst
=
List
(
mock_site
,
'
allpages
'
,
'
ap
'
,
limit
=
2
,
return_values
=
'
title
'
)
self
.
setupDummyResponses
(
mock_site
,
'
allpages
'
)
vals
=
[
x
for
x
in
lst
]
assert
len
(
vals
)
==
3
assert
type
(
vals
[
0
])
==
str
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_list_with_tuple_return_value
(
self
,
mock_site
):
# Test that the List yields tuples when return_values is tuple
lst
=
List
(
mock_site
,
'
allpages
'
,
'
ap
'
,
limit
=
2
,
return_values
=
(
'
title
'
,
'
ns
'
))
self
.
setupDummyResponses
(
mock_site
,
'
allpages
'
)
vals
=
[
x
for
x
in
lst
]
assert
len
(
vals
)
==
3
assert
type
(
vals
[
0
])
==
tuple
@mock.patch
(
'
mwclient.client.Site
'
)
def
test_generator_list
(
self
,
mock_site
):
# Test that the GeneratorList yields Page objects
lst
=
GeneratorList
(
mock_site
,
'
pages
'
,
'
p
'
)
self
.
setupDummyResponses
(
mock_site
,
'
pages
'
,
ns
=
[
0
,
6
,
14
])
vals
=
[
x
for
x
in
lst
]
assert
len
(
vals
)
==
3
assert
type
(
vals
[
0
])
==
mwclient
.
page
.
Page
assert
type
(
vals
[
1
])
==
mwclient
.
image
.
Image
assert
type
(
vals
[
2
])
==
mwclient
.
listing
.
Category
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