jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612838 )
Change subject: [tests] Additional tests for UploadRobot ......................................................................
[tests] Additional tests for UploadRobot
- code coverage of UploadRobot is 10% only Provide some additional dry tests for methods and attributes - move target_site.login() from Initializer to run method to enable dry tests
Bug: T60941 Change-Id: Ia9de151ea80b923c7038a0465a2d4797cd28be32 --- M pywikibot/specialbots/_upload.py M tests/uploadbot_tests.py 2 files changed, 26 insertions(+), 5 deletions(-)
Approvals: Huji: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py index b4bef7d..56ff407 100644 --- a/pywikibot/specialbots/_upload.py +++ b/pywikibot/specialbots/_upload.py @@ -115,7 +115,6 @@ 'commons') else: self.target_site = target_site or pywikibot.Site() - self.target_site.login()
def read_file_content(self, file_url=None): """Return name of temp file in which remote file is saved.""" @@ -454,6 +453,7 @@ return
# early check that user has proper rights to upload + self.target_site.login() if not self.target_site.has_right('upload'): pywikibot.error( "User '%s' does not have upload rights on site %s." diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py index bded553..29f29a3 100644 --- a/tests/uploadbot_tests.py +++ b/tests/uploadbot_tests.py @@ -5,18 +5,16 @@ These tests write to the wiki. """ # -# (C) Pywikibot team, 2014-2019 +# (C) Pywikibot team, 2014-2020 # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import os
from pywikibot.specialbots import UploadRobot
from tests import join_images_path -from tests.aspects import unittest, TestCase +from tests.aspects import unittest, TestCase, DefaultSiteTestCase
class TestUploadbot(TestCase): @@ -61,6 +59,29 @@ bot.run()
+class TestDryUploadbot(DefaultSiteTestCase): + + """Dry tests UploadRobot.""" + + net = False + + params = dict( # noqa: C408 + description='pywikibot upload.py script test', + keep_filename=True, + aborts=set(), + ignore_warning=True, + ) + + def test_png_file(self): + """Test UploadRobot attributes and methods.""" + bot = UploadRobot(url=['test.png'], target_site=self.site, + **self.params) + self.assertEqual(bot.description, self.params['description']) + self.assertTrue(bot._handle_warning('any warning')) # ignore_warning + self.assertTrue(bot.ignore_on_warn('any warning')) # ignore_warning + self.assertFalse(bot.abort_on_warn('any warning')) # aborts + + if __name__ == '__main__': # pragma: no cover try: unittest.main()
pywikibot-commits@lists.wikimedia.org