@@ -24,7 +24,7 @@ class TestViews(SetUp):
24
24
def test_status_view (self , mock_db_status ):
25
25
mock_db_status .return_value .get_status .return_value = (10 , 2 , 500 )
26
26
response = self .client .get (reverse ("status" ))
27
- self .assertResponseAndTemplate (response , "blog/status_page.html" )
27
+ self .assertTemplateUsed (response , "blog/status_page.html" )
28
28
29
29
# def test_all_posts_view_shows_pagination(self):
30
30
# response = self.client.get("/all-posts/")
@@ -42,20 +42,20 @@ def test_status_view(self, mock_db_status):
42
42
43
43
def test_all_posts_view (self ):
44
44
response = self .client .get (reverse ("all-posts" ))
45
- self .assertResponseAndTemplate (response , "blog/all_posts.html" )
45
+ self .assertTemplateUsed (response , "blog/all_posts.html" )
46
46
self .assertIsInstance (response .context ["posts" ][0 ], Post )
47
47
48
48
def test_home_view_anonymous_user (self ):
49
49
response = self .client .get (reverse ("home" ))
50
- self .assertResponseAndTemplate (response , "blog/home.html" )
50
+ self .assertTemplateUsed (response , "blog/home.html" )
51
51
self .assertIsInstance (response .context ["posts" ][0 ], Post )
52
52
53
53
def test_home_view_admin_user (self ):
54
54
self .client .login (
55
55
username = self .admin_user .username , password = self .admin_user_password
56
56
)
57
57
response = self .client .get (reverse ("home" ))
58
- self .assertResponseAndTemplate (response , "blog/home.html" )
58
+ self .assertTemplateUsed (response , "blog/home.html" )
59
59
60
60
def test_home_view_htmx_request (self ):
61
61
headers = {"HTTP_HX-Request" : "true" , "HTTP_HX-Trigger" : "TEST" }
@@ -71,7 +71,7 @@ def test_home_view_htmx_request(self):
71
71
def test_post_detail_view_anonymous (self ):
72
72
test_post_detail_url = reverse ("post-detail" , args = [self .first_post .slug ])
73
73
response = self .client .get (test_post_detail_url )
74
- self .assertResponseAndTemplate (response , "blog/post/post_detail.html" )
74
+ self .assertTemplateUsed (response , "blog/post/post_detail.html" )
75
75
76
76
def test_post_detail_view_anonymous_draft_post (self ):
77
77
draft_post_detail_url = reverse ("post-detail" , args = [self .draft_post .slug ])
@@ -92,7 +92,7 @@ def test_post_create_view_has_correct_context_template_and_form(self):
92
92
username = self .admin_user .username , password = self .admin_user_password
93
93
)
94
94
response = self .client .get (reverse ("post-create" ))
95
- self .assertResponseAndTemplate (response , "blog/post/add_post.html" )
95
+ self .assertTemplateUsed (response , "blog/post/add_post.html" )
96
96
self .assertIsInstance (response .context ["form" ], PostForm )
97
97
self .assertEqual (response .context ["title" ], "Create a New Post" )
98
98
@@ -155,7 +155,7 @@ def test_update_post_view_has_correct_context_template_and_form(self):
155
155
)
156
156
post1_update_url = reverse ("post-update" , args = [self .first_post .slug ])
157
157
response = self .client .get (post1_update_url )
158
- self .assertResponseAndTemplate (response , "blog/post/edit_post.html" )
158
+ self .assertTemplateUsed (response , "blog/post/edit_post.html" )
159
159
self .assertIsInstance (response .context ["form" ], PostForm )
160
160
self .assertEqual (response .context ["title" ], f"Edit { self .first_post .title } " )
161
161
@@ -344,7 +344,7 @@ def test_comment_delete_different_user_blocked(self):
344
344
def test_category_view_anonymous (self ):
345
345
category_url = reverse ("blog-category" , args = [self .default_category .slug ])
346
346
response = self .client .get (category_url )
347
- self .assertResponseAndTemplate (response , "blog/categories.html" )
347
+ self .assertTemplateUsed (response , "blog/categories.html" )
348
348
self .assertEqual (response .context ["category" ], self .default_category )
349
349
self .assertIsInstance (response .context ["posts" ][0 ], Post )
350
350
@@ -372,7 +372,7 @@ def test_category_view_htmx_request(self):
372
372
373
373
def test_search_view_blank (self ):
374
374
response = self .client .get (reverse ("blog-search" ))
375
- self .assertResponseAndTemplate (response , "blog/search_posts.html" )
375
+ self .assertTemplateUsed (response , "blog/search_posts.html" )
376
376
377
377
def test_search_view_anonymous (self ):
378
378
# If anonymous, should be able to find a post
@@ -394,7 +394,7 @@ def test_search_view_staff(self):
394
394
395
395
def test_register_view_happy_path (self ):
396
396
response = self .client .get (reverse ("register" ))
397
- self .assertResponseAndTemplate (response , "users/register.html" )
397
+ self .assertTemplateUsed (response , "users/register.html" )
398
398
self .assertIsInstance (response .context ["form" ], UserRegisterForm )
399
399
400
400
data = {
@@ -438,7 +438,7 @@ def test_profile_view(self):
438
438
username = self .admin_user .username , password = self .admin_user_password
439
439
)
440
440
response = self .client .get (reverse ("profile" ))
441
- self .assertResponseAndTemplate (response , "users/profile.html" )
441
+ self .assertTemplateUsed (response , "users/profile.html" )
442
442
self .assertIsInstance (response .context ["p_form" ], ProfileUpdateForm )
443
443
self .assertIsInstance (response .context ["u_form" ], UserUpdateForm )
444
444
@@ -475,29 +475,29 @@ def test_profile_view_edit_invalid(self):
475
475
476
476
def test_login_view (self ):
477
477
response = self .client .get (reverse ("login" ))
478
- self .assertResponseAndTemplate (response , "users/login.html" )
478
+ self .assertTemplateUsed (response , "users/login.html" )
479
479
480
480
def test_logout_view (self ):
481
481
self .client .login (
482
482
username = self .admin_user .username , password = self .admin_user_password
483
483
)
484
484
response = self .client .post (reverse ("logout" ))
485
- self .assertResponseAndTemplate (response , "users/logout.html" )
485
+ self .assertTemplateUsed (response , "users/logout.html" )
486
486
487
487
def test_password_rest_view (self ):
488
488
response = self .client .get (reverse ("password_reset" ), follow = True )
489
- self .assertResponseAndTemplate (response , "users/password_reset.html" )
489
+ self .assertTemplateUsed (response , "users/password_reset.html" )
490
490
491
491
def test_password_reset_done_view (self ):
492
492
response = self .client .get (reverse ("password_reset_done" ), follow = True )
493
- self .assertResponseAndTemplate (response , "users/password_reset_done.html" )
493
+ self .assertTemplateUsed (response , "users/password_reset_done.html" )
494
494
495
495
# def test_password_reset_confirm_view(self):
496
496
# # TODO
497
497
498
498
def test_password_reset_complete (self ):
499
499
response = self .client .get (reverse ("password_reset_complete" ), follow = True )
500
- self .assertResponseAndTemplate (response , "users/password_reset_complete.html" )
500
+ self .assertTemplateUsed (response , "users/password_reset_complete.html" )
501
501
502
502
def test_sitemap_view (self ):
503
503
response = self .client .get (reverse ("django.contrib.sitemaps.views.sitemap" ))
0 commit comments