jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335055?usp=email )

Change subject: tests: Fix repeatable non-chunked upload test
......................................................................

tests: Fix repeatable non-chunked upload test

The persistent test target can already contain the source fixture.
MediaWiki rejects an exact copy of the current revision even when upload
warnings are ignored. Select an alternate fixture when needed so every run
still performs a real upload.

Bug: T367319
Change-Id: Id10ddd691999eb9fc2d2780b3b90c55898bf3e6a
---
M tests/upload_tests.py
1 file changed, 19 insertions(+), 4 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/tests/upload_tests.py b/tests/upload_tests.py
index b1957ee..7dd9d56 100755
--- a/tests/upload_tests.py
+++ b/tests/upload_tests.py
@@ -336,13 +336,28 @@
     sounds_png = join_images_path('MP_sounds.png')
     arrow_png = join_images_path('1rightarrow.png')

-    @unittest.expectedFailure  # T367319
     def test_png(self) -> None:
         """Test uploading a png using Site.upload."""
         page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png')
-        self.site.upload(page, source_filename=self.sounds_png,
-                         summary='pywikibot test',
-                         ignore_warnings=True)
+        current_sha1 = None
+        with suppress(pywikibot.exceptions.PageRelatedError):
+            self.site.loadimageinfo(page)
+            current_sha1 = page.latest_file_info.sha1
+
+        # MediaWiki rejects publishing an exact copy of the current revision,
+        # even when upload warnings are ignored. Alternate between two test
+        # images so repeated test runs still exercise a successful upload.
+        sounds_sha1 = compute_file_hash(self.sounds_png)
+        source_filename = (self.arrow_png
+                           if current_sha1 == sounds_sha1
+                           else self.sounds_png)
+        source_sha1 = compute_file_hash(source_filename)
+
+        self.assertNotEqual(current_sha1, source_sha1)
+        self.assertTrue(
+            self.site.upload(page, source_filename=source_filename,
+                             summary='pywikibot test',
+                             ignore_warnings=True))

     def test_png_chunked(self) -> None:
         """Test uploading a png in chunks using Site.upload."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335055?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: Id10ddd691999eb9fc2d2780b3b90c55898bf3e6a
Gerrit-Change-Number: 1335055
Gerrit-PatchSet: 3
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]

Reply via email to