Skip to content

Commit 0b323f1

Browse files
Further changes to response urls, to make package production-ready
1 parent d512dd0 commit 0b323f1

File tree

2 files changed

+1164
-1156
lines changed

2 files changed

+1164
-1156
lines changed

django_expanded_test_cases/test_cases/integration_test_case.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,10 @@ def assertResponse(
363363
# Verify page status code.
364364
self.assertStatusCode(response, expected_status)
365365

366-
# Verify base url.
367-
if expected_url is not None and response.urls.computed.final_url != expected_url:
366+
# Verify initial url.
367+
# TODO: Inconsistent expected_x_url handling.
368+
# See project issue 22 (https://github.com/brodriguez8774/django-expanded-test-cases/issues/22).
369+
if expected_url is not None and response.url_data.computed.initial_url != expected_url:
368370
self.fail(
369371
(
370372
'Expected Url and actual Url do not match. \n'
@@ -374,7 +376,7 @@ def assertResponse(
374376
'"{1}" \n'
375377
).format(
376378
expected_url,
377-
response.urls.computed.final_url,
379+
response.url_data.computed.initial_url,
378380
)
379381
)
380382

@@ -387,14 +389,16 @@ def assertResponse(
387389
if view_should_redirect is None:
388390
# No value provided for this assertion. Fall back to settings value.
389391
view_should_redirect = ETC_VIEWS_SHOULD_REDIRECT
390-
if view_should_redirect is not None and not (bool(response.urls.computed.redirect_url) == view_should_redirect):
392+
if view_should_redirect is not None and not (bool(response.url_data.computed.redirect_url) == view_should_redirect):
391393
if view_should_redirect:
392394
self.fail('Expected a page redirect, but response did not redirect.')
393395
else:
394396
self.fail('Expected no page redirects, but response processed one or more redirects.')
395397

396398
# Verify page redirect.
397399
# This is more specific than the above "view_should_redirect" assertion, so intentionally done second.
400+
# TODO: Inconsistent expected_x_url handling.
401+
# See project issue 22 (https://github.com/brodriguez8774/django-expanded-test-cases/issues/22).
398402
if expected_redirect_url is not None:
399403
self.assertRedirects(
400404
response,
@@ -837,7 +841,7 @@ def assertRedirects(
837841
'Expected url was "{0}". Actual url was "{1}".'
838842
).format(
839843
expected_redirect_url,
840-
response.urls.computed.redirect_url,
844+
response.url_data.computed.redirect_url,
841845
)
842846
)
843847
else:
@@ -1725,23 +1729,27 @@ def _get_page_response(
17251729
# The same as above, but with an attempt to prepend the project site root to it.
17261730
response_url_data.computed.full_initial_url = full_url
17271731

1728-
# The fully computed url after processing all view data.
1729-
# Usually the same as the initial_url value, but not always.
1730-
final_url = url
1731-
response_url_data.computed.final_url = final_url
1732-
response_url_data.computed.full_final_url = '{0}{1}'.format(self.site_root_url, final_url)
1733-
1734-
# If redirects occurred, then the final url at the end of the chain.
1735-
# Might be redundant with above `final_url` value?
1732+
# If redirects occurred, then the final url at the end of the redirect chain.
1733+
redirect_url = None
17361734
if hasattr(response, 'redirect_chain') and len(response.redirect_chain) > 0:
17371735
redirect_data = response.redirect_chain[-1]
1738-
if redirect_data[1] == 302 or redirect_data[0] != response.urls.computed._initial_url:
1736+
if redirect_data[1] == 302 and redirect_data[0] != response_url_data.computed.initial_url:
17391737
redirect_url = redirect_data[0]
17401738
response_url_data.computed.redirect_url = redirect_url
17411739
response_url_data.computed.full_redirect_url = '{0}{1}'.format(self.site_root_url, redirect_url)
17421740

1741+
# The fully computed url after processing all view data.
1742+
# The same as the `initial_url` value, unless a redirect occurs.
1743+
# In most instances, will match `initial_url` unless the project is very redirect-heavy.
1744+
if redirect_url is not None:
1745+
final_url = redirect_url
1746+
else:
1747+
final_url = url
1748+
response_url_data.computed.final_url = final_url
1749+
response_url_data.computed.full_final_url = '{0}{1}'.format(self.site_root_url, final_url)
1750+
17431751
# Save calculated set of url data to response.
1744-
response.urls = response_url_data
1752+
response.url_data = response_url_data
17451753
# Save user data to response.
17461754
response.user = user
17471755

0 commit comments

Comments
 (0)