XZise has submitted this change and it was merged.
Change subject: Set several site tests to be logged in ......................................................................
Set several site tests to be logged in
Several site tests depend on site.user() returning a valid username. These have been moved into a specific class, with 'user = True' set.
Improve 'user = True' so that it logs in before each test if the site has become logged out during a different test.
Change-Id: I2e218471d99bc7ad23f42570157e9fd80432716e --- M tests/aspects.py M tests/site_tests.py M tox.ini 3 files changed, 26 insertions(+), 1 deletion(-)
Approvals: XZise: Looks good to me, approved
diff --git a/tests/aspects.py b/tests/aspects.py index 4e120ea..58ef0a4 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -215,6 +215,17 @@ '%s: Unable able to login to %s' % cls.__name__, cls.site)
+ def setUp(self): + """ + Set up the test case. + + Login to the site if it is not logged in. + """ + super(RequireUserMixin, self).setUp() + site = self.get_site() + if not site.logged_in(): + site.login() +
class MetaTestCaseClass(type):
@@ -446,6 +457,7 @@ return mainpage
def get_missing_article(self, site=None): + """Get a Page which refers to a missing page on the site.""" if not site: site = self.get_site() page = pywikibot.Page(pywikibot.page.Link( diff --git a/tests/site_tests.py b/tests/site_tests.py index fde7cee..fca2b38 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -649,6 +649,13 @@ self.assertIsInstance(using, pywikibot.Page) self.assertFalse(using.isRedirectPage())
+ +class SiteUserTestCase(DefaultSiteTestCase): + + """Test site method using a user.""" + + user = True + def testLogEvents(self): """Test the site.logevents() method""" mysite = self.get_site() @@ -1044,6 +1051,11 @@ self.assertTrue(user["name"] in ["Jimbo Wales", "Brion VIBBER", "Tim Starling"])
+ +class SiteRandomTestCase(DefaultSiteTestCase): + + """Test random methods of a site.""" + def testRandompages(self): """Test the site.randompages() method""" mysite = self.get_site() diff --git a/tox.ini b/tox.ini index a3ce817..3772be9 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,8 @@ ./pywikibot/bot.py \ ./pywikibot/data/__init__.py \ ./pywikibot/compat/userlib.py ./pywikibot/compat/catlib.py \ - ./pywikibot/compat/query.py + ./pywikibot/compat/query.py \ + ./tests/aspects.py deps = flake8-docstrings
[testenv:nose]
pywikibot-commits@lists.wikimedia.org