MCPcopy
hub / github.com/django/django / assertURLEqual

Method assertURLEqual

django/test/testcases.py:527–549  ·  view source on GitHub ↗

Assert that two URLs are the same, ignoring the order of query string parameters except for parameters with the same name. For example, /path/?x=1&y=2 is equal to /path/?y=2&x=1, but /path/?a=1&a=2 isn't equal to /path/?a=2&a=1.

(self, url1, url2, msg_prefix="")

Source from the content-addressed store, hash-verified

525 )
526
527 def assertURLEqual(self, url1, url2, msg_prefix=""):
528 """
529 Assert that two URLs are the same, ignoring the order of query string
530 parameters except for parameters with the same name.
531
532 For example, /path/?x=1&y=2 is equal to /path/?y=2&x=1, but
533 /path/?a=1&a=2 isn't equal to /path/?a=2&a=1.
534 """
535
536 def normalize(url):
537 """Sort the URL's query string parameters."""
538 url = str(url) # Coerce reverse_lazy() URLs.
539 scheme, netloc, path, query, fragment = urlsplit(url)
540 query_parts = sorted(parse_qsl(query))
541 return urlunsplit((scheme, netloc, path, urlencode(query_parts), fragment))
542
543 if msg_prefix:
544 msg_prefix += ": "
545 self.assertEqual(
546 normalize(url1),
547 normalize(url2),
548 msg_prefix + "Expected '%s' to equal '%s'." % (url1, url2),
549 )
550
551 def _text_repr(self, content, force_string):
552 if isinstance(content, bytes) and not force_string:

Callers 1

assertRedirectsMethod · 0.95

Calls 1

normalizeFunction · 0.85

Tested by

no test coverage detected