jenkins-bot has submitted this change and it was merged.

Change subject: HTTP binary file tests
......................................................................


HTTP binary file tests

Test getting binary files with each layer of http handling in pywikibot.

Change-Id: I1f413418461a1dc8e47b1f6b0cfbee405f46a61f
---
M tests/http_tests.py
1 file changed, 41 insertions(+), 0 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  XZise: Looks good to me, approved
  Xqt: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/http_tests.py b/tests/http_tests.py
index 3c49acd..66ec833 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -7,6 +7,7 @@
 #
 __version__ = '$Id$'
 
+import os
 import sys
 
 import httplib2
@@ -16,6 +17,7 @@
 from pywikibot import config2 as config
 from pywikibot.comms import http, threadedhttp
 
+from tests import _images_dir
 from tests.aspects import unittest, TestCase
 from tests.utils import expected_failure_if
 
@@ -414,6 +416,45 @@
         self.assertRaises(UnicodeDecodeError, lambda: req.content)
 
 
+class BinaryTestCase(TestCase):
+
+    """Get binary file using httplib2 and pywikibot."""
+
+    net = True
+
+    url = 'https://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png'
+
+    @classmethod
+    def setUpClass(cls):
+        super(BinaryTestCase, cls).setUpClass()
+
+        with open(os.path.join(_images_dir, 'MP_sounds.png'), 'rb') as f:
+            cls.png = f.read()
+
+    def test_httplib2(self):
+        """Test with httplib2, underlying package."""
+        h = httplib2.Http()
+        r = h.request(uri=self.url)
+
+        self.assertEqual(r[0]['content-type'], 'image/png')
+        self.assertEqual(r[1], self.png)
+
+        next(iter(h.connections.values())).close()
+
+    def test_threadedhttp(self):
+        """Test with threadedhttp, internal layer on top of httplib2."""
+        r = threadedhttp.Http().request(uri=self.url)
+
+        self.assertEqual(r[0]['content-type'], 'image/png')
+        self.assertEqual(r[1], self.png)
+
+    def test_http(self):
+        """Test with http, standard http interface for pywikibot."""
+        r = http.fetch(uri=self.url)
+
+        self.assertEqual(r.raw, self.png)
+
+
 if __name__ == '__main__':
     try:
         unittest.main()

-- 
To view, visit https://gerrit.wikimedia.org/r/169989
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1f413418461a1dc8e47b1f6b0cfbee405f46a61f
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to