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

Change subject: tests: Make upload SHA1 mismatch test dry
......................................................................

tests: Make upload SHA1 mismatch test dry

The live test started a new upload instead of passing its captured stash
key back to the uploader, so it did not exercise stash validation.

Replaced it with an offline test using the existing upload test doubles.
The test supplies the stash key and offset, checks the SHA1 mismatch
error, and verifies that no upload request is created. Removed the
expected-failure marker along with the broken live test.

All TestUploaderStateTransitions tests pass.

Bug: T367321
Change-Id: I86b936e5fc45bce11aca7f2e4bfe1e9457d642b7
---
M tests/upload_tests.py
1 file changed, 27 insertions(+), 13 deletions(-)

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




diff --git a/tests/upload_tests.py b/tests/upload_tests.py
index 58bec4b..c45f82f 100755
--- a/tests/upload_tests.py
+++ b/tests/upload_tests.py
@@ -213,6 +213,33 @@
                 self.assertNotIn('filekey', submitted[0])
                 self.assertEqual(submitted[1]['filekey'], ['upload-key'])

+    def test_stash_sha1_mismatch(self) -> None:
+        """Test rejecting a stash whose SHA1 differs from the local file."""
+        source = join_images_path('1rightarrow.png')
+        stash_info = {
+            'size': 1024,
+            'sha1': '3503db342c8dfb0a38db0682b7370ddd271fa163',
+        }
+        site = _Site([], stash_info)
+        uploader = Uploader(
+            site, _FilePage(), source_filename=source,
+            comment='upload test', chunk_size=1024,
+            ignore_warnings=True)
+
+        with self.assertRaises(ValueError) as cm:
+            uploader._upload(
+                ignore_warnings=True, report_success=False,
+                file_key='upload-key', offset=1024)
+
+        self.assertEqual(
+            str(cm.exception),
+            'The SHA1 of 1024 bytes of the stashed "upload-key" is '
+            '3503db342c8dfb0a38db0682b7370ddd271fa163 while the local file is '
+            '3dd334f11aa1e780d636416dc0649b96b67588b6')
+        self.assertEqual(
+            site.stash_calls, [('upload-key', ['size', 'sha1'])])
+        self.assertIsEmpty(site.requests)
+
     def test_transfer_and_publication_polling(self) -> None:
         """Test transfer and publication polling remain distinct."""
         responses = [
@@ -390,19 +417,6 @@
         """Test a first chunk is stashed after an upload warning."""
         self._init_upload(1024)

-    @unittest.expectedFailure  # T367321
-    def test_sha1_mismatch(self) -> None:
-        """Test trying to continue with a different file."""
-        self._init_upload(1024)
-        with self.assertRaises(ValueError) as cm:
-            self._finish_upload(1024, self.arrow_png)
-        self.assertEqual(
-            str(cm.exception),
-            f'The SHA1 of 1024 bytes of the stashed "{self._file_key}" is '
-            '3503db342c8dfb0a38db0682b7370ddd271fa163 while the local file is '
-            '3dd334f11aa1e780d636416dc0649b96b67588b6')
-        self._verify_stash()
-
     @unittest.expectedFailure  # T367316
     def test_offset_mismatch(self) -> None:
         """Test trying to continue with a different offset."""

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

Reply via email to