jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1332488?usp=email )
Change subject: tests: Fix non-chunked filekey continuation
......................................................................
tests: Fix non-chunked filekey continuation
Accept known duplicate and history warnings which can accumulate for the
persistent upload fixture while still requiring the core warnings.
Resume the captured stash with its file key and offset so the test exercises
continuation instead of starting a separate upload.
Bug: T367314
Change-Id: If59d96a6c6b1f3ccb1e1b5e1f6c4ded089ffc62f
---
M tests/upload_tests.py
1 file changed, 22 insertions(+), 11 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/upload_tests.py b/tests/upload_tests.py
index 87e66ad..76e0553 100755
--- a/tests/upload_tests.py
+++ b/tests/upload_tests.py
@@ -300,20 +300,24 @@
def _init_upload(self, chunk_size) -> None:
"""Do an initial upload causing an abort because of warnings."""
+ required_warns = {'exists'} if chunk_size else {'duplicate', 'exists'}
+ # The persistent test file may have further duplicate/history warnings.
+ allowed_warns = required_warns | {
+ 'duplicate-archive', 'duplicateversions', 'nochange'}
+
def warn_callback(warnings) -> None:
"""A simple callback not automatically finishing the upload."""
- self.assertCountEqual([w.code for w in warnings], expected_warns)
- # by now we know there are only two but just make sure
- self.assertLength(warnings, expected_warns)
- self.assertIn(len(expected_warns), [1, 2])
- if len(expected_warns) == 2:
- self.assertEqual(warnings[0].file_key, warnings[1].file_key)
- self.assertEqual(warnings[0].offset, warnings[1].offset)
+ self.assertTrue(warnings)
+ warning_codes = {warning.code for warning in warnings}
+ self.assertLessEqual(required_warns, warning_codes)
+ self.assertLessEqual(warning_codes, allowed_warns)
+ self.assertTrue(all(warning.file_key == warnings[0].file_key
+ for warning in warnings))
+ self.assertTrue(all(warning.offset == warnings[0].offset
+ for warning in warnings))
self._file_key = warnings[0].file_key
self._offset = warnings[0].offset
- expected_warns = ['exists'] if chunk_size else ['duplicate', 'exists']
-
# First upload the warning with warnings enabled
page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png')
self.assertNotHasAttr(self, '_file_key')
@@ -348,14 +352,21 @@
def _test_continue_filekey(self, chunk_size) -> None:
"""Test uploading a chunk first and finish in a separate upload."""
self._init_upload(chunk_size)
- self._finish_upload(chunk_size, self.sounds_png)
+ page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png')
+ uploader = Uploader(
+ self.site, page, source_filename=self.sounds_png,
+ comment='pywikibot test', text=page.text,
+ chunk_size=chunk_size,
+ ignore_warnings=True, report_success=False)
+ self.assertTrue(uploader._upload(
+ ignore_warnings=True, report_success=False,
+ file_key=self._file_key, offset=self._offset))
# Check if it's still cached
with self.assertAPIError('siiinvalidsessiondata') as cm:
self.site.stash_info(self._file_key)
self.assertStartsWith(cm.exception.info, 'File not found')
- @unittest.expectedFailure # T367314
def test_continue_filekey_once(self) -> None:
"""Test continuing to upload a file without using chunked mode."""
self._test_continue_filekey(0)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1332488?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If59d96a6c6b1f3ccb1e1b5e1f6c4ded089ffc62f
Gerrit-Change-Number: 1332488
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]