def test_encode_params(self): r = Request(url=gh_url) r_latin1 = Request(url=gh_url, encoding='latin1') # test interface self.assertEqual(r._encode_params('mimino'), 'mimino') self.assertEqual(r._encode_params(u'mi\xa3no'), 'mi\xc2\xa3no') self.assertEqual(r_latin1._encode_params(u'mi\xa3no'), 'mi\xa3no') self.assertEqual(r._encode_params({'hello': 'world'}), 'hello=world') self.assertIn(r._encode_params({'a': 'b', 'c': 'd'}), ['a=b&c=d', 'c=d&a=b']) self.assertEqual(r._encode_params([('a', 'b'), ('c', 'd')]), 'a=b&c=d') self.assertEqual(r._encode_params([('a', ''), ('c', '10')]), 'a=&c=10') self.assertRaises(Exception, r._encode_params) self.assertRaises(Exception, r._encode_params, 10) self.assertRaises(Exception, r._encode_params, ['hello', 'world']) # test quoting self.assertEqual(r._encode_params( [('a', u'mi\xa3no'), ('b', 'mi\xc2\xa3no')]), 'a=mi%C2%A3no&b=mi%C2%A3no') self.assertEqual(r._encode_params( {'! #$%&\'()*+,': '/:;=?@[]~'}), '%21+%23%24%25%26%27%28%29%2A%2B%2C=%2F%3A%3B%3D%3F%40%5B%5D%7E')