Skip to content

Commit 32f4997

Browse files
committed
Fix p3k tests
1 parent 007ac36 commit 32f4997

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

tests/test_oauth.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
THE SOFTWARE.
2525
"""
26+
import sys
2627
import random
2728
import time
2829
import unittest
@@ -52,6 +53,7 @@
5253
_B2766 = b'\xe2\x9d\xa6' # u'\u2766' encoded to UTF-8
5354
_U2766 = u(_B2766, 'utf8') # u'\u2766'
5455

56+
PY3 = sys.version_info >= (3,)
5557

5658
class TestError(unittest.TestCase):
5759
def test_message(self):
@@ -473,12 +475,24 @@ def test_to_url_works_with_non_ascii_parameters(self):
473475
params.update(other_params)
474476

475477
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)
482496

483497
def test_to_header(self):
484498
realm = "http://sp.example.com/"
@@ -902,10 +916,11 @@ def test_request_nonutf8_bytes(self, mock_make_nonce, mock_make_timestamp):
902916
'oauth_consumer_key': con.key
903917
}
904918

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)
909924

910925
# And if they pass an unicode, then we'll use it.
911926
url = u('http://sp.example.com/') + _U2019

0 commit comments

Comments
 (0)