Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aioresponses/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import asyncio # noqa: F401
import sys
from typing import Dict, Optional, Union # noqa
from urllib.parse import parse_qsl, urlencode
from urllib.parse import parse_qsl

from aiohttp import __version__ as aiohttp_version, StreamReader
from aiohttp.client_proto import ResponseHandler
Expand Down Expand Up @@ -40,7 +40,7 @@ def merge_params(
def normalize_url(url: 'Union[URL, str]') -> 'URL':
"""Normalize url to make comparisons."""
url = URL(url)
return url.with_query(urlencode(sorted(parse_qsl(url.query_string))))
return url.with_query(sorted(parse_qsl(url.query_string)))


try:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ddt import ddt, data
from yarl import URL

from aioresponses.compat import merge_params
from aioresponses.compat import merge_params, normalize_url


def get_url(url: str, as_str: bool) -> Union[URL, str]:
Expand All @@ -19,6 +19,7 @@ class CompatTestCase(TestCase):
def setUp(self):
self.url_with_parameters = 'http://example.com/api?foo=bar#fragment'
self.url_without_parameters = 'http://example.com/api?#fragment'
self.url_with_unsafe_chars_and_unordered_params = 'http://example.com/api?foo=bar&type=arg@&see:=thatagain'

@data(True, False)
def test_no_params_returns_same_url__as_str(self, as_str):
Expand Down Expand Up @@ -46,3 +47,9 @@ def test_base_without_params_returns_corrected_url__as_str(self, as_str):
url = get_url(self.url_without_parameters, as_str)

self.assertEqual(merge_params(url, {'x': 42}), expected_url)

def test_normalize_url(self):
self.assertEqual(
normalize_url(self.url_with_unsafe_chars_and_unordered_params),
URL('http://example.com/api?foo=bar&see:=thatagain&type=arg@')
)