Exemple #1
0
    def test_gzip(self):
        o = threadedhttp.Http()
        r = o.request('http://www.wikipedia.org/')
        self.assertTrue('-content-encoding' in r[0])
        self.assertEquals(r[0]['-content-encoding'], 'gzip')

        url = 'https://test.wikidata.org/w/api.php?action=query&meta=siteinfo'
        r = o.request(url)
        self.assertTrue('-content-encoding' in r[0])
        self.assertEquals(r[0]['-content-encoding'], 'gzip')
Exemple #2
0
    def test_request(self):
        o = threadedhttp.Http()
        r = o.request('http://www.wikipedia.org/')
        self.assertIsInstance(r, tuple)
        self.assertIsInstance(r[0], dict)
        self.assertTrue('status' in r[0])
        self.assertIsInstance(r[0]['status'], str)
        self.assertEquals(r[0]['status'], '200')

        self.assertIsInstance(r[1], str)
        self.assertTrue('<html lang="mul"' in r[1])
        self.assertEquals(int(r[0]['content-length']), len(r[1]))
Exemple #3
0
    def test_request(self):
        o = threadedhttp.Http()
        r = o.request('http://www.wikipedia.org/')
        self.assertIsInstance(r, tuple)
        self.assertIsInstance(r[0], dict)
        self.assertIn('status', r[0])
        self.assertIsInstance(r[0]['status'], str)
        self.assertEqual(r[0]['status'], '200')

        self.assertIsInstance(r[1], bytes if sys.version_info[0] >= 3 else str)
        self.assertIn(b'<html lang="mul"', r[1])
        self.assertEqual(int(r[0]['content-length']), len(r[1]))
    def test_https(self):
        """Test threadedhttp.Http.request using https://www.wikipedia.org/."""
        o = threadedhttp.Http()
        r = o.request('https://www.wikipedia.org/')
        self.assertIsInstance(r, tuple)
        self.assertNotIsInstance(r[0], Exception)
        self.assertIsInstance(r[0], dict)
        self.assertIn('status', r[0])
        self.assertIsInstance(r[0]['status'], str)
        self.assertEqual(r[0]['status'], '200')

        self.assertIsInstance(r[1], bytes)
        self.assertIn(b'<html lang="mul"', r[1])
        self.assertEqual(int(r[0]['content-length']), len(r[1]))
    def test_gzip(self):
        o = threadedhttp.Http()
        r = o.request('http://www.wikipedia.org/')
        self.assertIsInstance(r, tuple)
        self.assertNotIsInstance(r[0], Exception)
        self.assertIn('-content-encoding', r[0])
        self.assertEqual(r[0]['-content-encoding'], 'gzip')

        url = 'https://test.wikidata.org/w/api.php?action=query&meta=siteinfo'
        r = o.request(url)
        self.assertIsInstance(r, tuple)
        self.assertNotIsInstance(r[0], Exception)
        self.assertIn('-content-encoding', r[0])
        self.assertEqual(r[0]['-content-encoding'], 'gzip')
Exemple #6
0
    def fetch(self, table, format="xml"):
        """
        Fetch data from WikiStats.

        @param table: table of data to fetch
        @type table: basestring
        @param format: Format of data to use
        @type format: 'xml' or 'csv'.
        @rtype: bytes
        """
        URL = self.url + '/api.php?action=dump&table=%s&format=%s'

        if table not in self.ALL_KEYS:
            pywikibot.warning('WikiStats unknown table %s' % table)

        if table in self.FAMILY_MAPPING:
            table = self.FAMILY_MAPPING[table]

        o = threadedhttp.Http()
        r = o.request(uri=URL % (table, format))
        if isinstance(r, Exception):
            raise r
        return r[1]
    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)