@@ -46,7 +46,7 @@ def test_all_posts_view(self):
46
46
self .assertIsInstance (response .context ["posts" ][0 ], Post )
47
47
48
48
def test_home_view_anonymous_user (self ):
49
- response = self .client .get (reverse ("home" ))
49
+ response = self .client .get (reverse ("home" ) + "/" , follow = True )
50
50
self .assertTemplateUsed (response , "blog/home.html" )
51
51
self .assertIsInstance (response .context ["posts" ][0 ], Post )
52
52
@@ -225,11 +225,14 @@ def test_create_comment_view(self):
225
225
"content" : "Test comment" ,
226
226
"post_slug" : self .first_post .slug ,
227
227
},
228
+ follow = True
229
+ )
230
+ # Check final redirect location and status
231
+ self .assertRedirects (
232
+ response ,
233
+ test_post_detail_url + "#comments" ,
234
+ status_code = 302
228
235
)
229
- # Redirect to post detail page after comment submission
230
- self .assertEqual (response .status_code , 302 )
231
- # Ensure redirect to post after comment submission
232
- self .assertRedirects (response , test_post_detail_url + "#comments" )
233
236
# Ensure a comment was added to the post
234
237
self .assertEqual (self .first_post .comments .count (), first_post_comment_count + 1 )
235
238
@@ -371,14 +374,14 @@ def test_category_view_htmx_request(self):
371
374
# self.assertTrue(response.context["page_obj"].has_previous())
372
375
373
376
def test_search_view_blank (self ):
374
- response = self .client .get (reverse ("blog-search" ))
377
+ response = self .client .get (reverse ("blog-search" ), follow = True )
375
378
self .assertTemplateUsed (response , "blog/search_posts.html" )
376
379
377
380
def test_search_view_anonymous (self ):
378
381
# If anonymous, should be able to find a post
379
382
data = {"searched" : self .first_post .title }
380
- response = self .client .get (reverse ("blog-search" ), data = data )
381
-
383
+ response = self .client .get (reverse ("blog-search" ), data = data , follow = True )
384
+ self . assertTemplateUsed ( response , "blog/search_posts.html" )
382
385
self .assertEqual (response .context ["posts" ][0 ], self .first_post )
383
386
384
387
def test_search_view_staff (self ):
@@ -387,8 +390,8 @@ def test_search_view_staff(self):
387
390
self .client .login (
388
391
username = self .admin_user .username , password = self .admin_user_password
389
392
)
390
- response = self .client .get (reverse ("blog-search" ), data = data )
391
-
393
+ response = self .client .get (reverse ("blog-search" ), data = data , follow = True )
394
+ self . assertTemplateUsed ( response , "blog/search_posts.html" )
392
395
posts_in_response = response .context ["posts" ]
393
396
self .assertEqual (posts_in_response .count (), 1 )
394
397
@@ -525,10 +528,12 @@ def test_generate_gpt_input_title(self, mock_create):
525
528
mock_create .return_value = {"choices" : [{"text" : "mocked response" }]}
526
529
headers = {"HTTP_HX-Trigger" : "generate-title" }
527
530
response = self .client .post (
528
- "/generate-with-gpt/" , data = {"content" : "my test blog content" }, ** headers
531
+ "/generate-with-gpt/" ,
532
+ data = {"content" : "my test blog content" },
533
+ ** headers ,
534
+ follow = True
529
535
)
530
-
531
- self .assertIn ("mocked response" , response .content .decode ())
536
+ self .assertContains (response , "mocked response" )
532
537
533
538
def test_generate_gpt_input_title_empty (self ):
534
539
headers = {"HTTP_HX-Trigger" : "generate-title" }
0 commit comments