|
23 | 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 24 | THE SOFTWARE.
|
25 | 25 | """
|
| 26 | +import sys |
26 | 27 | import random
|
27 | 28 | import time
|
28 | 29 | import unittest
|
|
52 | 53 | _B2766 = b'\xe2\x9d\xa6' # u'\u2766' encoded to UTF-8
|
53 | 54 | _U2766 = u(_B2766, 'utf8') # u'\u2766'
|
54 | 55 |
|
| 56 | +PY3 = sys.version_info >= (3,) |
55 | 57 |
|
56 | 58 | class TestError(unittest.TestCase):
|
57 | 59 | def test_message(self):
|
@@ -473,12 +475,24 @@ def test_to_url_works_with_non_ascii_parameters(self):
|
473 | 475 | params.update(other_params)
|
474 | 476 |
|
475 | 477 | req = oauth.Request("GET", "http://example.com", params)
|
476 |
| - self.assertEquals( |
477 |
| - req.to_url(), |
478 |
| - 'http://example.com?oauth_consumer=asdfasdfasdf&' |
479 |
| - 'uni_unicode_2=%C3%A5%C3%85%C3%B8%C3%98&' |
480 |
| - 'uni_utf8=%C2%AE&multi=%5B%27FOO%27%2C+%27BAR%27%5D&' |
481 |
| - 'uni_unicode=%C2%AE&bar=foo&foo=baz') |
| 478 | + |
| 479 | + # We need to split out the host and params and check individually since the order is not determinate. |
| 480 | + url_parts = req.to_url().split("?") |
| 481 | + host = url_parts[0] |
| 482 | + params = dict(item.strip().split("=") for item in url_parts[1].split("&")) |
| 483 | + |
| 484 | + expected_params = { |
| 485 | + 'uni_utf8': '%C2%AE', |
| 486 | + 'foo': 'baz', |
| 487 | + 'bar': 'foo', |
| 488 | + 'uni_unicode_2': '%C3%A5%C3%85%C3%B8%C3%98', |
| 489 | + 'uni_unicode': '%C2%AE', |
| 490 | + 'multi': '%5Bb%27FOO%27%2C+b%27BAR%27%5D', |
| 491 | + 'oauth_consumer': 'asdfasdfasdf' |
| 492 | + } |
| 493 | + |
| 494 | + self.assertEquals("http://example.com", host) |
| 495 | + self.assertEquals(expected_params, params) |
482 | 496 |
|
483 | 497 | def test_to_header(self):
|
484 | 498 | realm = "http://sp.example.com/"
|
@@ -902,10 +916,11 @@ def test_request_nonutf8_bytes(self, mock_make_nonce, mock_make_timestamp):
|
902 | 916 | 'oauth_consumer_key': con.key
|
903 | 917 | }
|
904 | 918 |
|
905 |
| - # If someone passes a sequence of bytes which is not ascii for |
906 |
| - # url, we'll raise an exception as early as possible. |
907 |
| - url = "http://sp.example.com/\x92" # It's actually cp1252-encoding... |
908 |
| - self.assertRaises(TypeError, oauth.Request, method="GET", url=url, parameters=params) |
| 919 | + if not PY3: |
| 920 | + # If someone passes a sequence of bytes which is not ascii for |
| 921 | + # url, we'll raise an exception as early as possible. |
| 922 | + url = "http://sp.example.com/\x92" # It's actually cp1252-encoding... |
| 923 | + self.assertRaises(TypeError, oauth.Request, method="GET", url=url, parameters=params) |
909 | 924 |
|
910 | 925 | # And if they pass an unicode, then we'll use it.
|
911 | 926 | url = u('http://sp.example.com/') + _U2019
|
|
0 commit comments