@@ -22,7 +22,9 @@ def test_model(self):
22
22
def test_redirect (self ):
23
23
redirect = Redirect .objects .create (old_path = "/initial" , new_path = "/new_target" )
24
24
self .assertEqual (redirect .nr_times_visited , 0 )
25
- response = self .client .get ("/initial" )
25
+ with self .captureOnCommitCallbacks (execute = True ) as callbacks :
26
+ response = self .client .get ("/initial" )
27
+ self .assertEqual (len (callbacks ), 1 )
26
28
self .assertRedirects (
27
29
response , "/new_target" , status_code = 301 , target_status_code = 404
28
30
)
@@ -35,7 +37,9 @@ def test_redirect_with_append_slash(self):
35
37
old_path = "/initial/" , new_path = "/new_target/"
36
38
)
37
39
self .assertEqual (redirect .nr_times_visited , 0 )
38
- response = self .client .get ("/initial" )
40
+ with self .captureOnCommitCallbacks (execute = True ) as callbacks :
41
+ response = self .client .get ("/initial" )
42
+ self .assertEqual (len (callbacks ), 1 )
39
43
self .assertRedirects (
40
44
response , "/new_target/" , status_code = 301 , target_status_code = 404
41
45
)
@@ -51,12 +55,14 @@ def test_redirect_with_append_slash_and_query_string(self):
51
55
)
52
56
53
57
def test_regular_expression (self ):
54
- redirect = Redirect .objects .create (
58
+ Redirect .objects .create (
55
59
old_path = r"/news/index/(\d+)/(.*)/" ,
56
60
new_path = "/my/news/$2/" ,
57
61
regular_expression = True ,
58
62
)
59
- response = self .client .get ("/news/index/12345/foobar/" )
63
+ with self .captureOnCommitCallbacks (execute = True ) as callbacks :
64
+ response = self .client .get ("/news/index/12345/foobar/" )
65
+ self .assertEqual (len (callbacks ), 1 )
60
66
self .assertRedirects (
61
67
response , "/my/news/foobar/" , status_code = 301 , target_status_code = 404
62
68
)
0 commit comments