@@ -60,7 +60,7 @@ def test_home_view_admin_user(self):
60
60
def test_home_view_htmx_request (self ):
61
61
headers = {"HTTP_HX-Request" : "true" , "HTTP_HX-Trigger" : "TEST" }
62
62
response = self .client .get (reverse ("home" ), ** headers )
63
- self . assertEqual ( response . status_code , 200 )
63
+
64
64
self .assertTemplateUsed (response , "blog/parts/posts.html" )
65
65
66
66
# def test_home_view_paginated(self):
@@ -84,7 +84,7 @@ def test_post_detail_view_admin_user_sees_draft_post(self):
84
84
)
85
85
draft_post_detail_url = reverse ("post-detail" , args = [self .draft_post .slug ])
86
86
response = self .client .get (draft_post_detail_url )
87
- self . assertEqual ( response . status_code , 200 )
87
+
88
88
self .assertTemplateUsed (response , "blog/post/post_detail.html" )
89
89
90
90
def test_post_create_view_has_correct_context_template_and_form (self ):
@@ -203,7 +203,7 @@ def test_post_delete_view(self):
203
203
)
204
204
205
205
response = self .client .get (post1_delete_url )
206
- self . assertEqual ( response . status_code , 200 )
206
+
207
207
self .assertTemplateUsed (response , "blog/post/post_confirm_delete.html" )
208
208
response = self .client .post (post1_delete_url , follow = True )
209
209
self .assertRedirects (response , expected_url = reverse ("home" ))
@@ -249,7 +249,7 @@ def test_create_comment_view_with_htmx(self):
249
249
},
250
250
** headers ,
251
251
)
252
- self . assertEqual ( response . status_code , 200 )
252
+
253
253
self .assertEqual (self .first_post .comments .count (), first_post_comment_count + 1 )
254
254
255
255
def test_update_comment_view_has_correct_context_template_and_form (self ):
@@ -259,7 +259,7 @@ def test_update_comment_view_has_correct_context_template_and_form(self):
259
259
)
260
260
unqiue_comment = create_comment (post = self .first_post )
261
261
response = self .client .get (reverse ("comment-update" , args = [unqiue_comment .id ]))
262
- self . assertEqual ( response . status_code , 200 )
262
+
263
263
self .assertTemplateUsed (response , "blog/comment/update_comment.html" )
264
264
self .assertIsInstance (response .context ["form" ], CommentForm )
265
265
self .assertEqual (
@@ -304,7 +304,7 @@ def test_comment_delete_view_with_htmx(self):
304
304
response = self .client .delete (
305
305
reverse ("comment-delete" , args = [delete_me_comment .id ]), ** headers
306
306
)
307
- self . assertEqual ( response . status_code , 200 )
307
+
308
308
self .assertEqual (response .reason_phrase , "Comment deleted successfully" )
309
309
self .assertFalse (Comment .objects .filter (id = delete_me_comment .id ).exists ())
310
310
@@ -352,7 +352,7 @@ def test_category_view_htmx_request(self):
352
352
category_url = reverse ("blog-category" , args = [self .default_category .slug ])
353
353
headers = {"HTTP_HX-Request" : "true" , "HTTP_HX-Trigger" : "test" }
354
354
response = self .client .get (category_url , ** headers )
355
- self . assertEqual ( response . status_code , 200 )
355
+
356
356
self .assertTemplateUsed (response , "blog/parts/posts.html" )
357
357
358
358
# def test_category_view_paginated(self):
@@ -370,7 +370,6 @@ def test_category_view_htmx_request(self):
370
370
# response = self.client.get(category_url, {"page": 2})
371
371
# self.assertTrue(response.context["page_obj"].has_previous())
372
372
373
-
374
373
def test_search_view_blank (self ):
375
374
response = self .client .get (reverse ("blog-search" ))
376
375
self .assertResponseAndTemplate (response , "blog/search_posts.html" )
@@ -379,7 +378,7 @@ def test_search_view_anonymous(self):
379
378
# If anonymous, should be able to find a post
380
379
data = {"searched" : self .first_post .title }
381
380
response = self .client .get (reverse ("blog-search" ), data = data )
382
- self . assertEqual ( response . status_code , 200 )
381
+
383
382
self .assertEqual (response .context ["posts" ][0 ], self .first_post )
384
383
385
384
def test_search_view_staff (self ):
@@ -389,7 +388,6 @@ def test_search_view_staff(self):
389
388
username = self .admin_user .username , password = self .admin_user_password
390
389
)
391
390
response = self .client .get (reverse ("blog-search" ), data = data )
392
- self .assertEqual (response .status_code , 200 )
393
391
394
392
posts_in_response = response .context ["posts" ]
395
393
self .assertEqual (posts_in_response .count (), 1 )
@@ -470,7 +468,7 @@ def test_profile_view_edit_invalid(self):
470
468
reverse ("profile" ),
471
469
data = {"email" : "invalid" , "username" : "" },
472
470
)
473
- self . assertEqual ( response . status_code , 200 )
471
+
474
472
self .assertTemplateUsed (response , "users/profile.html" )
475
473
self .assertIsInstance (response .context ["p_form" ], ProfileUpdateForm )
476
474
self .assertIsInstance (response .context ["u_form" ], UserUpdateForm )
@@ -503,29 +501,24 @@ def test_password_reset_complete(self):
503
501
504
502
def test_sitemap_view (self ):
505
503
response = self .client .get (reverse ("django.contrib.sitemaps.views.sitemap" ))
506
- self .assertEqual (response .status_code , 200 )
507
504
508
505
def test_robots_view (self ):
509
506
response = self .client .get (reverse ("robots_rule_list" ))
510
- self . assertEqual ( response . status_code , 200 )
507
+
511
508
lines = response .content .decode ().splitlines ()
512
509
self .assertEqual (lines [0 ], "User-agent: *" )
513
510
514
511
def test_works_cited_view (self ):
515
512
response = self .client .get (reverse ("works-cited" ))
516
- self .assertEqual (response .status_code , 200 )
517
513
518
514
def test_privacy_view (self ):
519
515
response = self .client .get (reverse ("privacy" ))
520
- self .assertEqual (response .status_code , 200 )
521
516
522
517
def test_security_txt_view (self ):
523
518
response = self .client .get (reverse ("security-txt" ))
524
- self .assertEqual (response .status_code , 200 )
525
519
526
520
def test_security_pgp_key_view (self ):
527
521
response = self .client .get (reverse ("security-pgp-key-txt" ))
528
- self .assertEqual (response .status_code , 200 )
529
522
530
523
@patch ("openai.Completion.create" )
531
524
def test_generate_gpt_input_title (self , mock_create ):
@@ -534,15 +527,15 @@ def test_generate_gpt_input_title(self, mock_create):
534
527
response = self .client .post (
535
528
"/generate-with-gpt/" , data = {"content" : "my test blog content" }, ** headers
536
529
)
537
- self . assertEqual ( response . status_code , 200 )
530
+
538
531
self .assertIn ("mocked response" , response .content .decode ())
539
532
540
533
def test_generate_gpt_input_title_empty (self ):
541
534
headers = {"HTTP_HX-Trigger" : "generate-title" }
542
535
response = self .client .post (
543
536
"/generate-with-gpt/" , data = {"content" : "" }, ** headers
544
537
)
545
- self . assertEqual ( response . status_code , 200 )
538
+
546
539
self .assertIn (
547
540
"No content found in the post content field" , response .content .decode ()
548
541
)
@@ -556,7 +549,7 @@ def test_generate_gpt_input_slug(self, mock_create):
556
549
data = {"title" : "my test blog title" },
557
550
** headers ,
558
551
)
559
- self . assertEqual ( response . status_code , 200 )
552
+
560
553
self .assertIn ("mocked-response" , response .content .decode ())
561
554
562
555
def test_generate_gpt_input_slug_empty (self ):
@@ -566,7 +559,7 @@ def test_generate_gpt_input_slug_empty(self):
566
559
data = {"title" : "" },
567
560
** headers ,
568
561
)
569
- self . assertEqual ( response . status_code , 200 )
562
+
570
563
self .assertIn (
571
564
"No content found in the post title field" , response .content .decode ()
572
565
)
@@ -580,7 +573,7 @@ def test_generate_gpt_input_metadesc(self, mock_create):
580
573
data = {"content" : "my test blog content" },
581
574
** headers ,
582
575
)
583
- self . assertEqual ( response . status_code , 200 )
576
+
584
577
self .assertIn ("mocked response" , response .content .decode ())
585
578
586
579
def test_generate_gpt_input_metadesc_empty (self ):
@@ -590,7 +583,7 @@ def test_generate_gpt_input_metadesc_empty(self):
590
583
data = {"content" : "" },
591
584
** headers ,
592
585
)
593
- self . assertEqual ( response . status_code , 200 )
586
+
594
587
self .assertIn (
595
588
"No content found in the post content field" , response .content .decode ()
596
589
)
@@ -605,5 +598,5 @@ def test_answer_question_with_gpt(
605
598
response = self .client .post (
606
599
"/answer-with-gpt/" , data = {"question-text-area" : "Test question?" }
607
600
)
608
- self . assertEqual ( response . status_code , 200 )
601
+
609
602
self .assertIn ("mocked response" , response .content .decode ())
0 commit comments