@@ -363,8 +363,10 @@ def assertResponse(
363
363
# Verify page status code.
364
364
self .assertStatusCode (response , expected_status )
365
365
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 :
368
370
self .fail (
369
371
(
370
372
'Expected Url and actual Url do not match. \n '
@@ -374,7 +376,7 @@ def assertResponse(
374
376
'"{1}" \n '
375
377
).format (
376
378
expected_url ,
377
- response .urls .computed .final_url ,
379
+ response .url_data .computed .initial_url ,
378
380
)
379
381
)
380
382
@@ -387,14 +389,16 @@ def assertResponse(
387
389
if view_should_redirect is None :
388
390
# No value provided for this assertion. Fall back to settings value.
389
391
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 ):
391
393
if view_should_redirect :
392
394
self .fail ('Expected a page redirect, but response did not redirect.' )
393
395
else :
394
396
self .fail ('Expected no page redirects, but response processed one or more redirects.' )
395
397
396
398
# Verify page redirect.
397
399
# 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).
398
402
if expected_redirect_url is not None :
399
403
self .assertRedirects (
400
404
response ,
@@ -837,7 +841,7 @@ def assertRedirects(
837
841
'Expected url was "{0}". Actual url was "{1}".'
838
842
).format (
839
843
expected_redirect_url ,
840
- response .urls .computed .redirect_url ,
844
+ response .url_data .computed .redirect_url ,
841
845
)
842
846
)
843
847
else :
@@ -1725,23 +1729,27 @@ def _get_page_response(
1725
1729
# The same as above, but with an attempt to prepend the project site root to it.
1726
1730
response_url_data .computed .full_initial_url = full_url
1727
1731
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
1736
1734
if hasattr (response , 'redirect_chain' ) and len (response .redirect_chain ) > 0 :
1737
1735
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 :
1739
1737
redirect_url = redirect_data [0 ]
1740
1738
response_url_data .computed .redirect_url = redirect_url
1741
1739
response_url_data .computed .full_redirect_url = '{0}{1}' .format (self .site_root_url , redirect_url )
1742
1740
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
+
1743
1751
# Save calculated set of url data to response.
1744
- response .urls = response_url_data
1752
+ response .url_data = response_url_data
1745
1753
# Save user data to response.
1746
1754
response .user = user
1747
1755
0 commit comments